- PHP-FPM 8.3.13
- PHP-FPM 8.2.25
- PHP-FPM 8.1.30
- PHP-FPM 8.0.30
- PHP-FPM 7.4.33
- Apache 2 + PHP 8.1.30
- Apache 2 + PHP 7.4.33
- Apache 2 + PHP 5.6.40
To use old versions of PHP you can check docker-compose-php v. 0.1.9
All you have to do is run these commands:
sudo vim /etc/hosts
and add
127.0.0.1 site.test
cp mysql.env.example mysql.env
cp docker/nginx/config/templates/site.test.conf-php-82 docker/nginx/config/site.test.conf
mkdir -p projects/site.test
echo '<?php echo phpversion();' > projects/site.test/index.php
make up
Example of using another PHP versions
cp mysql.env.example mysql.env
#edit mysql.env
#you can choose the template with specific php version
cp templates/docker-compose-php-81.yml docker-compose.yml
#and copy specific config for Nginx + PHP-FPM
cp docker/nginx/config/templates/site.test.conf-php-81 docker/nginx/config/site.test.conf
#or copy configs for Nginx + Apache PHP
cp templates/docker-compose-apache-php-74.yml docker-compose.yml
cp docker/nginx/config/templates/site.test.conf-apache-php-74 docker/nginx/config/site.test.conf
cp docker/apache-php-74/config/templates/site.test.conf docker/apache-php-74/config/sites-enabled/site.test.conf
mkdir -p projects/site.test
echo '<?php echo phpversion();' > projects/site.test/index.php
make up
http://localhost:8025 - mailhog (super:demo)
http://localhost:8080 - adminer (super:demo)
http://site.test - test site
For ease of management, all basic commands are included in the Makefile. To list the available commands, run cat Makefile.
#runs docker-compose up -d
make up
#runs docker-compose stop
make stop
#runs docker-compose ps
make ps
#runs docker-compose logs -tail=100 -f (php-82|db|mailhog|nginx)
make logs name=php-82
Database host - db
Open docker/nginx/.htpasswd
and replace its contents.
In the terminal, using the id command, we get the digital identifier of our user and group. Then uncomment the line
#RUN usermod -u 1050 www-data && groupmod -g 1050 www-data
In docker/php-82/build/Dockerfile
and replace id 1050 with your identifiers there.
We start containers with a rebuild
#runs docker-compose up -d --build
make upb
Open docker/php-82/config/php.ini
Or edit the php-fpm settings - www.conf
Uncomment the block with the container of the required php version in docker-compose.yml.
In Nginx config for the site, comment out the old upstream and uncomment the new one.
#runs docker-compose stop && docker-compose up -d --build
make st upb
In the case of Apache in the Nginx config, you need to comment out the entire block for PHP-FPM and uncomment the one below for Apache. Also do not forget to tweak Apache configs.
Just copy config docker/nginx/config/templates/site.test.conf
and tweak it.
In the case of using the container with apache, you must also fix the docker/apache-php-56/config/sites-enabled/site.test.conf
config.
There are examples of Nginx config files in docker/nginx/config/disabled/
make php
mysql -uroot -hdb -pMYSQL_ROOT_PASSWORD
Example with importing SQL-dump:
make php
mysql -uroot -hdb -pMYSQL_ROOT_PASSWORD
> create database test;
mysql -uroot -hdb -pMYSQL_ROOT_PASSWORD test < dump.sql
#runs docker-compose -f docker-compose.mycli.yml run --rm mycli /bin/ash -c "mycli -uroot -hdb -p\$$MYSQL_ROOT_PASSWORD" || true
make mycli
#runs docker-compose exec $(name) /bin/sh || true
make exec name=php-82
The password is registered in the MYSQL_ROOT_PASSWORD parameter in mysql.env
Changed in mysql.env file
* * * * * /usr/local/bin/docker-compose -f /srv/www/docker-compose-php/docker-compose.yml exec php-82 /srv/projects/site.test/yii api/send
#runs docker-compose -f docker-compose.acme.yml run --rm acme acme.sh --issue -d `echo $(d) | sed 's/,/ \-d /g'` -w /acme-challenge
make ssl d="site.ru,www.site.ru"
SSL certificates are saved in the docker/nginx/ssl directory
. To make it work you need to uncomment
lines in the docker-compose.yml
config
# - ./docker/nginx/ssl:/etc/nginx/ssl:ro
Also uncomment the line
# -"443:443"
crontab
00 3 * * * /usr/local/bin/docker-compose -f /srv/www/docker-compose-php/docker-compose.acme.yml run --rm acme acme.sh --cron
02 3 * * * /usr/local/bin/docker-compose -f /srv/www/docker-compose-php/docker-compose.yml exec -T nginx nginx -t -q && /usr/local/bin/docker-compose -f /srv/www/docker-compose-php/docker-compose.yml restart nginx
If you need to run acme.sh
for some other purpose, you can do this with this command:
make acme
#runs docker-compose -f docker-compose.node.yml run --rm node /bin/ash || true
make node
#runs docker-compose -f docker-compose.mysqltuner.yml run --rm mysqltuner /bin/ash -c "/opt/mysqltuner --user root --host db --pass \$$MYSQL_ROOT_PASSWORD --forcemem $(mem)" || true
make mysqltuner mem=4096