Hi,
I just started using Qovery and I need to deploy a Laravel project. I have issues deploying the project using PHP-FPM and nginx.
In local development, I use docker-compose to share a volume with php-fpm:
version: "3"
services:
api-doorin-php:
restart: always
build:
context: .
dockerfile: Dockerfile
env_file:
- .env
environment:
- DB_HOST=host.docker.internal
volumes:
- volume-doorin:/app
api-doorin-nginx:
restart: always
image: nginx:latest
ports:
- "8000:80"
volumes:
- volume-doorin:/app
- ./nginx-local.conf:/etc/nginx/conf.d/default.conf
depends_on:
- api-doorin-php
api-doorin-queue:
restart: always
build:
context: .
dockerfile: Dockerfile
env_file:
- .env
environment:
- DB_HOST=host.docker.internal
command: php artisan queue:work --queue=fileUpload,default
depends_on:
- api-doorin-php
volumes:
- volume-doorin:/app
links:
- api-doorin-php
volumes:
volume-doorin:
My Dockerfile is like this:
# Base image
FROM php:8.1-fpm
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip \
libzip-dev \
tzdata \
libmagickwand-dev --no-install-recommends \
locales \
locales-all \
libreoffice \
ghostscript
# Install PHP extensions
RUN docker-php-ext-install exif gd intl mysqli pdo_mysql zip bcmath calendar gettext \
&& docker-php-ext-enable exif gd intl mysqli pdo_mysql zip bcmath calendar gettext
# Install Imagick
RUN pecl install imagick \
&& docker-php-ext-enable imagick
# Allow PDF to image conversion in Imagick
RUN sed -i '92 a<!--' /etc/ImageMagick-6/policy.xml \
&& sed -i '98 a/-->' /etc/ImageMagick-6/policy.xml
# Install xdebug
RUN pecl install xdebug-3.1.5 \
&& docker-php-ext-enable xdebug
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Application setup
COPY . /var/www/html
RUN usermod -u 1000 www-data \
&& chown -R www-data:www-data /var/www/html
WORKDIR /var/www/html
# Environment configuration
ENV TZ=Europe/Paris \
LC_ALL=fr_FR.utf8 \
LANG=fr_FR.utf8 \
LANGUAGE=fr_FR.utf8
RUN rm /etc/localtime && echo $TZ > /etc/localtime
# Set PHP configuration
COPY ./confphp.ini /usr/local/etc/php/conf.d/confphp.ini
# Install composer
RUN php -r "readfile('https://getcomposer.org/installer');" | php -- --install-dir=/usr/local/bin --filename=composer \
&& chmod +x /usr/local/bin/composer
# Install dependencies
RUN touch /var/www/html/storage/logs/laravel.log \
&& mkdir -p /var/www/html/storage/framework/cache/data \
&& composer install --optimize-autoloader --no-dev \
&& composer dump-autoload \
&& php artisan optimize:clear \
&& chown -R www-data:www-data /var/www/html/storage \
&& chmod -R 755 /var/www/html/storage \
&& chown -R www-data:www-data /var/www/html/storage/framework/cache/data \
&& chmod -R 755 /var/www/html/storage/framework/cache/data \
&& chgrp -R www-data storage bootstrap/cache \
&& chmod -R ug+rwx storage bootstrap/cache
EXPOSE 9000
CMD ["php-fpm", "-F"]
I managed to build and deploy the app for the php-fpm and the laravel queue parts of the docker-compose. But I didn’t manage to run the nginx part.
I tried to build it with a new Dockerfile:
FROM nginx:1.25.3-alpine
# Copy Nginx configuration
COPY nginx.conf /etc/nginx/conf.d/default.conf
# Expose Nginx port
EXPOSE 80
# Start Nginx
CMD ["nginx", "-g", "daemon off;"]
But it is not connected to the PHP code from the other Dockerfile (in the docker-compose it is connected via a volume).
I tried to update the nginx.conf file that I use with docker-compose:
server {
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /app/public;
client_max_body_size 0;
client_body_buffer_size 128k;
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
output_buffers 1 32k;
postpone_output 1460;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass api-doorin-php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ \.php$ {
return 404;
}
}
In local, I have fastcgi_pass api-doorin-php:9000;
which is the shared volume that I need to update to “connect” to the php-fpm container exposing on port 9000.
Another solution that I tried is to used a multi-stage Dockerfile with PHP-FPM and then NGINX stages but I did not manage to make it work because I need both the PHP-FPM and the NGINX to run.
I am currently trying to connect a NGINX container to a PHP-FPM container in local but maybe it is not the right way to do it.
Thanks a lot.