Skip to content

Commit e80b05d

Browse files
committed
Adapt Nginx configuration with PHP volume
1 parent b7683f7 commit e80b05d

File tree

4 files changed

+69
-42
lines changed

4 files changed

+69
-42
lines changed

README.md

+65-39
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
# Nginx PHP MySQL
22

3-
Docker running Nginx, PHP-FPM, MySQL and PHPMyAdmin.
4-
5-
**THIS ENVIRONMENT SHOULD ONLY BE USED FOR DEVELOPMENT!**
6-
7-
**DO NOT USE IT IN PRODUCTION!**
3+
Docker running Nginx, PHP-FPM, Composer, MySQL and PHPMyAdmin.
84

95
## Images to use
106

@@ -20,51 +16,87 @@ Docker running Nginx, PHP-FPM, MySQL and PHPMyAdmin.
2016
1. Download it :
2117

2218
```sh
23-
$ git clone https://github.com/nanoninja/docker-nginx-php-mysql.git
24-
$ cd docker-nginx-php-mysql
19+
git clone https://github.com/nanoninja/docker-nginx-php-mysql.git
20+
21+
cd docker-nginx-php-mysql
2522
```
2623

2724
2. Copying the composer configuration file :
2825

2926
```sh
30-
# Convenient to avoid overwriting the configuration with Git.
31-
$ cp web/app/composer.json.dist web/app/composer.json
27+
cp web/app/composer.json.dist web/app/composer.json
3228
```
3329

34-
3. Run :
30+
3. Start :
3531

3632
```sh
37-
$ docker-compose up -d
33+
docker-compose up -d
3834
```
3935

36+
**Please wait this might take a several minutes...**
37+
4038
4. Open your favorite browser :
4139

4240
* [http://localhost:8000](http://localhost:8000/)
4341
* [https://localhost:3000](https://localhost:3000/) ([HTTPS](https://github.com/nanoninja/docker-nginx-php-mysql#generating-ssl-certificates) not configured by default)
4442
* [phpMyAdmin](http://localhost:8080/) (user: dev, pass: dev)
4543

44+
5. Stop :
45+
46+
```sh
47+
docker-compose stop
48+
docker-compose kill
49+
docker-compose rm -f
50+
```
51+
52+
## Using Makefile
53+
54+
When developing, you can use the Makefile for doing the following operations :
55+
56+
### Makefile
57+
58+
| Name | Description |
59+
|---------------|-----------------------------------|
60+
| apidoc | Generate documentation of API |
61+
| clean | Clean directories for reset |
62+
| composer-up | Update php composer |
63+
| docker-start | Create and start containers |
64+
| docker-stop | Stop all services |
65+
| docker-sweep | Sweep old containers and volumes |
66+
| gen-certs | Generate SSL certificates |
67+
| mysql-dump | Create backup of whole database |
68+
| mysql-restore | Restore backup from whole databas |
69+
| test | Test application |
70+
4671
## Directory tree
4772

4873
```sh
74+
.
75+
├── Makefile
4976
├── README.md
5077
├── bin
51-
│   └── linux
52-
│   └── clean.sh
78+
│ └── linux
79+
│ └── clean.sh
80+
├── data
81+
│ └── db
82+
│ └── mysql
5383
├── docker-compose.yml
5484
├── etc
55-
│   ├── nginx
56-
│   │   └── default.conf
57-
│   └── php
58-
│   └── php.ini
85+
│ ├── nginx
86+
│ │ └── default.conf
87+
│ ├── php
88+
│ │ └── php.ini
89+
│ └── ssl
5990
└── web
6091
├── app
61-
│   ├── composer.json.dist
62-
│   ├── phpunit.xml.dist
63-
│   ├── src
64-
│   │   └── Foo.php
65-
│   └── test
66-
│   ├── FooTest.php
67-
│   └── bootstrap.php
92+
│ ├── composer.json
93+
│ ├── composer.json.dist
94+
│ ├── phpunit.xml.dist
95+
│ ├── src
96+
│ │ └── Foo.php
97+
│ └── test
98+
│ ├── FooTest.php
99+
│ └── bootstrap.php
68100
└── public
69101
└── index.php
70102
```
@@ -81,50 +113,44 @@ Docker running Nginx, PHP-FPM, MySQL and PHPMyAdmin.
81113
## Updating composer
82114

83115
```sh
84-
$ docker run --rm -v $(pwd)/web/app:/app -v ~/.ssh:/root/.ssh composer/composer update
116+
docker run --rm -v $(PWD)/web/app:/app composer/composer update
85117
```
86118

87119
## MySQL Container shell access
88120

89121
```sh
90-
$ docker exec -it mysql bash
122+
docker exec -it mysql bash
91123
```
92124

93125
and
94126

95127
```sh
96-
$ mysql -uroot -proot
128+
mysql -uroot -proot
97129
```
98130

99131
## Creating database dumps
100132

101133
```sh
102-
$ docker exec mysql sh -c 'exec mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' > /some/path/on/your/host/all-databases.sql
134+
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"
103135
```
104136

105137
or
106138

107139
```sh
108-
$ docker exec mysql sh -c 'exec mysqldump dbname -uroot -p"$MYSQL_ROOT_PASSWORD"' > /some/path/on/your/host/dbname.sql
109-
```
110-
111-
### Example
112-
113-
```sh
114-
$ docker exec mysql sh -c 'exec mysqldump test -uroot -p"$MYSQL_ROOT_PASSWORD"' > $(pwd)/data/db/dumps/test.sql
140+
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"
115141
```
116142

117143
## Generating SSL certificates
118144

119145
1. Generate certificates
120146

121147
```sh
122-
$ docker run --rm -v $(pwd)/etc/ssl:/certificates -e "SERVER=localhost" jacoelho/generate-certificate
148+
docker run --rm -v $(PWD)/etc/ssl:/certificates -e "SERVER=localhost" jacoelho/generate-certificate
123149
```
124150

125151
2. Configure Nginx
126152

127-
Edit nginx file **etc/nginx/default.conf** and uncomment the server section.
153+
Edit nginx file **etc/nginx/default.conf** and uncomment the server section :
128154

129155
```nginx
130156
# server {
@@ -135,11 +161,11 @@ $ docker exec mysql sh -c 'exec mysqldump test -uroot -p"$MYSQL_ROOT_PASSWORD"'
135161
## Generating API Documentation
136162

137163
```sh
138-
./web/app/vendor/apigen/apigen/bin/apigen generate -s web/app/src -d web/app/doc
164+
docker exec -i $(docker-compose ps -q php) php ./app/vendor/apigen/apigen/bin/apigen generate -s app/src -d app/doc
139165
```
140166

141167
## Cleaning project
142168

143169
```sh
144-
$ ./bin/linux/clean.sh $(pwd)
170+
./bin/linux/clean.sh $(pwd)
145171
```

bin/linux/clean.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ rm -Rf $DATA_PATH/db/mysql/*
1616
rm -Rf $DATA_PATH/dumps/*
1717
rm -Rf $APP_PATH/vendor
1818
rm -Rf $APP_PATH/composer.lock
19+
rm -Rf $APP_PATH/doc
20+
rm -Rf $ETC_PATH/ssl/*
1921

2022
# remove exited containers
2123
docker rm $(docker ps -a -f status=exited -q)
22-
2324
docker volume rm $(docker volume ls -qf dangling=true)

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
volumes:
1010
- "./etc/nginx/default.conf:/etc/nginx/conf.d/default.conf"
1111
- "./etc/ssl:/etc/ssl"
12-
- "./web:/web"
12+
- "./web:/var/www/html"
1313
depends_on:
1414
- php
1515
- mysqldb

etc/nginx/default.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ server {
88
index index.php index.html;
99
error_log /var/log/nginx/error.log;
1010
access_log /var/log/nginx/access.log;
11-
root /web/public;
11+
root /var/www/html/public;
1212

1313
location ~ \.php$ {
1414
try_files $uri =404;

0 commit comments

Comments
 (0)