Table of Contents

    This is how I accomplished using the PHP-FPM image with Laravel Sail. Feel free to use it as a guide or reference. You can also leave a comment if you have any suggestions.

    This was tested with Laravel 9.21.

    Create a Laravel project with Sail

    Starting with a fresh Laravel project called sail-php-fpm:

    curl -s https://laravel.build/sail-php-fpm| bash
    cd sail-php-fpm

    Next we’ll start the default Sail environment and publish it’s assets:

    ./vendor/bin/sail up -d
    ./vendor/bin/sail artisan sail:publish

    The sail up -d command starts Sail’s docker services in the background so that we can continue using the same command prompt.

    The sail artisan sail:publish command will allow us to customize the docker image by using Sail’s Dockerfile as a starting point.

    Modify Dockerfile

    Update the first few lines in order to use the PHP FPM image and add mlocati’s extension installer. Also take the moment to update the maintainer label.

    - FROM ubuntu:22.04
    + FROM php:8.1-fpm
    
    + ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
    
    + RUN chmod +x /usr/local/bin/install-php-extensions
    
    LABEL maintainer="AND1"

    Continue modifying the Dockerfile by changing the main RUN section.

    RUN apt-get update \
        && apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 \
    -    && mkdir -p ~/.gnupg \
    -    && chmod 600 ~/.gnupg \
    -    && echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \
    -    && echo "keyserver hkp://keyserver.ubuntu.com:80" >> ~/.gnupg/dirmngr.conf \
    -    && gpg --recv-key 0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c \
    -    && gpg --export 0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c > /usr/share/keyrings/ppa_ondrej_php.gpg \
    -    && echo "deb [signed-by=/usr/share/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
    -    && apt-get update \
    -    && apt-get install -y php8.1-fpm php8.1-dev \
    -       php8.1-pgsql php8.1-sqlite3 php8.1-gd \
    -       php8.1-curl \
    -       php8.1-imap php8.1-mysql php8.1-mbstring \
    -       php8.1-xml php8.1-zip php8.1-bcmath php8.1-soap \
    -       php8.1-intl php8.1-readline \
    -       php8.1-ldap \
    -       php8.1-msgpack php8.1-igbinary php8.1-redis php8.1-swoole \
    -       php8.1-memcached php8.1-pcov php8.1-xdebug \
    +   && install-php-extensions \
    +       curl pdo_pgsql sqlite3 gd \
    +       imap pdo_mysql mbstring \
    +       xml zip bcmath soap \
    +       intl readline ldap \
    +       msgpack igbinary redis swoole \
    +       pcov xdebug \
    +       @composer \
    
    + RUN echo "\n[www]" >> /user/local/etc/php/fpm/pool.d/www.conf \
    +     && echo "user=sail" >> /user/local/etc/php/fpm/pool.d/www.conf \
    +     && echo "clear_env=false" >> /user/local/etc/php/fpm/pool.d/www.conf
    
    - COPY php.ini /etc/php/8.1/cli/conf.d/99-sail.ini
    + COPY php.ini /user/local/etc/php/cli/conf.d/99-sail.ini

    Make sure you also configure your web server such as Nginx, Caddy or Apache for PHP-FPM. You can reference this page for help.

    Rebuild the docker image

    ./vendor/bin/sail build --no-cache

    Leave a Reply

    Your email address will not be published. Required fields are marked *