Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
docker-compose configuration for PHP with NGINX and MySQL, including sendmail, MailDev and phpmyadmin

docker-compose configuration

This configuration basically resembles a mix of cmaessen's docker-php-sendmail project and mikechernev's NGINX configuration.

It includes the following:

  • PHP
    • FPM configured for NGINX
    • XDebug connecting to the docker host
    • place .php files into a directory named "code" for them to be executable
  • sendmail
  • MailDev
    • you might want to adjust the root mail address in Dockerfile:17
    • port 8081
  • MySQL
    • you also might want to adjust the default password (which is "password") in docker-compose.yml
    • port 3306
  • phpmyadmin
    • defaults see docker-compose.yml, also consider changing the password here too
    • port 8082
image: nginx:latest
- "8080:80"
- ./code:/code
- ./nginx.conf:/etc/nginx/conf.d/default.conf
- php
build: .
- ./code:/code
XDEBUG_CONFIG: remote_host=host.docker.internal
- mysql
- maildev
image: mysql:latest
- "3306:3306"
image: phpmyadmin/phpmyadmin
- mysql:db
- "8082:80"
- PMA_USER=root
- PMA_PASSWORD=password
image: djfarrelly/maildev
- "8081:80"
# see for more information
FROM php:5-fpm
RUN apt-get update && apt-get install -q -y ssmtp mailutils && rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-install mysql mysqli sysvsem
RUN pecl install xdebug-2.5.5 \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "[XDebug]" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_log=/tmp/xdebug.log" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=on" >> /usr/local/etc/php/conf.d/xdebug.ini
RUN echo "hostname=localhost.localdomain" > /etc/ssmtp/ssmtp.conf \
&& echo "root=root@localhost" >> /etc/ssmtp/ssmtp.conf \
&& echo "mailhub=maildev" >> /etc/ssmtp/ssmtp.conf \
&& echo "sendmail_path=sendmail -i -t" >> /usr/local/etc/php/conf.d/php-sendmail.ini
RUN echo "[Date]" >> /usr/local/etc/php/conf.d/php-sendmail.ini \
&& echo "date.timezone = Europe/Amsterdam" >> /usr/local/etc/php/conf.d/php-sendmail.ini
RUN echo "localhost localhost.localdomain" >> /etc/hosts
# see for more information
server {
index index.php index.html;
server_name php-docker.local;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /code;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 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;
Copy link

AdamDenoon commented Jul 26, 2018

I'm getting a "sendmail: Cannot open mailhub:25" error whenever trying to use sendmail from the PHP container. I temporarily set the permissions on ssmtp to 777 for testing, and still got the same error. Is it because I require a different root mail address?

(Edit needed: Your documentation says the root mail address line is line 10 in the Dockerfile, but after adding xdebug it became line 17)

Copy link

Displee commented May 28, 2020

I see that phpmyadmin uses apache to run. Does that mean you have 2 different web servers running with this configuration? Nginx and apache?

Copy link

Lisendra commented Oct 16, 2020

I see that phpmyadmin uses apache to run. Does that mean you have 2 different web servers running with this configuration? Nginx and apache?

you don't need apache to run phpmyadmin, it's a simple app as any other, just setup nginx to point a block for it.

Copy link

CristoferPortela commented Nov 26, 2020

Thank you very much! I'm trying to run php and nginx have ages and nothing! No tutorials worked, this is the first time I found something useful and working

Copy link

mohsadki commented Oct 24, 2021

I join @CristoferPortela it's the first time that I found a stack that works from the first shot :)
thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment