DEV Community

Cover image for Deploy a PHP site to Railway
Mark Munyaka
Mark Munyaka

Posted on

2

Deploy a PHP site to Railway

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>
Enter fullscreen mode Exit fullscreen mode

Test your site.

php -S localhost:8000
Enter fullscreen mode Exit fullscreen mode

Deploy to Railway

Install the Railway CLI tool:

npm i -g @railway/cli
Enter fullscreen mode Exit fullscreen mode

Login to your Railway account:

railway login --browserless
Enter fullscreen mode Exit fullscreen mode

Create a new Railway project:

railway init
Enter fullscreen mode Exit fullscreen mode

Link your folder to your Railway project.

railway link
Enter fullscreen mode Exit fullscreen mode

Deploy your app.

railway up --detach
Enter fullscreen mode Exit fullscreen mode

When the site is ready, generate a domain.

railway domain
Enter fullscreen mode Exit fullscreen mode

Update Site and Redeploy

Update home page, index.php:

<h1>Hello World!</h1>
<p>Happy to be here</p>
Enter fullscreen mode Exit fullscreen mode

Test update locally:

php -S localhost:8000
Enter fullscreen mode Exit fullscreen mode

Redeploy to Railway.

railway up --detach
Enter fullscreen mode Exit fullscreen mode

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (3)

Collapse
 
programmerraja profile image
Boopathi

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.

Collapse
 
markmunyaka profile image
Mark Munyaka

Thanks for that. I try to keep things simple.

Collapse
 
abdul_rehman_844698c86c26 profile image
Abdul Rehman

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.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay