• Stars
    star
    106
  • Rank 325,871 (Top 7 %)
  • Language
    Dockerfile
  • License
    MIT License
  • Created about 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Dockerized Nginx + PHP FPM images with many customizable options

github.com/tiredofit/docker-nginx-php-fpm

GitHub release Build Status Docker Stars Docker Pulls Become a sponsor Paypal Donate


About

This repository will build a Nginx w/PHP-FPM docker image, suitable for serving PHP scripts, or utilizing as a base image for installing additional software.

  • Tracking PHP 5.3-8.2
  • Easily enable / disable extensions based on your use case
  • Automatic Log rotation
  • Composer Included
  • XDebug capability
  • Caching via APC, opcache
  • Includes client libraries for MariaDB and Postgresql

Maintainer

Table of Contents

Prerequisites and Assumptions

  • Assumes you are using some sort of SSL terminating reverse proxy such as:

Installation

Build from Source

Clone this repository and build the image with docker build -t (imagename) .

Prebuilt Images

Builds of the image are available on Docker Hub

docker pull docker.io/tiredofit/nginx-php-fpm:(imagetag)

Builds of the image are also available on the Github Container Registry

docker pull ghcr.io/tiredofit/docker-nginx-php-fpm:(imagetag)

The following image tags are available along with their tagged release based on what's written in the Changelog:

PHP version Alpine Base Tag Debian Base Tag
latest edge :alpine-edge
8.2.x edge :alpine-8.2 Bookworm :debian-8.2
8.1.x 3.17 :alpine-8.1 Bookworm :debian-8.1
8.0.x 3.16 :alpine-8.0 Bookworm :debian-8.0
7.4.x 3.15 :alpine-7.4 Bookworm :debian-7.4
7.3.x 3.12 :alpine-7.3 Bookworm :debian-7.3
7.2.x 3.9 :alpine-7.2
7.1.x 3.7 :alpine-7.1
7.0.x 3.5 :alpine-7.0
5.6.x 3.8 :alpine-5.6
5.5.x 3.4 :5.5-latest
5.3.x 3.4 :5.3-latest

Multi Architecture

Images are built primarily for amd64 architecture, and may also include builds for arm/v7, arm64 and others. These variants are all unsupported. Consider sponsoring my work so that I can work with various hardware. To see if this image supports multiple architecures, type docker manifest (image):(tag)

Configuration

Quick Start

The container starts up and reads from /etc/nginx/nginx.conf for some basic configuration and to listen on port 73 internally for Nginx Status responses. Configuration of websites are done in /etc/services.available with the filename pattern of site.conf. You must set an environment variable for NGINX_SITE_ENABLED if you have more than one configuration in there if you only want to enable one of the configurartions, otherwise it will enable all of them. Use NGINX_SITE_ENABLED=null to break a parent image declaration.

Use this as a starting point for your site configurations:

  server {
      ### Don't Touch This
      listen {{NGINX_LISTEN_PORT}};
      server_name localhost;
      root {{NGINX_WEBROOT}};

      ### Populate your custom directives here
      index  index.php index.html index.htm;

      location / {
          try_files \$uri \$uri/ /index.php?\$args;
      }

      ### Populate your custom directives here
      location ~ \.php(/|\$) {
          include /etc/nginx/snippets/php-fpm.conf;
          fastcgi_split_path_info ^(.+?\.php)(/.+)\$;
          fastcgi_param PATH_INFO \$fastcgi_path_info;
          fastcgi_index index.php;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
      }

      # Deny access to any files with a .php extension in the uploads directory
      location ~* /(?:uploads|files)/.*\.php$ {
          deny all;
      }

      ### Don't edit past here
      include /etc/nginx/snippets/site_optimization.conf;
      include /etc/nginx/snippets/exploit_protection.conf;
    }

Persistent Storage

The container starts up and reads from /etc/nginx/nginx.conf for some basic configuration and to listen on port 73 internally for Nginx Status responses. /etc/nginx/conf.d contains a sample configuration file that can be used to customize a nginx server block.

The following directories are used for configuration and can be mapped for persistent storage.

Directory Description
/www/html Root Directory
/www/logs Nginx and php-fpm logfiles

Environment Variables

Base Images used

This image relies on an Alpine Linux or Debian Linux base image that relies on an init system for added capabilities. Outgoing SMTP capabilities are handlded via msmtp. Individual container performance monitoring is performed by zabbix-agent. Additional tools include: bash,curl,less,logrotate, nano. Be sure to view the following repositories to understand all the customizable options:

Image Description
OS Base Customized Image based on Alpine Linux
Nginx Nginx webserver

Container Options

The container has an ability to work in 3 modes, nginx-php-fpm (default) is an All in One image with nginx and php-fpm working together, nginx will only utilize nginx however not the included php-fpm instance, allowing for connecting to multiple remote php-fpm backends, and finally php-fpm to operate PHP-FPM in standalone mode.

Parameter Description Default
PHP_FPM_CONTAINER_MODE Mode of running container nginx-php-fpm, nginx, php-fpm nginx-php-fpm

When PHP_FPM_CONTAINER_MODE set to nginx the PHP_FPM_LISTEN_PORT environment variable is ignored and the PHP_FPM_HOST variable defined below changes. You can add multiple PHP-FPM hosts to the backend in this syntax : seperated by commas e.g php-fpm-container1:9000,php-fpm-container2:9000

You can also pass arguments to each server as defined in the Nginx Upstream Documentation

Parameter Description Default
PHP_APC_SHM_SIZE APC Cache Memory size - 0 to disable 128M
PHP_APC_TTL APC Time to live in seconds 7200
PHP_FPM_HOST Default PHP-FPM Host, seperate multiple by commas 127.0.0.1:9000 - See above Container options
PHP_FPM_LISTEN_PORT PHP-FPM Listening Port - Ignored with above container options 9000
PHP_FPM_MAX_CHILDREN Maximum Children 75
PHP_FPM_MAX_REQUESTS How many requests before spawning new server 500
PHP_FPM_MAX_SPARE_SERVERS Maximum Spare Servers available 3
PHP_FPM_MIN_SPARE_SERVERS Minium Spare Servers avaialble 1
PHP_FPM_OUTPUT_BUFFER_SIZE Output buffer size in bytes 0
PHP_FPM_POST_INIT_COMMAND If you wish to execute a command before php-fpm executes, enter it here and seperate multiples by comma.
PHP_FPM_POST_INIT_SCRIPT If you wish to execute a script before php-fpm executes, enter it here and seperate multiples by comma.
PHP_FPM_PROCESS_MANAGER How to handle processes static, ondemand, dynamic dynamic
PHP_FPM_START_SERVERS How many FPM servers to start initially 2
PHP_HIDE_X_POWERED_BY Hide X-Powered by response TRUE
PHP_LOG_ACCESS_FILE PHP Access Logfile Name access.log
PHP_LOG_ERROR_FILE Logfile name error.log
PHP_LOG_LEVEL PHP Log Level alert error warning notice debug notice
PHP_LOG_ACCESS_FORMAT Log format - default or json default
PHP_LOG_LIMIT Characters to log 2048
PHP_LOG_LOCATION Log Location for PHP Logs /www/logs/php-fpm
PHP_MEMORY_LIMIT How much memory should PHP use 128M
PHP_OPCACHE_INTERNED_STRINGS_BUFFER OPCache interned strings buffer 8
PHP_OPCACHE_JIT_BUFFER_SIZE JIT Buffer Size 0 to disable 50M
PHP_OPCACHE_JIT_MODE JIT CRTO Mode - > PHP 8.x 1255
PHP_OPCACHE_MAX_ACCELERATED_FILES OPCache Max accelerated files 10000
PHP_OPCACHE_MEM_SIZE OPCache Memory Size - Set 0 to disable or via other env vars 128
PHP_OPCACHE_REVALIDATE_FREQ OPCache revalidate frequency in seconds 2
PHP_OPCACHE_MAX_WASTED_PERCENTAGE Max wasted percentage cache 5
PHP_OPCACHE_VALIDATE_TIMESTAMPS Validate timestamps 1 or 0 1
PHP_OPCACHE_SAVE_COMMENTS Opcache Save Comments 0 or 1 1
PHP_OPCACHE_MAX_FILE_SIZE Opcache maximum file size 0
PHP_OPCACHE_OPTIMIZATION_LEVEL Opcache optimization level 0x7FFFBFF
PHP_POST_MAX_SIZE Maximum Input Size for POST 2G
PHP_TIMEOUT Maximum Script execution Time 180
PHP_UPLOAD_MAX_SIZE Maximum Input Size for Uploads 2G
PHP_WEBROOT Used with CONTAINER_MODE=php-fpm /www/html

Enabling / Disabling Specific Extensions

Enable extensions by using the PHP extension name ie redis as PHP_ENABLE_REDIS=TRUE. Core extensions are enabled by default are:

Parameter Default
PHP_ENABLE_APCU TRUE
PHP_ENABLE_BCMATH TRUE
PHP_ENABLE_BZ2 TRUE
PHP_ENABLE_CTYPE TRUE
PHP_ENABLE_CURL TRUE
PHP_ENABLE_DOM TRUE
PHP_ENABLE_EXIF TRUE
PHP_ENABLE_FILEINFO TRUE
PHP_ENABLE_GD TRUE
PHP_ENABLE_ICONV TRUE
PHP_ENABLE_IMAP TRUE
PHP_ENABLE_INTL TRUE
PHP_ENABLE_JSON TRUE
PHP_ENABLE_MBSTRING TRUE
PHP_ENABLE_MYSQLI TRUE
PHP_ENABLE_MYSQLND TRUE
PHP_ENABLE_OPCACHE TRUE
PHP_ENABLE_OPENSSL TRUE
PHP_ENABLE_PDO TRUE
PHP_ENABLE_PDO_MYSQL TRUE
PHP_ENABLE_PGSQL TRUE
PHP_ENABLE_PHAR TRUE
PHP_ENABLE_SESSION TRUE
PHP_ENABLE_SIMPLEXML TRUE
PHP_ENABLE_TOKENIZER TRUE
PHP_ENABLE_XML TRUE
PHP_ENABLE_XMLREADER TRUE
PHP_ENABLE_XMLWRITER TRUE

To enable all extensions in image use PHP_KITCHENSINK=TRUE. Head inside the image and see what extensions are available by typing php-ext list all

Debug Options

To enable XDebug set PHP_ENABLE_XDEBUG=TRUE. Visit the PHP XDebug Documentation to understand what these options mean. If you debug a PHP project in PHPStorm, you need to set server name using PHP_IDE_CONFIG to the same value as set in PHPStorm. Usual value is localhost, i.e. PHP_IDE_CONFIG="serverName=localhost".

For Xdebug 2 (php <= 7.1) you should set:

Parameter Description Default
PHP_XDEBUG_PROFILER_DIR Where to store Profiler Logs /www/logs/xdebug/
PHP_XDEBUG_PROFILER_ENABLE Enable Profiler 0
PHP_XDEBUG_PROFILER_ENABLE_TRIGGER Enable Profiler Trigger 0
PHP_XDEBUG_REMOTE_AUTOSTART Enable Autostarting as opposed to GET/POST 1
PHP_XDEBUG_REMOTE_CONNECT_BACK Enbable Connection Back 0
PHP_XDEBUG_REMOTE_ENABLE Enable Remote Debugging 1
PHP_XDEBUG_REMOTE_HANDLER XDebug Remote Handler dbgp
PHP_XDEBUG_REMOTE_HOST Set this to your IP Address 127.0.0.1
PHP_XDEBUG_REMOTE_PORT XDebug Remote Port 9090

For Xdebug 3 (php >= 7.2) you should set:

Parameter Description Default
PHP_XDEBUG_OUTPUT_DIR Where to store Logs /www/logs/xdebug/
PHP_XDEBUG_MODE This setting controls which Xdebug features are enabled. develop
PHP_XDEBUG_START_WITH_REQUEST Enable Autostarting as opposed to GET/POST default
PHP_XDEBUG_DISCOVER_CLIENT_HOST Xdebug will try to connect to the client that made the HTTP request. 1
PHP_XDEBUG_CLIENT_HOST Set this to your IP Address 127.0.0.1
PHP_XDEBUG_CLIENT_PORT XDebug Remote Port 9003

Networking

The following ports are exposed.

Port Description
9000 PHP-FPM

Maintenance

Inside the image are tools to perform modification on how the image runs.

Shell Access

For debugging and maintenance purposes you may want access the containers shell.

docker exec -it (whatever your container name is e.g. nginx-php-fpm) bash

PHP Extensions

If you want to enable or disable or list what PHP extensions are available, type php-ext help

Maintenance Mode

If you wish to turn the web server into maintenance mode showing a single page screen outlining that the service is being worked on, you can also enter into the container and type maintenance ARG, where ARG is either ON,OFF, or SLEEP (seconds) which will temporarily place the site in maintenance mode and then restore it back to normal after time has passed.

Contributions

Welcomed. Please fork the repository and submit a pull request for any bug fixes, features or additions you propose to be included in the image. If it does not impact my intended usage case, it will be merged into the tree, tagged as a release and credit to the contributor in the CHANGELOG.

Support

These images were built to serve a specific need in a production environment and gradually have had more functionality added based on requests from the community.

Usage

  • The Discussions board is a great place for working with the community on tips and tricks of using this image.
  • Consider sponsoring me for personalized support

Bugfixes

  • Please, submit a Bug Report if something isn't working as expected. I'll do my best to issue a fix in short order.

Feature Requests

  • Feel free to submit a feature request, however there is no guarantee that it will be added, or at what timeline.
  • Consider sponsoring me regarding development of features.

Updates

  • Best effort to track upstream changes, More priority if I am actively using the image in a production environment.
  • Consider sponsoring me for up to date releases.

License

MIT. See LICENSE for more details.

References

More Repositories

1

docker-freepbx

Dockerized FreePBX 15 w/Asterisk 17, Seperate MySQL Database support, and Data Persistence and UCP
496
star
2

docker-db-backup

Backup multiple database types on a scheduled basis with many customizable options
Dockerfile
472
star
3

docker-traefik-cloudflare-companion

Automatically Create CNAME records for containers served by Traefik
Python
274
star
4

docker-freescout

Dockerized Freescout Helpdesk
Dockerfile
146
star
5

docker-self-service-password

Dockerized LDAP Tollbox Self Service Password Changer with many customizable options
Dockerfile
115
star
6

docker-openldap

Dockerized OpenLDAP server with many customizable options
99
star
7

docker-jitsi-meet

Docker Jitsi Meet WebRTC conferencing system w/Prosody XMPP and s6 overlay
Dockerfile
64
star
8

docker-collabora-online

Dockerized Collabora Office Online with customizable options
Dockerfile
62
star
9

docker-osticket

Dockerized Help Desk Software
PHP
48
star
10

docker-tinc

Docker Tinc VPN Mesh server w/S6 Overlay Init, Zabbix Monitoring, and distributed configuration updating based on Alpine
Dockerfile
43
star
11

docker-postal

Dockerized Postal SMTP Server based on Alpine Linux and Ruby
Dockerfile
40
star
12

docker-fusiondirectory

Dockerized FusionDirectory LDAP Manager
Dockerfile
39
star
13

docker-lemonldap

Dockerized Authentication Server with Single Sign On SAML, OpenID Connect, CAS, and Header support
Dockerfile
39
star
14

docker-openldap-fusiondirectory

Dockerized OpenLDAP server with FusionDirectory Schema Support
34
star
15

docker-wordpress

Dockerized Wordpress Image with customizable options
Python
31
star
16

docker-alpine

Docker Alpine Linux Base Images
Dockerfile
30
star
17

docker-traefik

Dockerized Traefik Reverse Proxy with customizable options
Dockerfile
29
star
18

docker-mongodb-backup

Docker MongoDB Backup Container based on Alpine w/S6 init, Zabbix Monitoring
Dockerfile
28
star
19

docker-nginx-proxy-cloudflare-companion

Automatically update CNAME records when Docker container starts via Cloudflare
Python
27
star
20

docker-spamassassin

Docker Spamassassin Spam filtering based on Alpine Linux
Dockerfile
26
star
21

docker-clamav

Docker ClamAV Image with Zabbix Monitoring and Customizable Configuration
Dockerfile
23
star
22

docker-baserow

Dockerized Baserow No/Low code data management application based on Alpine
Dockerfile
22
star
23

docker-nginx

Dockerzed webserver with many customizable options
Dockerfile
22
star
24

docker-nextcloud

Dockerized Nextcloud Server with many customizable options
17
star
25

docker-gitlab-ee

Dockerized Gitlab Enterprise Edition
Dockerfile
17
star
26

docker-debian

Docker Debian Base Images
Dockerfile
15
star
27

docker-discourse

Dockerized Discourse Forum
Dockerfile
15
star
28

docker-backuppc

Docker BackupPC with Zabbix monitoring support
Perl
15
star
29

docker-gcds

Docker Google Cloud Directory Sync service (GADS) w/S6 Overlay, Zabbix Monitoring
Dockerfile
14
star
30

docker-mariadb-backup

Docker MariaDB Backup Container w/ S6 Overlay, Zabbix Monitoring based on Alpine
Dockerfile
13
star
31

docker-zabbix

Dockerized Zabbix Server, Proxy, and Frontend
Dockerfile
13
star
32

docker-insync

Docker Insync Headless Client
Dockerfile
12
star
33

docker-rspamd

Dockerized Anti Spam Filter
Python
12
star
34

docker-nginx-ldap

Docker Nginx Image w/LDAP Authentication, Zabbix agent monitoring, S6 init, logrotate based on Alpine
Dockerfile
11
star
35

docker-bookstack

Dockerized Information Manager
Dockerfile
11
star
36

docker-mariadb

Docker MariaDB server w/ S6 Overlay, Zabbix Monitoring based on Alpine
11
star
37

docker-gitlab

Dockerized Gitlab CE w/Alpine Linux, Zabbix Monitoring and S6 Overlay
Dockerfile
10
star
38

docker-staytus

Docker Staytus Image w/s6 overlay, zabbix monitoring based on Alpine
HTML
10
star
39

docker-leantime

Dockerized Project Managment tool with many configurable options
Dockerfile
10
star
40

docker-otrs

Dockerized OTRS ITSM Helpdesk/Ticketing System based on Alpine w/Nginx
Dockerfile
9
star
41

docker-unbound

Docker Unbound DNS Resolver based on Alpine
Dockerfile
9
star
42

docker-postgres

Dockerized Postgresql Server with multiple databases/users, replication, and monitoring support
Dockerfile
9
star
43

docker-postfix

Dockerized MTA with many customizable features, LDAP, SASL, Milter, Relay Support
Dockerfile
8
star
44

docker-matomo

Dockerized Matomo (Piwik) Analytics
Dockerfile
8
star
45

docker-yourls

Dockerized YOURLS link shortener based on Alpine
Dockerfile
8
star
46

docker-invoiceninja

Dockerized Invoicing web application
Dockerfile
7
star
47

docker-nodejs

Docker NodeJS Base Images
7
star
48

docker-postfix-relay

Dockerized Postfix Relay for easy SMTP capabilities
Shell
7
star
49

docker-openvpn

Dockerized OpenVPN server w/Alpine+Debian Variants w/s6 overlay, and LDAP Authentication support
7
star
50

docker-rocketchat

Docker Rocketchat Server with S6 Initsystem and Zabbix Monitoring based on Alpine
6
star
51

docker-kopano

Dockerized Kopano Groupware server
Dockerfile
6
star
52

docker-n8n

Dockerized n8n workflow automation tool
Dockerfile
6
star
53

docker-listmonk

Dockerized Listmonk Mailing List server built iwth Alpine w/Zabbix Monitoring
Dockerfile
6
star
54

docker-cpuminer

Cryptocurrency Miner based on Alpine
6
star
55

docker-kopano-core

Dockerized Kopano Groupware Server
6
star
56

docker-grafana

Dockerfile
5
star
57

docker-moodle

Dockerized Moodle Learning Management System
Dockerfile
5
star
58

docker-loki

Dockerized Loki Log Analyzer
Dockerfile
5
star
59

docker-teampass

Dockerized Password Vault for Teams based on Alpine w/nginx,php-fpm
Dockerfile
5
star
60

docker-orbeon

Docker Orbeon Forms CE w/S6 Init, Tomcat, based on Alpine
Dockerfile
5
star
61

docker-redis

Docker Redis Server with S6 Initsystem and Zabbix Monitoring based on Alpine
5
star
62

docker-elasticsearch

Dockerized Elasticsearch based on Alpine linux
4
star
63

fusiondirectory-plugin-kopano

Plugin to manage users/groups for Kopano (fork of Zarafa) within Fusion Directory LDAP Manager
PHP
4
star
64

docker-novnc

Run GUI applications within a browser - Base image
Dockerfile
4
star
65

docker-flarum

Dockerized Flarum Web Forum Software based on Alpine
Shell
4
star
66

docker-registry

Dockerized Docker Registry
Dockerfile
4
star
67

docker-rabbitmq

Dockerized RabbitMQ server
Python
4
star
68

docker-gitlab-runner

Docker Gitlab runner w/ Zabbix monitoring support based on Alpine
4
star
69

docker-openeats

Dockerized Openeats Recipe manager based on Alpine Linux w/Zabbix Monitoring
Dockerfile
3
star
70

docker-restic

Dockerized Backup application
Dockerfile
3
star
71

docker-dovecot

Docker Dovecot IMAP server based on Alpine w/LDAP Support
TSQL
3
star
72

docker-uptimekuma

Dockerized Service availability monitoring system
Dockerfile
3
star
73

docker-draw-io

Docker Draw.IO image based on Alpine and Nginx
3
star
74

docker-logrotate

Docker Logrotate to keep logfiles compressed and rotated based on Alpine
Shell
3
star
75

docker-mailhog

Dockerized SMTP Test server
Dockerfile
3
star
76

docker-cachet

Dockerized Cachet Status monitoring application based on Alpine Linux
Dockerfile
3
star
77

docker-sentry

Dockerized Sentry.IO Exception tracking system based on Debian w/LDAP and SAML
Python
3
star
78

docker-airsonic-advanced

Dockerized Airsonic Advanced Server based on Alpine
Dockerfile
3
star
79

docker-limesurvey

Dockerized Limesurvey application based on Alpine
Dockerfile
3
star
80

docker-mongo

Docker MongoDB server w/ S6 Overlay, Zabbix Monitoring based on Alpine
3
star
81

docker-haraka

Docker Haraka MTA based on Alpine
JavaScript
3
star
82

docker-ruby

Docker Ruby base images w/ S6 Overlay and Zabbix monitoring support
3
star
83

docker-ubuntu

Dockerized Ubuntu Base Images
Dockerfile
2
star
84

docker-memcached

Docker Memcached Server w/ S6 Initsystem and Zabbix Monitoring based on Alpine
Dockerfile
2
star
85

home

Home-Manager configuration ala Nix flakes
Nix
2
star
86

docker-kopano-meet

Dockerfile
2
star
87

docker-soulseek

Dockerized Soulseek Client
Dockerfile
2
star
88

docker-kopano-kapi

Dockerfile
2
star
89

docker-kopano-konnect

Dockerfile
2
star
90

docker-olefy

Dockerized Olefy TCP listener for OLE Tools
Dockerfile
2
star
91

docker-logchimp

Dockerized Logchimp Application
Dockerfile
2
star
92

docker-transmission

Dockerized Transmission client
Dockerfile
2
star
93

docker-dind

Docker in Docker Image with Zabbix monitoring Support and --squash --compress options by default based on Alpine
Dockerfile
2
star
94

docker-matrix-bridges

Dockerized Matrix Bridges to interconnect services
Dockerfile
2
star
95

docker-monica

Dockerized Monica PRM
Dockerfile
2
star
96

tiredofit

2
star
97

docker-minio

Dockerized Minio Server based on Alpine
Dockerfile
2
star
98

docker-tomcat

Docker Apache Tomcat based on Alpine
2
star
99

docker-mongo-builder

Docker Image to build MongoDB and associated tools for Alpine Edge from aports/non-free
Dockerfile
2
star
100

nixos-config

NixOS configurations
Nix
1
star