NGINX + PHP on Alpine with PHP extension pdo and sqlite
574
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 for php so I had to build my own.
This one is specifically built for having the need to save data into a sqlite db. Note that it does not have mysql extensions.
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 including the missing PHP modules
RUN apk add --no-cache \
nginx \
supervisor \
sqlite \
php \
php-fpm \
php-pdo \
php-pdo_sqlite \
php-sqlite3 \
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-opcache \
php-fileinfo \
php-gd \
php-tokenizer \
php-xmlwriter \
&& mkdir -p /run/nginx /var/lib/nginx/logs /var/www/html /var/log/php84 \
&& ln -sf /usr/sbin/php-fpm8* /usr/sbin/php-fpm \
&& sed -i 's|listen = /run/php-fpm.sock|listen = 127.0.0.1:9000|g' /etc/php8*/php-fpm.d/www.conf \
&& sed -i 's|^error_log = .*|error_log = /dev/stderr|g' /etc/php8*/php-fpm.conf \
&& chmod -R 777 /run /var/lib/nginx /var/log/nginx /var/www/html /var/log/php84
# Configure Nginx
COPY default.conf /etc/nginx/http.d/default.conf
# Configure Supervisor
COPY supervisord.conf /etc/supervisord.conf
WORKDIR /var/www/html
# Expose HTTP port
EXPOSE 80
# Start Supervisor directly
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
supervisord.conf
[supervisord]
nodaemon=true
[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 _;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# Deny access to hidden files
location ~ /\. {
deny all;
}
# Protect SQLite databases from being downloaded
location ~ \.sqlite$ {
deny all;
}
}
Content type
Image
Digest
sha256:b19e2c310…
Size
47 MB
Last updated
15 days ago
docker pull zeighy/alpine-nginx-php-pdo-sqlite