PHP is a framework for building websites. Railway is a platform for hosting web apps. Learn how to host a PHP site on Railway.
Prerequisites
- Railway Account
- PHP
Create Home Page
On your local machine, create a index.php
file.
<h1>Hello, World</h1>
Test your site.
php -S localhost:8000
Deploy to Railway
Install the Railway CLI tool:
npm i -g @railway/cli
Login to your Railway account:
railway login --browserless
Create a new Railway project:
railway init
Link your folder to your Railway project.
railway link
Deploy your app.
railway up --detach
When the site is ready, generate a domain.
railway domain
Update Site and Redeploy
Update home page, index.php
:
<h1>Hello World!</h1>
<p>Happy to be here</p>
Test update locally:
php -S localhost:8000
Redeploy to Railway.
railway up --detach
Top comments (3)
This is a clear and concise guide to deploying a PHP site on Railway! I'm impressed with how easy it is to get started, thanks for sharing.
Thanks for that. I try to keep things simple.
I tried a similar approach with Railway for a while, but I found Cloudways to be a bit more convenient for managing PHP apps, especially when it comes to scaling and performance optimization. The control over server configurations is pretty solid, and their support is responsive if you ever need to troubleshoot. Definitely worth considering if anyone is looking for a more hands-off management experience. I recently purchased Cloudways using the 40% off black friday promo. Not sure if the offer is still up.