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 compose
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.
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 :
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.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.
-
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.conf
file, it is overwritten byetc/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; # ... # }
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();
}
?>