Local docker environment for PHP development.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
images/php
logs
mysql
nginx
redis
www/hello.dev
README.md
docker-compose.yml
mysql.sql

README.md

Docker PHP environment

Local docker environment for PHP development with components:

  • PHP 7.3
  • Nginx
  • MySQL 8
  • Redis

Features

We'll follow important docker rule - one service per container. Also, we'll mount docker volumes to keep code and data on our host machine and use it in containers, so our containers will work for "read-only" purpose and can be stopped, deleted or replaced without losing data.

Folders structure

  • www - projects files
  • mysql - mysql data
  • logs - different logs
  • nginx - nginx conf files
  • images - docker images

Execute

Just run

docker-compose up -d

Test build

Open the browser and go to localhost:8080. You'll see:

Check MySQL connection, run localhost:8080/db.php

Known issues

In new versions of PHP and MySQL you may see an error:

SQLSTATE[HY000] [2002] Connection refused

Just connect to a MySQL container and run commands:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'secret';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'secret';
ALTER USER 'default'@'%' IDENTIFIED WITH mysql_native_password BY 'secret';

To connect to Mysql container find container id by running

docker container ls

Connect to the container

docker exec -it CONTAINER_ID /bin/bash 

Then connect to mysql from command line

mysql -uroot -p.