DEV Community

Sebastian Arrieta
Sebastian Arrieta

Posted on • Originally published at sarrietav.dev

Laravel 12 + Inertia on Railway: Step-by-Step Deployment Guide

Today I had to deploy a basic Laravel 12 + Inertia app to Railway, but if you follow the official Railway guide to the letter, you’re likely to run into errors (at least, I did). So I’m going to walk you through how I actually got it working.


Prerequisites

  • A Laravel project hosted on GitHub.

Step-by-Step Deployment

1. Create a Railway Project

Click the New button and choose Empty Project.


2. Add a PostgreSQL Database

Click Create, choose Database, and select PostgreSQL.


3. Add the Laravel Service

Click Create > Empty Service. Once it’s created:

  • Click on the new service to open its settings.
  • Rename it to something like Laravel App (tip: click the icon to change it too).

4. Set Environment Variables

Go to the Variables tab, then open the Raw Editor. Paste the contents of your .env file, but before saving, make sure to:

  • Generate a new APP_KEY with:
  php artisan key:generate --show
Enter fullscreen mode Exit fullscreen mode
  • Set APP_ENV=production
  • Set APP_DEBUG=false
  • Update your database connection settings to use the Railway PostgreSQL instance:
  DB_CONNECTION=pgsql
  DB_URL=${{Postgres.DATABASE_URL}}
Enter fullscreen mode Exit fullscreen mode

⚠️ Important: The DATABASE_URL points to the internal private address of your Railway PostgreSQL instance. This is good (no ingress data charges), but it’s not available during the build phase. So don’t run database migrations during build — you’ll get an error like:

SQLSTATE[08006] [7] could not translate host name "postgres.railway.internal" to address
Enter fullscreen mode Exit fullscreen mode

5. Connect Your GitHub Repository

Under Settings > Source, connect your GitHub repo.

💡 Alternatively, if you're using the Railway CLI, you can run:

railway up

6. Switch to Railpack

In the Build section, change the builder from Nixpacks to Railpack (beta). This builder uses FrankenPHP instead of PHP-FPM and automatically runs:

  • php artisan optimize
  • php artisan migrate --force

Add Worker and Cron Services

You’ll need two additional services: one for running cron jobs and another for queue workers.

1. Create Startup Scripts

Add the following to your project root:

#!/bin/bash
# Make sure this file is executable: chmod +x run-cron.sh

while [ true ]; do
    echo "Running the scheduler..."
    php artisan schedule:run --verbose --no-interaction &
    sleep 60
done
Enter fullscreen mode Exit fullscreen mode
#!/bin/bash
# Make sure this file is executable: chmod +x run-worker.sh

php artisan queue:work
Enter fullscreen mode Exit fullscreen mode

2. Create Cron and Worker Services

In Railway:

  • Right-click your Laravel service and Duplicate it twice.
  • Name one Cron, and the other Worker.

In each duplicated service:

  • Go to Settings > Deploy > Custom Start Command and add:

For Cron:

chmod +x ./run-cron.sh && sh ./run-cron.sh
Enter fullscreen mode Exit fullscreen mode

For Worker:

chmod +x ./run-worker.sh && sh ./run-worker.sh
Enter fullscreen mode Exit fullscreen mode

3. Force HTTPS in Production

In AppServiceProvider.php, add:

public function boot(): void
{
    if (app()->environment('production')) {
        URL::forceScheme('https');
    }
}
Enter fullscreen mode Exit fullscreen mode

Make sure to import:

use Illuminate\Support\Facades\URL;
Enter fullscreen mode Exit fullscreen mode

This avoids issues like:

Mixed Content: The page at ... was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint ...


Final Steps

  1. Click Deploy on your Laravel service.
  2. Once deployed, go to Settings > Networking, and generate a public domain. Your app will be accessible at port 8080.
  3. Update your service secrets to include the new domain:
APP_URL=https://your-new-url.railway.app
ASSET_URL=https://your-new-url.railway.app
Enter fullscreen mode Exit fullscreen mode

You're Done

And that’s it! You’ve successfully deployed your Laravel 12 + Inertia app to Railway with working cron jobs, queue workers, HTTPS support, and a live domain. Here's the template of the setup if you want to copy it:

Deploy on Railway

Top comments (1)

Collapse
 
isa30a profile image
Isabella Alvarado

Great! very usefull Thanksssss