A basic Nginx and PHP server with the php-pdo for mysql
750
I created this for some of my own projects. I was initially using the trafex image with nginx php, but I needed a few extensions (pdo in particular) for php so I had to build my own.
I've now also set to build and update the image once a month to keep it relatively fresh. May build to update sooner if I become aware of any critical updates.
Dockerfile
FROM alpine:latest
# Install packages
RUN apk add --no-cache \
nginx \
supervisor \
php \
php-fpm \
php-mysqli \
php-pdo \
php-pdo_mysql \
php-json \
php-openssl \
php-curl \
php-zlib \
php-xml \
php-phar \
php-intl \
php-dom \
php-xmlreader \
php-ctype \
php-session \
php-mbstring \
php-gd \
php-fileinfo \
php-sockets \
php-iconv \
&& mkdir -p /run/nginx
&& ln -sf /usr/sbin/php-fpm8* /usr/sbin/php-fpm
# Configure Nginx
COPY default.conf /etc/nginx/http.d/default.conf
# Configure Supervisor
COPY supervisord.conf /etc/supervisord.conf
# Expose HTTP port
EXPOSE 80
# Start Supervisor directly
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
supervisor.conf
[supervisord]
nodaemon=true
user=root
[program:php-fpm]
# Alpine's php-fpm package usually links the versioned binary to /usr/sbin/php-fpm
command=/usr/sbin/php-fpm -F
autostart=true
autorestart=true
priority=5
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:nginx]
command=/usr/sbin/nginx -g "daemon off;"
autostart=true
autorestart=true
priority=10
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
default.conf
server {
listen 80;
server_name localhost;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
NOTES 2026-11-04 : added packages php-gd, php-fileinfo, php-sockets, php-iconv
Content type
Image
Digest
sha256:aafe18b26…
Size
45.6 MB
Last updated
3 days ago
docker pull zeighy/alpine-nginx-php