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

kenprogrammer's avatar

Laravel Sail In Production

I understand that Laravel Sail uses internal PHP server. Given that your local development image configurations are the ones used to build production images. How would I change to Apache or Nginx in production and still retain local dev with default configurations.

Hint: Deployment using Kubernetes Cluster

Any suggestions will be highly appreciated.

0 likes
6 replies
bait-dept's avatar
Level 11

I faced the same issue.

So, to implement it I basically re-wrote the entire dockerfile to be based on php:7.4-apache with the required extensions and modified the start-container file to initialize the apache server and the supervisor.

This retains all local development commands using sail.

My only problem is with slowness.

As a side note, I think it's possible only by installing the apache server in the initial dockerfile provided by sail, creating and copying the apache config and initialize the apache from the start-container.

Dockerfile

FROM php:7.4-apache

WORKDIR /var/www/html

ARG WWWGROUP

ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN apt-get update && apt-get install -y \
        libpng-dev \
        zlib1g-dev \
        libxml2-dev \
        libzip-dev \
        libonig-dev \
        zip \
        curl \
        unzip \
        libmagickwand-dev --no-install-recommends \
        supervisor \
        ghostscript \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libpng-dev \
        libc-client-dev libkrb5-dev \
    && docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install -j$(nproc) gd \
    && docker-php-ext-install pdo_mysql \
    && docker-php-ext-install mysqli \
    && docker-php-ext-install zip \
    && docker-php-ext-install mbstring \
    && docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
    && docker-php-ext-install -j$(nproc) imap \
    && mkdir -p /usr/src/php/ext/imagick \
    && curl -fsSL https://github.com/Imagick/imagick/archive/06116aa24b76edaf6b1693198f79e6c295eda8a9.tar.gz | tar xvz -C "/usr/src/php/ext/imagick" --strip 1 \
    && docker-php-ext-install imagick \
    && docker-php-source delete

RUN sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml
   
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
    
COPY vhost.conf /etc/apache2/sites-available/000-default.conf

RUN groupadd --force -g $WWWGROUP sail

RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail

RUN chown -R sail:$WWWGROUP /var/www/html \
    && a2enmod rewrite \
    && a2enmod headers

COPY start-container /usr/local/bin/start-container

COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

COPY php.ini /usr/local/etc/php/php.ini

RUN chmod +x /usr/local/bin/start-container
    
ENTRYPOINT ["start-container"]
start-container

#!/usr/bin/env bash

if [ $# -gt 0 ];then
    exec gosu $WWWUSER "$@"
else
    # sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml
   
    exec docker-php-entrypoint apache2-foreground
    
    /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
fi
vhosts.config

ServerName localhost

<VirtualHost *:80>
    
    DocumentRoot /var/www/html/public/
    <Directory /var/www/html/public/>
        DirectoryIndex index.php
        Options Indexes FollowSymLinks Includes ExecCGI		
		AllowOverride All
		Order allow,deny
		Allow from all
		Require all granted
		RewriteEngine On
    </Directory>
    
    # Send apache logs to stdout and stderr
    CustomLog /proc/self/fd/1 common
    ErrorLog /proc/self/fd/2
</VirtualHost>
2 likes

Please or to participate in this conversation.