Skip to content

Instantly share code, notes, and snippets.

Embed
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:

  • NGINX
  • 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
web:
image: nginx:latest
ports:
- "8080:80"
volumes:
- ./code:/code
- ./nginx.conf:/etc/nginx/conf.d/default.conf
links:
- php
php:
build: .
volumes:
- ./code:/code
environment:
XDEBUG_CONFIG: remote_host=host.docker.internal
links:
- mysql
- maildev
mysql:
image: mysql:latest
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=password
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- mysql:db
ports:
- "8082:80"
environment:
- PMA_USER=root
- PMA_PASSWORD=password
- PHP_UPLOAD_MAX_FILESIZE=100MB
maildev:
image: djfarrelly/maildev
ports:
- "8081:80"
# see https://github.com/cmaessen/docker-php-sendmail 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 xdebug.so)" > /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 https://github.com/mikechernev/dockerised-php 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;
}
}
@AdamDenoon
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)

@Displee
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?

@Lisendra
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.

@CristoferPortela
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

@mohsadki
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