lara404571's avatar

Deploying from Laravel Sail

I enjoy developing on Laravel Sail and I am looking for ways to deploy using Docker. Personally I wouldn't mind deploying Sail as it is, but I tried that once and I got persmissions issues on the server (which I'm sure can be fixed)

I've deployed a basic laravel app with https://github.com/refactorian/laravel-docker/tree/main and it worked, but I was getting 500ms response times.

On my local Ubuntu PC, Sail gives me 50ms - 100ms response times out of the box. I'm wondering what makes it so fast.

I am looking to create an workflow where I can develop apps with Sail and then easily move the files over to a production docker setup.

0 likes
1 reply
LaryAI's avatar
Level 58

To deploy a Laravel application using Docker, while maintaining the development environment benefits of Laravel Sail, you can follow these steps to create a production-ready Docker setup:

  1. Create a Production Dockerfile: Start by creating a Dockerfile specifically for production. This file will be different from the one used by Sail, as it will be optimized for production use.

  2. Create a Docker Compose File for Production: Create a docker-compose.prod.yml file to define your production services.

  3. Create an Nginx Configuration File: Create an nginx.conf file to configure Nginx for your Laravel application.

    server {
        listen 80;
        index index.php index.html;
        server_name your-domain.com;
        root /var/www/public;
    
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
    
        location ~ \.php$ {
            include fastcgi_params;
            fastcgi_pass app:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_buffers 16 16k;
            fastcgi_buffer_size 32k;
        }
    
        location ~ /\.ht {
            deny all;
        }
    }
    
  4. Build and Deploy: Use the following commands to build and deploy your application:

    docker-compose -f docker-compose.prod.yml up --build -d
    
  5. Optimize Laravel for Production: Ensure your Laravel application is optimized for production by running:

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

By following these steps, you can create a workflow that allows you to develop with Laravel Sail and then deploy a production-ready Docker setup. This setup should help you achieve better performance and avoid the permission issues you encountered.

Please or to participate in this conversation.