Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

totoosa's avatar

Going from Laravel Sail (dev environment) + production environment

Is there a reasonable guide/way of transitioning from a laravel sail docker setup of your app in your development environment to deploying on a simple vps? I can't seem to get the hang of deploying without using first party solutions like laravel forge. If there are any guides, please can anyone share? Also what's the point of using sail as our development environment, since the containers in our development environment would be entirely different from what we have in production? It's kind of confusing/demanding going from development to production

0 likes
7 replies
LaryAI's avatar
Level 58

Transitioning from a Laravel Sail (development environment) to a production environment on a VPS can indeed be a bit challenging if you're not familiar with the process. Here’s a step-by-step guide to help you through this transition:

1. Prepare Your VPS

First, ensure your VPS is set up with the necessary software. You will need:

  • A web server (e.g., Nginx or Apache)
  • PHP (compatible version with your Laravel application)
  • A database server (e.g., MySQL or PostgreSQL)
  • Composer
  • Git (optional, but recommended for deployment)

2. Set Up Your Web Server

For this example, let's use Nginx. Here’s a basic Nginx configuration for a Laravel application:

server {
    listen 80;
    server_name yourdomain.com;
    root /var/www/your-laravel-app/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

3. Deploy Your Application

You can deploy your application using Git. Here’s a simple way to do it:

  1. Clone your repository:

    cd /var/www
    git clone https://github.com/yourusername/your-laravel-app.git
    cd your-laravel-app
    
  2. Install dependencies:

    composer install --optimize-autoloader --no-dev
    
  3. Set up environment variables:

    cp .env.example .env
    nano .env
    

    Update the .env file with your production settings.

  4. Generate application key:

    php artisan key:generate
    
  5. Run migrations:

    php artisan migrate --force
    
  6. Set permissions:

    chown -R www-data:www-data /var/www/your-laravel-app
    chmod -R 775 /var/www/your-laravel-app/storage
    chmod -R 775 /var/www/your-laravel-app/bootstrap/cache
    

4. Configure Supervisor (for Queue Workers)

If your application uses queues, you’ll need to set up Supervisor to manage your queue workers.

  1. Install Supervisor:

    sudo apt-get install supervisor
    
  2. Create a Supervisor configuration file:

    sudo nano /etc/supervisor/conf.d/your-laravel-app-worker.conf
    

    Add the following content:

    [program:your-laravel-app-worker]
    process_name=%(program_name)s_%(process_num)02d
    command=php /var/www/your-laravel-app/artisan queue:work --sleep=3 --tries=3
    autostart=true
    autorestart=true
    user=www-data
    numprocs=1
    redirect_stderr=true
    stdout_logfile=/var/www/your-laravel-app/storage/logs/worker.log
    
  3. Start Supervisor:

    sudo supervisorctl reread
    sudo supervisorctl update
    sudo supervisorctl start your-laravel-app-worker:*
    

5. Set Up SSL (Optional but recommended)

Use Certbot to obtain an SSL certificate from Let's Encrypt:

sudo apt-get install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com

6. Optimize Your Application

Run the following commands to optimize your Laravel application for production:

php artisan config:cache
php artisan route:cache
php artisan view:cache

Conclusion

Using Laravel Sail for development is beneficial because it provides a consistent environment that mirrors production as closely as possible. However, for production, you typically want a more tailored setup that is optimized for performance and security. By following the steps above, you can transition from a Sail-based development environment to a robust production environment on a VPS.

puklipo's avatar

With PHP, there is little need to strictly match the development environment and production environment.

In most cases, it will work without any problems as long as you have the same PHP version, extensions, and database.

It is sufficient to use Sail for development and a general web server for production.

1 like
totoosa's avatar

@puklipo This doesn't answer my question though, no offense. I'm asking what's the convention if i wanted to use docker both in development and in production since sail is only meant to be used in development , without using a first party solution. Like if i wanted to do it manually myself

1 like
martinbean's avatar

@totoosa If you wanted to use Docker across environments then that’s when you’d define your own Docker Compose set-up instead of using Sail.

1 like
MohamedTammam's avatar

Don't use sail for production, the docker image for sail isn't built for that. As @martinbean said, write your own image if you want to use it in both development and productions.

Speaking of deployment :

I can't seem to get the hang of deploying without using first party solutions like laravel forge

Search on YouTube "Deploy Laravel on VPS".

Also DigitalOcean has Laravel support for app platform. (I didn't use myself)

2 likes
vincent15000's avatar

I recently have had the same thoughts as you about sail and docker.

I have added the services I need inside the docker-compose.yml file used by sail.

And I have written my own docker-compose.yml file for the production environment with exactly the same services than in development.

Sure I should have written initially the docker-compose.yml file used by both the development and production environments, but I thought that sail could be used in production (I was wrong).

If you use exactly the same services (with the same versions), there is no reason it could not work.

totoosa's avatar

@vincent15000 Well if you are using sail, pretty sure it's using something like artisan serve/ php server under the hood, as opposed to using a full fledged server like nginx or apache, which is the major breakdown issue with deploying the same code to your production environment.

I had the opinion when i started using sail that all i would need to is pull from github and build my containers on my vps as opposed to having to containerize it differently for production.

but now realizing is i need something different from production.

Please or to participate in this conversation.