Docker nginx php mysql
https://github.com/nanoninja/docker-nginx-php-mysql
docker-nginx-php-mysql
Docker running Nginx, PHP-FPM, Composer, MySQL and PHPMyAdmin.
Configure Xdebug [Optional
]
We'll configure Xdebug for IDE (PHPStorm or Netbeans).
Use Makefile [Optional
]
When developing, you can use Makefile
for doing recurrent operations.
To run the docker commands without using sudo you must add the docker group to your-user :
Copy sudo usermod -aG docker your-user
For now, this project has been mainly created for Unix (Linux/MacOS)
. Perhaps it could work on Windows.
All requisites should be available for your distribution. The most important are :
Check if docker-compose
is already installed by entering the following command :
Check Docker Compose compatibility :
The following is optional but makes life more enjoyable :
On Ubuntu and Debian these are available in the meta-package build-essential. On other distributions, you may need to install the GNU C++ compiler separately.
Copy sudo apt install build-essential
You should be careful when installing third party web servers such as MySQL or Nginx.
This project use the following ports :
To install Git , download it and install following the instructions :
Copy git clone https://github.com/nanoninja/docker-nginx-php-mysql.git
Go to the project directory :
Copy cd docker-nginx-php-mysql
Copy .
├── Makefile
├── README.md
├── data
│ └── db
│ ├── dumps
│ └── mysql
├── doc
├── docker-compose.yml
├── etc
│ ├── nginx
│ │ ├── default.conf
│ │ └── default.template.conf
│ ├── php
│ │ └── php.ini
│ └── ssl
└── web
├── app
│ ├── composer.json.dist
│ ├── phpunit.xml.dist
│ ├── src
│ │ └── Foo.php
│ └── test
│ ├── FooTest.php
│ └── bootstrap.php
└── public
└── index.php
You can change the host name by editing the .env
file.
If you modify the host name, do not forget to add it to the /etc/hosts
file.
Copy Generate SSL certificates
Copy ```
source .env && docker run --rm -v $(pwd)/etc/ssl:/certificates -e "SERVER=$NGINX_HOST" jacoelho/generate-certificate
```
2. Configure Nginx
Copy Do not modify the `etc/nginx/default.conf` file, it is overwritten by `etc/nginx/default.template.conf`
Edit nginx file `etc/nginx/default.template.conf` and uncomment the SSL server section :
```
# server {
# server_name ${NGINX_HOST};
#
# listen 443 ssl;
# fastcgi_param HTTPS on;
# ...
# }
```
If you use another IDE than PHPStorm or Netbeans , go to the remote debugging section of Xdebug documentation.
For a better integration of Docker to PHPStorm, use the documentation .
Copy Get your own local IP address :
Copy ```
sudo ifconfig
```
2. Edit php file etc/php/php.ini
and comment or uncomment the configuration as needed. 3.
Copy Set the `remote_host` parameter with your IP :
```
xdebug.remote_host=192.168.0.1 # your IP
```
Copy Copying the composer configuration file :
Copy ```
cp web/app/composer.json.dist web/app/composer.json
```
2. Start the application :
Copy ```
docker-compose up -d
```
**Please wait this might take a several minutes...**
```
docker-compose logs -f # Follow log output
```
3.
Copy Open your favorite browser :
- [http://localhost:8000](http://localhost:8000/)
- [https://localhost:3000](https://localhost:3000/) ([HTTPS](https://github.com/nanoninja/docker-nginx-php-mysql#configure-nginx-with-ssl-certificates) not configured by default)
- [http://localhost:8080](http://localhost:8080/) PHPMyAdmin (username: dev, password: dev)
4.
Copy Stop and clear services
```
docker-compose down -v
```
When developing, you can use Makefile for doing the following operations :
Start the application :
Show help :
Copy docker run --rm -v $(pwd)/web/app:/app composer require symfony/yaml
Copy docker run --rm -v $(pwd)/web/app:/app composer update
Copy docker run --rm -v $(pwd):/data phpdoc/phpdoc -i=vendor/ -d /data/web/app/src -t /data/web/app/doc
Copy docker-compose exec -T php ./app/vendor/bin/phpunit --colors=always --configuration ./app
Copy docker-compose exec -T php ./app/vendor/bin/phpcbf -v --standard=PSR2 ./app/src
Copy docker-compose exec -T php ./app/vendor/bin/phpcs -v --standard=PSR2 ./app/src
Copy docker-compose exec -T php ./app/vendor/bin/phpmd ./app/src text cleancode,codesize,controversial,design,naming,unusedcode
Copy docker-compose exec php php -m
Copy docker exec -it mysql bash
and
Copy mysql -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD"
Copy mkdir -p data/db/dumps
Copy source .env && docker exec $(docker-compose ps -q mysqldb) mysqldump --all-databases -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" > "data/db/dumps/db.sql"
Copy source .env && docker exec -i $(docker-compose ps -q mysqldb) mysql -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" < "data/db/dumps/db.sql"
Notice:
Replace "YOUR_DB_NAME" by your custom name.
Copy source .env && docker exec $(docker-compose ps -q mysqldb) mysqldump -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" --databases YOUR_DB_NAME > "data/db/dumps/YOUR_DB_NAME_dump.sql"
Copy source .env && docker exec -i $(docker-compose ps -q mysqldb) mysql -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" < "data/db/dumps/YOUR_DB_NAME_dump.sql"
Copy <?php
try {
$dsn = 'mysql:host=mysql;dbname=test;charset=utf8;port=3306';
$pdo = new PDO($dsn, 'dev', 'dev');
} catch (PDOException $e) {
echo $e->getMessage();
}
?>