4.1 KiB
4.1 KiB
Nginx PHP MySQL
Docker running Nginx, PHP-FPM, Composer, MySQL and PHPMyAdmin.
Images to use
Start using it
-
Download it :
git clone https://github.com/nanoninja/docker-nginx-php-mysql.git cd docker-nginx-php-mysql -
Copying the composer configuration file :
cp web/app/composer.json.dist web/app/composer.json -
Start :
docker-compose up -dPlease wait this might take a several minutes...
-
Open your favorite browser :
- http://localhost:8000
- https://localhost:3000 (HTTPS not configured by default)
- phpMyAdmin (user: dev, pass: dev)
-
Stop :
docker-compose stop && docker-compose kill && docker-compose rm -f
Makefile
When developing, you can use the Makefile for doing the following operations :
| Name | Description |
|---|---|
| apidoc | Generate documentation of API |
| clean | Clean directories for reset |
| composer-up | Update php composer |
| docker-start | Create and start containers |
| docker-stop | Stop all services |
| docker-sweep | Sweep old containers and volumes |
| gen-certs | Generate SSL certificates for nginx |
| mysql-dump | Create backup of whole database |
| mysql-restore | Restore backup from whole database |
| test | Test application with phpunit |
Example :
make docker-start
Show help
make help
Directory tree
.
├── Makefile
├── README.md
├── bin
│ └── linux
│ └── clean.sh
├── data
│ └── db
│ └── mysql
├── docker-compose.yml
├── etc
│ ├── nginx
│ │ └── default.conf
│ ├── php
│ │ └── php.ini
│ └── ssl
└── web
├── app
│ ├── composer.json.dist
│ ├── phpunit.xml.dist
│ ├── src
│ │ └── Foo.php
│ └── test
│ ├── FooTest.php
│ └── bootstrap.php
└── public
└── index.php
Connecting from PDO
<?php
$dsn = 'mysql:host=mysql;dbname=test;charset=utf8;port=3306';
$pdo = new PDO($dsn, 'dev', 'dev');
?>
Updating composer
docker run --rm -v $(PWD)/web/app:/app composer/composer update
MySQL Container shell access
docker exec -it mysql bash
and
mysql -uroot -proot
Creating database dumps
source .env && docker exec -i $(docker-compose ps -q mysqldb) mysqldump --all-databases -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" > "$MYSQL_DUMPS_DIR/db.sql"
or
source .env && docker exec -i $(docker-compose ps -q mysqldb) mysqldump test -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" > "$MYSQL_DUMPS_DIR/test.sql"
Generating SSL certificates
-
Generate certificates
docker run --rm -v $(PWD)/etc/ssl:/certificates -e "SERVER=localhost" jacoelho/generate-certificate -
Configure Nginx
Edit nginx file etc/nginx/default.conf and uncomment the server section :
# server { # ... # }
Generating API Documentation
docker exec -i $(docker-compose ps -q php) php ./app/vendor/apigen/apigen/bin/apigen generate -s app/src -d app/doc
Cleaning project
./bin/linux/clean.sh $(pwd)