first commit
This commit is contained in:
132
README.md
Normal file
132
README.md
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
# Nginx PHP MySQL
|
||||||
|
|
||||||
|
Docker running Nginx, PHP-FPM, MySQL and PHPMyAdmin.
|
||||||
|
|
||||||
|
**THIS ENVIRONMENT SHOULD ONLY BE USED FOR DEVELOPMENT!**
|
||||||
|
|
||||||
|
**DO NOT USE IT IN PRODUCTION!**
|
||||||
|
|
||||||
|
## Images to use
|
||||||
|
|
||||||
|
* [Nginx](https://hub.docker.com/_/nginx/) (181.85 MB)
|
||||||
|
* [MySQL](https://hub.docker.com/_/mysql/) (400.2 MB)
|
||||||
|
* [PHP-FPM](https://hub.docker.com/r/nanoninja/php-fpm/) (635.9 MB)
|
||||||
|
* [Composer](https://hub.docker.com/r/composer/composer/) (635.7 MB)
|
||||||
|
* [PHPMyAdmin](https://hub.docker.com/r/phpmyadmin/phpmyadmin/) (102.2 MB)
|
||||||
|
* [generate-certificate](https://hub.docker.com/r/jacoelho/generate-certificate/) (9.07 MB)
|
||||||
|
|
||||||
|
## Start using it
|
||||||
|
|
||||||
|
1. Download it :
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git clone https://github.com/nanoninja/docker-nginx-php-mysql.git
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Run :
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Open your favorite browser :
|
||||||
|
|
||||||
|
* http://localhost:8000
|
||||||
|
* https://localhost:3000 (not configured by default)
|
||||||
|
* http://localhost:8080/ (phpmyadmin)
|
||||||
|
|
||||||
|
## Directory tree
|
||||||
|
|
||||||
|
```sh
|
||||||
|
.
|
||||||
|
├── bin
|
||||||
|
│ └── linux
|
||||||
|
│ └── clean.sh
|
||||||
|
├── data
|
||||||
|
│ └── db
|
||||||
|
│ ├── dumps
|
||||||
|
│ └── mysql
|
||||||
|
├── docker-compose.yml
|
||||||
|
├── etc
|
||||||
|
│ ├── nginx
|
||||||
|
│ │ └── default.conf
|
||||||
|
│ ├── php
|
||||||
|
│ │ └── php.ini
|
||||||
|
│ └── ssl
|
||||||
|
└── web
|
||||||
|
├── app
|
||||||
|
│ ├── composer.json
|
||||||
|
│ ├── src
|
||||||
|
│ └── tests
|
||||||
|
└── public
|
||||||
|
└── index.php
|
||||||
|
```
|
||||||
|
|
||||||
|
## Connecting from PDO
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
$dsn = 'mysql:host=mysql;dbname=test;charset=utf8;port=3306';
|
||||||
|
$pdo = new PDO($dsn, 'root', 'root');
|
||||||
|
?>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Updating composer
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker run --rm -v $(pwd)/web/app:/app -v ~/.ssh:/root/.ssh composer/composer update
|
||||||
|
```
|
||||||
|
|
||||||
|
## MySQL Container shell access
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker exec -it mysql bash
|
||||||
|
```
|
||||||
|
|
||||||
|
and
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ mysql -uroot -proot
|
||||||
|
```
|
||||||
|
|
||||||
|
## Creating database dumps
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker exec mysql sh -c 'exec mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' > /some/path/on/your/host/all-databases.sql
|
||||||
|
```
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker exec mysql sh -c 'exec mysqldump dbname -uroot -p"$MYSQL_ROOT_PASSWORD"' > /some/path/on/your/host/dbname.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
|
||||||
|
|
||||||
|
1. Generate certificates
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker run --rm -v $(pwd)/etc/ssl:/certificates -e "SERVER=localhost" jacoelho/generate-certificate
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Configure Nginx
|
||||||
|
|
||||||
|
Edit nginx file **etc/nginx/default.conf** and uncomment the server section.
|
||||||
|
|
||||||
|
```nginx
|
||||||
|
server {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Cleaning project
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./bin/linux/clean.sh $(pwd)
|
||||||
|
```
|
||||||
20
bin/linux/clean.sh
Executable file
20
bin/linux/clean.sh
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
ROOT_PATH=$1
|
||||||
|
|
||||||
|
if [[ ! -d "$ROOT_PATH" && ! -L "$ROOT_PATH" ]]; then
|
||||||
|
echo "No such file or directory"
|
||||||
|
fi
|
||||||
|
|
||||||
|
WEB_PATH=$ROOT_PATH/web
|
||||||
|
DATA_PATH=$ROOT_PATH/data
|
||||||
|
ETC_PATH=$ROOT_PATH/etc
|
||||||
|
APP_PATH=$WEB_PATH/app
|
||||||
|
|
||||||
|
rm -Rf $DATA_PATH/db/mysql/*
|
||||||
|
rm -Rf $DATA_PATH/dumps/*
|
||||||
|
rm -Rf $APP_PATH/vendor
|
||||||
|
rm -Rf $APP_PATH/composer.lock
|
||||||
|
|
||||||
|
docker rm -f $(docker ps -aq)
|
||||||
|
docker volume rm $(docker volume ls -qf dangling=true)
|
||||||
50
docker-compose.yml
Normal file
50
docker-compose.yml
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
version: '2'
|
||||||
|
services:
|
||||||
|
web:
|
||||||
|
image: nginx:latest
|
||||||
|
ports:
|
||||||
|
- "8000:80"
|
||||||
|
- "3000:443"
|
||||||
|
restart: always
|
||||||
|
volumes:
|
||||||
|
- "./etc/nginx/default.conf:/etc/nginx/conf.d/default.conf"
|
||||||
|
- "./etc/ssl:/etc/ssl"
|
||||||
|
- "./web:/web"
|
||||||
|
depends_on:
|
||||||
|
- "php"
|
||||||
|
- "mysqldb"
|
||||||
|
php:
|
||||||
|
image: nanoninja/php-fpm
|
||||||
|
restart: always
|
||||||
|
volumes:
|
||||||
|
- "./etc/php/php.ini:/usr/local/etc/php/conf.d/php.ini"
|
||||||
|
- ./web:/web
|
||||||
|
composer:
|
||||||
|
image: composer/composer
|
||||||
|
volumes:
|
||||||
|
- ./web/app:/app
|
||||||
|
command: install
|
||||||
|
myadmin:
|
||||||
|
image: phpmyadmin/phpmyadmin
|
||||||
|
container_name: phpmyadmin
|
||||||
|
ports:
|
||||||
|
- "8080:80"
|
||||||
|
environment:
|
||||||
|
- PMA_ARBITRARY=1
|
||||||
|
- PMA_HOST=mysql
|
||||||
|
restart: always
|
||||||
|
depends_on:
|
||||||
|
- "mysqldb"
|
||||||
|
mysqldb:
|
||||||
|
image: mysql
|
||||||
|
container_name: mysql
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
- MYSQL_DATABASE=test
|
||||||
|
- MYSQL_ROOT_PASSWORD=root
|
||||||
|
- MYSQL_USER=student
|
||||||
|
- MYSQL_PASSWORD=0000
|
||||||
|
ports:
|
||||||
|
- 3306:3306
|
||||||
|
volumes:
|
||||||
|
- ./data/db/mysql:/var/lib/mysql
|
||||||
48
etc/nginx/default.conf
Normal file
48
etc/nginx/default.conf
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
# Nginx configuration
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 80 default_server;
|
||||||
|
listen [::]:80 default_server;
|
||||||
|
server_name localhost;
|
||||||
|
|
||||||
|
index index.php index.html;
|
||||||
|
error_log /var/log/nginx/error.log;
|
||||||
|
access_log /var/log/nginx/access.log;
|
||||||
|
root /web/public;
|
||||||
|
|
||||||
|
location ~ \.php$ {
|
||||||
|
try_files $uri =404;
|
||||||
|
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||||
|
fastcgi_pass php:9000;
|
||||||
|
fastcgi_index index.php;
|
||||||
|
include fastcgi_params;
|
||||||
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||||
|
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# server {
|
||||||
|
# server_name localhost;
|
||||||
|
#
|
||||||
|
# listen 443 ssl;
|
||||||
|
# fastcgi_param HTTPS on;
|
||||||
|
#
|
||||||
|
# ssl_certificate /etc/ssl/server.pem;
|
||||||
|
# ssl_certificate_key /etc/ssl/server.key;
|
||||||
|
# ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
|
||||||
|
#
|
||||||
|
# index index.php index.html;
|
||||||
|
# error_log /var/log/nginx/error.log;
|
||||||
|
# access_log /var/log/nginx/access.log;
|
||||||
|
# root /web/public;
|
||||||
|
#
|
||||||
|
# location ~ \.php$ {
|
||||||
|
# try_files $uri =404;
|
||||||
|
# fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||||
|
# fastcgi_pass php:9000;
|
||||||
|
# fastcgi_index index.php;
|
||||||
|
# include fastcgi_params;
|
||||||
|
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||||
|
# fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||||
|
# }
|
||||||
|
# }
|
||||||
6
etc/php/php.ini
Normal file
6
etc/php/php.ini
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[xdebug]
|
||||||
|
xdebug.remote_enable=1
|
||||||
|
xdebug.idekey=PHPSTORM
|
||||||
|
xdebug.profiler_enable=0
|
||||||
|
xdebug.max_nesting_level=700
|
||||||
|
xdebug.remote_host=localhost
|
||||||
8
web/app/composer.json
Normal file
8
web/app/composer.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"require": {},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"App\\": ["src/", "tests/"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
10
web/public/index.php
Normal file
10
web/public/index.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Docker Nginx PHP MySQL</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Docker Nginx PHP MySQL</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user