This was origionally a clone of Nanoninja's docker-nginx-php-mysql. A docker-compose setup that was developed to have a full web stack for developers to get up an running quickly. This project is still in development, but for the most part is good to go. This is by no means a lightweight stack; it was designed to removie the heavy lifting
- Nginx w\ Node
- This is the web server which will host your code.
- PHP-FPM
- PHP server.
- Composer
- Composer for all your dependencies.
- MailHog
- Gotta trap them all (emails that is).
- PHPMyAdmin
- Easy GUI access for mysql.
- MySQL
- MySQL server.
- Redis
- Redis server (I use this for cache and sessions)
- LocalStack
- AWS for local development.
- Currently I am only supporting S3 and SQS.
- AWS-CLI
- CLI to access localstack.
- For the endpoint please use the LOCALSTACK_HOST from the .env
- DNS Proxy Server
- Used in conjunction with the nginx proxy server to allow easy urls.
- During load and shutdown of this service you may see a small hiccup in your network connection. Please see Troubleshooting
- If not shutdown correctly this may interrupt your network connection. Please see Troubleshooting
- Nginx
- Used as a proxy server.
- Works with DNS proxy server to add SSL and hide ports on many services.
- Generate Certificate
- Used to generate SSL certs.
-
Before installing project make sure the following prerequisites have been met.
-
We’ll download the code from its repository on GitHub.
-
This docker compose file works heavily off of the .env file. We will get it setup and ready to go.
-
Setup SSL Certificates [
Required
]We'll generate and configure SSL certificate for nginx before running server.
-
Configure Xdebug [
Optional
]We'll configure Xdebug for IDE (PHPStorm or Netbeans).
-
By this point we’ll have all the project pieces in place.
-
Use Makefile [
Optional
]When developing, you can use
Makefile
for doing recurrent operations. -
When running, you can use docker commands for doing recurrent operations.
For now, this project has been mainly created for Unix (Linux/MacOS)
.
Linux Mint 18.1 Serena
I will try to test and add more OSes to this list, but I can not verify any MacOS. If you can, please create a PR updating this list.
All requisites should be available for your distribution. The most important are :
Check if docker-compose
is already installed by entering the following command :
which docker-compose
Check Docker Compose compatibility :
The following is optional but makes life more enjoyable :
which make
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
To install Git, download it and install following the instructions :
git clone https://github.com/rihoj/docker-full-stack.git
Go to the project directory :
cd docker-full-stack
There are three steps to setting up your environment
-
Edit
/etc/hosts
file# Add the following line to the file. 127.0.0.2 rp.io
It is important to know what you are doing in this file. The rp.io can be changed to your preferred domain. This will be referenced in the
.env
file. -
Edit
.env
fileI have tried to explain everything in the env. Please see that file.
-
Update
./conf/dns/config.json
If you have changed the $ROOT_DOMAIN you will need to update the DNS configuration. Hopefully soon this will be configured through the
.env
-
Generate SSL certificates
source .env && sudo docker run --rm -v $(pwd)/conf/ssl:/certificates -e "SERVER=*.$ROOT_DOMAIN" jacoelho/generate-certificate
or
make gen-certs
This is a legacy section from Nanoninja. I do not use xdebug and have not been able to test this yet.
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.
-
Get your own local IP address :
sudo ifconfig
-
Edit php file
etc/php/php.ini
and comment or uncomment the configuration as needed. -
Set the
remote_host
parameter with your IP :xdebug.remote_host=192.168.0.1 # your IP
-
Start the application :
sudo docker-compose up -d
Please wait this might take a several minutes...
sudo docker-compose logs -f # Follow log output
-
Open your favorite browser :
Access your sites with the following logic: https://$X_DOMAIN.$ROOT_DOMAIN
I.E. for the phpmyadmin service you would to go to: https://phpmyadmin.rp.io
-
Stop and clear services
sudo docker-compose down -v
When developing, you can use Makefile for doing the following operations :
Name | Description |
---|---|
apidoc | Generate documentation of API |
clean | Clean directories for reset |
code-sniff | Check the API with PHP Code Sniffer (PSR2 ) |
composer-up | Update PHP dependencies with composer |
docker-start | Create and start containers |
docker-stop | Stop and clear all services |
gen-certs | Generate SSL certificates for nginx |
logs | Follow log output |
mysql-dump | Create backup of all databases |
mysql-restore | Restore backup of all databases |
phpmd | Analyse the API with PHP Mess Detector |
test | Test application with phpunit |
Name | Description |
---|---|
gen-certs | Generate SSL certificates for nginx |
docker-start | Create and start containers |
docker-stop | Stop and clear all services |
make docker-stop
will clear your data.
Start the application :
sudo make docker-start
Show help :
make help
sudo docker run --rm -v $(pwd)/web/app:/app composer require symfony/yaml
sudo docker run --rm -v $(pwd)/web/app:/app composer update
sudo docker-compose exec -T php php -d memory_limit=256M -d xdebug.profiler_enable=0 ./app/vendor/bin/apigen generate app/src --destination ./app/doc
sudo docker-compose exec -T php ./app/vendor/bin/phpunit --colors=always --configuration ./app
Fixing standard code with PSR2
sudo docker-compose exec -T php ./app/vendor/bin/phpcbf -v --standard=PSR2 ./app/src
Checking the standard code with PSR2
sudo docker-compose exec -T php ./app/vendor/bin/phpcs -v --standard=PSR2 ./app/src
Analyzing source code with PHP Mess Detector
sudo docker-compose exec -T php ./app/vendor/bin/phpmd ./app/src text cleancode,codesize,controversial,design,naming,unusedcode
sudo docker-compose exec php php -m
sudo docker exec -it mysql bash
and
mysql -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD"
mkdir -p data/db/dumps
source .env && sudo docker exec $(sudo docker-compose ps -q mysqldb) mysqldump --all-databases -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" > "data/db/dumps/db.sql"
source .env && sudo docker exec -i $(sudo 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.
source .env && sudo docker exec $(sudo 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"
source .env && sudo docker exec -i $(sudo docker-compose ps -q mysqldb) mysql -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" < "data/db/dumps/YOUR_DB_NAME_dump.sql"
Connecting MySQL from PDO
<?php
try {
$dsn = 'mysql:host=mysql.io;dbname=test;charset=utf8;port=3306';
$pdo = new PDO($dsn, 'dev', 'dev');
} catch (PDOException $e) {
echo $e->getMessage();
}
?>
The DNS proxy server edits your local /etc/resolv.conf
file. This means that during the start up and shutdown your Internet may see hiccups in connection. This is normal, please bear with it.
If the service does not shut down correctly you may see your internet not work at all. This can be fixed.
Option 1: Edit your local /etc/resolv.conf
remove the lines with the comment # dps-entry
and uncomment lines with # dps-comment
I welcome any thoughts, feedback, or bugs! Please create an issue and I will get to it as soon as possible!
-
Move the web directory into the repository.
-
Make DNS config.json be able to use template.
-
Update makefile with accurate commands
-
Update documentation.
-
Custom roll AWS-CLI to not need endpoints.
-
Update
.travis.yml
to update tests. -
Test more operating systems.