commit 671766bdf372423347ab3305f3561defb5bdab78 Author: Vincent Letourneau Date: Sun Jan 15 15:48:31 2017 +0100 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..5bfcb5d --- /dev/null +++ b/README.md @@ -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 + +``` + +## 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) +``` diff --git a/bin/linux/clean.sh b/bin/linux/clean.sh new file mode 100755 index 0000000..90200df --- /dev/null +++ b/bin/linux/clean.sh @@ -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) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..89f78e0 --- /dev/null +++ b/docker-compose.yml @@ -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 diff --git a/etc/nginx/default.conf b/etc/nginx/default.conf new file mode 100644 index 0000000..743956d --- /dev/null +++ b/etc/nginx/default.conf @@ -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; +# } +# } diff --git a/etc/php/php.ini b/etc/php/php.ini new file mode 100644 index 0000000..5f2abf5 --- /dev/null +++ b/etc/php/php.ini @@ -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 diff --git a/web/app/composer.json b/web/app/composer.json new file mode 100644 index 0000000..770ec0f --- /dev/null +++ b/web/app/composer.json @@ -0,0 +1,8 @@ +{ + "require": {}, + "autoload": { + "psr-4": { + "App\\": ["src/", "tests/"] + } + } +} diff --git a/web/public/index.php b/web/public/index.php new file mode 100644 index 0000000..92adc28 --- /dev/null +++ b/web/public/index.php @@ -0,0 +1,10 @@ + + + + + Docker Nginx PHP MySQL + + +

Docker Nginx PHP MySQL

+ +