Docker running Nginx, PHP-FPM, MySQL.
To run the docker commands without using sudo you must add the docker group to your-user:
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 :
docker composeOn 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.
sudo apt install build-essentialYou should be careful when installing third party web servers such as MySQL or Nginx.
This project use the following ports :
| Server | Port |
|---|---|
| MySQL | 8989 |
| Nginx | 8000 |
| Nginx SSL | 3000 |
.
├── data
│ └── db
│ ├── dumps
│ └── mysql
├── docker-compose.yml
├── etc
│ ├── nginx
│ │ ├── default.conf
│ │ └── default.template.conf
│ ├── php
│ │ └── php.ini
│ └── ssl
└── web
└── public
└── index.phpYou 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.
-
Generate SSL certificates
source .env && docker run --rm -v $(pwd)/etc/ssl:/certificates -e "SERVER=$NGINX_HOST" jacoelho/generate-certificate
-
Configure Nginx
Do not modify the
etc/nginx/default.conffile, it is overwritten byetc/nginx/default.template.confEdit nginx file
etc/nginx/default.template.confand uncomment the SSL server section :# server { # server_name ${NGINX_HOST}; # # listen 443 ssl; # fastcgi_param HTTPS on; # ... # }
Connecting MySQL from PDO
<?php
try {
$dsn = 'mysql:host=mysql;dbname=test;charset=utf8;port=3306';
$pdo = new PDO($dsn, 'dev', 'dev');
} catch (PDOException $e) {
echo $e->getMessage();
}
?>