Files
Open-RSC-Docker-Home/README.md
Vincent Letourneau 12cf097153 Update README
2017-07-27 19:08:58 +02:00

4.0 KiB

Nginx PHP MySQL

Docker running Nginx, PHP-FPM, Composer, MySQL and PHPMyAdmin.

Images to use

Start using it

  1. Download it :

    git clone https://github.com/nanoninja/docker-nginx-php-mysql.git
    
    cd docker-nginx-php-mysql
    
  2. Copying the composer configuration file :

    cp web/app/composer.json.dist web/app/composer.json
    
  3. Start :

    docker-compose up -d
    

    Please wait this might take a several minutes...

  4. Open your favorite browser :

  5. 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

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

  1. Generate certificates

    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 :

    # 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)