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

lemmon's avatar
Level 28

Can Sail be used in production?

I am learning docker and I am learning sail. I have run into some trouble with docker and sail just works so smooth. I am wondering if you can use sail in deployment of is it just for development?

0 likes
2 replies
LaryAI's avatar
Level 58

Laravel Sail is primarily designed as a development environment for Laravel applications. It provides a simple way to get started with Docker for local development. However, it is not recommended to use Sail in a production environment for several reasons:

  1. Performance: Sail is optimized for development and may not be configured for the best performance in a production setting.
  2. Security: Production environments require stricter security measures, and Sail's default configurations may not meet these requirements.
  3. Scalability: Production environments often need to handle scaling, load balancing, and other advanced configurations that Sail does not provide out of the box.

For production, it is better to use a more robust Docker setup tailored to your specific needs. You can still use Docker, but you should create custom Dockerfiles and Docker Compose configurations that are optimized for production.

Here is a basic example of how you might set up a Docker Compose file for a Laravel application in production:

version: '3.8'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    image: your-app-image
    container_name: your-app-container
    restart: always
    environment:
      - APP_ENV=production
      - APP_DEBUG=false
      - APP_KEY=${APP_KEY}
    volumes:
      - .:/var/www/html
    networks:
      - app-network

  webserver:
    image: nginx:alpine
    container_name: nginx-container
    restart: always
    ports:
      - "80:80"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
      - .:/var/www/html
    networks:
      - app-network

  db:
    image: mysql:5.7
    container_name: mysql-container
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_USER: ${DB_USERNAME}
      MYSQL_PASSWORD: ${DB_PASSWORD}
    volumes:
      - dbdata:/var/lib/mysql
    networks:
      - app-network

networks:
  app-network:
    driver: bridge

volumes:
  dbdata:

In this example:

  • The app service builds your Laravel application.
  • The webserver service uses Nginx to serve your application.
  • The db service runs a MySQL database.

You would also need to create a Dockerfile for your Laravel application, which might look something like this:

FROM php:7.4-fpm

# Set working directory
WORKDIR /var/www/html

# Install dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    libpng-dev \
    libjpeg62-turbo-dev \
    libfreetype6-dev \
    locales \
    zip \
    jpegoptim optipng pngquant gifsicle \
    vim \
    unzip \
    git \
    curl

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd

# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Copy existing application directory contents
COPY . /var/www/html

# Copy existing application directory permissions
COPY --chown=www-data:www-data . /var/www/html

# Change current user to www
USER www-data

# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]

This setup is more suitable for a production environment, but you should further customize it to meet your specific requirements, including security hardening, performance tuning, and scaling considerations.

Tray2's avatar
Tray2
Best Answer
Level 73

The short answer is no, the longer one is, using Sail in production is like using XAMPP in production, while it would work, it is not secured and optimized like a production server should be.

3 likes

Please or to participate in this conversation.