Introduction

Welcome to Laravel Atlas! This guide helps you deploy Laravel apps using Railway, with a focus on environment setup and deployment best practices.

  • Clean up your project and commit changes.
  • Push your code to GitHub (see next section).
  • Deploy and configure your app on Railway.

My Deployment Journey & Tips

Making deployment work required special attention to linking the database and the app. Here are some key lessons and tips from my experience:

  • Database First: You must set up your database (e.g., MySQL) before deploying your Laravel app. Railway will deploy your databases using Docker. If Docker status is down, you can build your Docker file and publish it from GitHub directly to your page.
  • No Need for composer run dev in Production: Railway handles asset building and deployment for you. Running composer run dev is not recommended in production.
  • Project Expiry: When you deploy, you may see a prompt that your project expires in 24 hours. Claim it by signing in with your GitHub account.
  • Debugging 500 Errors: If your project shows a 500 error, set APP_DEBUG="true" in your environment variables to see the issue. After fixing, always set APP_DEBUG back to false for security reasons.
  • Fast & Easy Deployments: Deployment with this platform is much faster and easier—thanks to Railway!

Enjoy shipping your Laravel apps with confidence!

Pushing to GitHub

  1. Create a new repository on GitHub.
  2. Initialize git and add your remote:
    git init
    git remote add main https://github.com/your-username/Laravel-Atlas.git
  3. Add, commit, and push your code:
    git add .
    git commit -m "first commit"
    git push --set-upstream main master

Deploying to Railway

  1. First, set up your database (e.g., MySQL) in Railway. This is required before deploying your Laravel app.
    MySQL Deploying
  2. Click Deploy in Railway to start the deployment process.
  3. Sign in with GitHub to claim your project if prompted.
  4. Deploy your Laravel app from GitHub.
    Deploy App
  5. Railway will auto-detect your Laravel app and set up build/start commands.
    Railway Builder
  6. Optionally, add custom migrations or seeding commands as needed.

Environment Setup

After deployment, set up your environment variables in Railway:

  1. Go to your Railway service, click Variables, and use the raw editor.
  2. Copy your .env file contents and paste them in the editor.
  3. Update variables as needed. Example:
APP_NAME="Laravel-Atlas"
APP_ENV="production"
APP_KEY="your key" # must be present
APP_DEBUG="false" # set to true for debugging
APP_URL="https://your-app.up.railway.app/"
DB_CONNECTION="mysql"
DB_HOST="mysql.railway.internal"
DB_PORT="3306"
DB_DATABASE="railway"
DB_USERNAME="root"
DB_PASSWORD="your_db_password"
SESSION_DRIVER="database"
# ...other variables
                    

Database Variables

Ensure these variables match between your Laravel project and Railway database:

Laravel .env Railway DB
DB_CONNECTIONmysql
DB_HOSTmysql.railway.internal
DB_PORT3306
DB_DATABASErailway
DB_USERNAMEroot
DB_PASSWORDMYSQL_ROOT_PASSWORD
SESSION_DRIVERdatabase

Finishing Up

  • Open your generated domain (e.g., your-app.up.railway.app).
  • Your Laravel app should be running!