Adapt Nginx configuration with PHP volume

This commit is contained in:
Vincent Letourneau
2017-07-27 18:51:52 +02:00
parent b7683f79a6
commit e80b05d855
4 changed files with 69 additions and 42 deletions

104
README.md
View File

@@ -1,10 +1,6 @@
# Nginx PHP MySQL # Nginx PHP MySQL
Docker running Nginx, PHP-FPM, MySQL and PHPMyAdmin. Docker running Nginx, PHP-FPM, Composer, MySQL and PHPMyAdmin.
**THIS ENVIRONMENT SHOULD ONLY BE USED FOR DEVELOPMENT!**
**DO NOT USE IT IN PRODUCTION!**
## Images to use ## Images to use
@@ -20,51 +16,87 @@ Docker running Nginx, PHP-FPM, MySQL and PHPMyAdmin.
1. Download it : 1. Download it :
```sh ```sh
$ git clone https://github.com/nanoninja/docker-nginx-php-mysql.git git clone https://github.com/nanoninja/docker-nginx-php-mysql.git
$ cd docker-nginx-php-mysql
cd docker-nginx-php-mysql
``` ```
2. Copying the composer configuration file : 2. Copying the composer configuration file :
```sh ```sh
# Convenient to avoid overwriting the configuration with Git. cp web/app/composer.json.dist web/app/composer.json
$ cp web/app/composer.json.dist web/app/composer.json
``` ```
3. Run : 3. Start :
```sh ```sh
$ docker-compose up -d docker-compose up -d
``` ```
**Please wait this might take a several minutes...**
4. Open your favorite browser : 4. Open your favorite browser :
* [http://localhost:8000](http://localhost:8000/) * [http://localhost:8000](http://localhost:8000/)
* [https://localhost:3000](https://localhost:3000/) ([HTTPS](https://github.com/nanoninja/docker-nginx-php-mysql#generating-ssl-certificates) not configured by default) * [https://localhost:3000](https://localhost:3000/) ([HTTPS](https://github.com/nanoninja/docker-nginx-php-mysql#generating-ssl-certificates) not configured by default)
* [phpMyAdmin](http://localhost:8080/) (user: dev, pass: dev) * [phpMyAdmin](http://localhost:8080/) (user: dev, pass: dev)
5. Stop :
```sh
docker-compose stop
docker-compose kill
docker-compose rm -f
```
## Using Makefile
When developing, you can use the Makefile for doing the following operations :
### Makefile
| 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 |
| mysql-dump | Create backup of whole database |
| mysql-restore | Restore backup from whole databas |
| test | Test application |
## Directory tree ## Directory tree
```sh ```sh
.
├── Makefile
├── README.md ├── README.md
├── bin ├── bin
   └── linux └── linux
   └── clean.sh └── clean.sh
├── data
│ └── db
│ └── mysql
├── docker-compose.yml ├── docker-compose.yml
├── etc ├── etc
   ├── nginx ├── nginx
   │   └── default.conf └── default.conf
  ── php ── php
   └── php.ini └── php.ini
│ └── ssl
└── web └── web
├── app ├── app
   ├── composer.json.dist ├── composer.json
   ├── phpunit.xml.dist ├── composer.json.dist
   ├── src ├── phpunit.xml.dist
   │   └── Foo.php ├── src
   └── test │ └── Foo.php
   ── FooTest.php ── test
   ── bootstrap.php ── FooTest.php
│ └── bootstrap.php
└── public └── public
└── index.php └── index.php
``` ```
@@ -81,37 +113,31 @@ Docker running Nginx, PHP-FPM, MySQL and PHPMyAdmin.
## Updating composer ## Updating composer
```sh ```sh
$ docker run --rm -v $(pwd)/web/app:/app -v ~/.ssh:/root/.ssh composer/composer update docker run --rm -v $(PWD)/web/app:/app composer/composer update
``` ```
## MySQL Container shell access ## MySQL Container shell access
```sh ```sh
$ docker exec -it mysql bash docker exec -it mysql bash
``` ```
and and
```sh ```sh
$ mysql -uroot -proot mysql -uroot -proot
``` ```
## Creating database dumps ## Creating database dumps
```sh ```sh
$ docker exec mysql sh -c 'exec mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' > /some/path/on/your/host/all-databases.sql 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 or
```sh ```sh
$ docker exec mysql sh -c 'exec mysqldump dbname -uroot -p"$MYSQL_ROOT_PASSWORD"' > /some/path/on/your/host/dbname.sql 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"
```
### Example
```sh
$ docker exec mysql sh -c 'exec mysqldump test -uroot -p"$MYSQL_ROOT_PASSWORD"' > $(pwd)/data/db/dumps/test.sql
``` ```
## Generating SSL certificates ## Generating SSL certificates
@@ -119,12 +145,12 @@ $ docker exec mysql sh -c 'exec mysqldump test -uroot -p"$MYSQL_ROOT_PASSWORD"'
1. Generate certificates 1. Generate certificates
```sh ```sh
$ docker run --rm -v $(pwd)/etc/ssl:/certificates -e "SERVER=localhost" jacoelho/generate-certificate docker run --rm -v $(PWD)/etc/ssl:/certificates -e "SERVER=localhost" jacoelho/generate-certificate
``` ```
2. Configure Nginx 2. Configure Nginx
Edit nginx file **etc/nginx/default.conf** and uncomment the server section. Edit nginx file **etc/nginx/default.conf** and uncomment the server section :
```nginx ```nginx
# server { # server {
@@ -135,11 +161,11 @@ $ docker exec mysql sh -c 'exec mysqldump test -uroot -p"$MYSQL_ROOT_PASSWORD"'
## Generating API Documentation ## Generating API Documentation
```sh ```sh
./web/app/vendor/apigen/apigen/bin/apigen generate -s web/app/src -d web/app/doc docker exec -i $(docker-compose ps -q php) php ./app/vendor/apigen/apigen/bin/apigen generate -s app/src -d app/doc
``` ```
## Cleaning project ## Cleaning project
```sh ```sh
$ ./bin/linux/clean.sh $(pwd) ./bin/linux/clean.sh $(pwd)
``` ```

View File

@@ -16,8 +16,9 @@ rm -Rf $DATA_PATH/db/mysql/*
rm -Rf $DATA_PATH/dumps/* rm -Rf $DATA_PATH/dumps/*
rm -Rf $APP_PATH/vendor rm -Rf $APP_PATH/vendor
rm -Rf $APP_PATH/composer.lock rm -Rf $APP_PATH/composer.lock
rm -Rf $APP_PATH/doc
rm -Rf $ETC_PATH/ssl/*
# remove exited containers # remove exited containers
docker rm $(docker ps -a -f status=exited -q) docker rm $(docker ps -a -f status=exited -q)
docker volume rm $(docker volume ls -qf dangling=true) docker volume rm $(docker volume ls -qf dangling=true)

View File

@@ -9,7 +9,7 @@ services:
volumes: volumes:
- "./etc/nginx/default.conf:/etc/nginx/conf.d/default.conf" - "./etc/nginx/default.conf:/etc/nginx/conf.d/default.conf"
- "./etc/ssl:/etc/ssl" - "./etc/ssl:/etc/ssl"
- "./web:/web" - "./web:/var/www/html"
depends_on: depends_on:
- php - php
- mysqldb - mysqldb

View File

@@ -8,7 +8,7 @@ server {
index index.php index.html; index index.php index.html;
error_log /var/log/nginx/error.log; error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log; access_log /var/log/nginx/access.log;
root /web/public; root /var/www/html/public;
location ~ \.php$ { location ~ \.php$ {
try_files $uri =404; try_files $uri =404;