Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Docker running Nginx, PHP-FPM, MySQL & PHPMyAdmin

NotificationsYou must be signed in to change notification settings

nanoninja/docker-nginx-php-mysql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Overview

  1. Install prerequisites

    Before installing project make sure the following prerequisites have been met.

  2. Clone the project

    We’ll download the code from its repository on GitHub.

  3. Configure Nginx With SSL Certificates [Optional]

    We'll generate and configure SSL certificate for nginx before running server.

  4. Configure Xdebug [Optional]

    We'll configure Xdebug for IDE (PHPStorm or Netbeans).

  5. Run the application

    By this point we’ll have all the project pieces in place.

  6. Use Makefile [Optional]

    When developing, you can useMakefile for doing recurrent operations.

  7. Use Docker Commands

    When running, you can use docker commands for doing recurrent operations.


Install prerequisites

To run the docker commands without usingsudo you must add thedocker group toyour-user:

sudo usermod -aG docker your-user

For now, this project has been mainly created for Unix(Linux/MacOS). Perhaps it could work on Windows.

All requisites should be available for your distribution. The most important are :

Check ifdocker-compose is already installed by entering the following command :

which docker-compose

Check Docker Compose compatibility :

The following is optional but makes life more enjoyable :

which make

On Ubuntu and Debian these are available in the meta-package build-essential. On other distributions, you may need to install the GNU C++ compiler separately.

sudo apt install build-essential

Images to use

You should be careful when installing third party web servers such as MySQL or Nginx.

This project use the following ports :

ServerPort
MySQL8989
PHPMyAdmin8080
Nginx8000
Nginx SSL3000

Clone the project

To installGit, download it and install following the instructions :

git clone https://github.com/nanoninja/docker-nginx-php-mysql.git

Go to the project directory :

cd docker-nginx-php-mysql

Project tree

.├── Makefile├── README.md├── data│   └── db│       ├── dumps│       └── mysql├── doc├── docker-compose.yml├── etc│   ├── nginx│   │   ├── default.conf│   │   └── default.template.conf│   ├── php│   │   └── php.ini│   └── ssl└── web    ├── app    │   ├── composer.json.dist    │   ├── phpunit.xml.dist    │   ├── src    │   │   └── Foo.php    │   └──test    │       ├── FooTest.php    │       └── bootstrap.php    └── public        └── index.php

Configure Nginx With SSL Certificates

You can change the host name by editing the.env file.

If you modify the host name, do not forget to add it to the/etc/hosts file.

  1. Generate SSL certificates

    source .env&& docker run --rm -v$(pwd)/etc/ssl:/certificates -e"SERVER=$NGINX_HOST" jacoelho/generate-certificate
  2. Configure Nginx

    Do not modify theetc/nginx/default.conf file, it is overwritten byetc/nginx/default.template.conf

    Edit nginx fileetc/nginx/default.template.conf and uncomment the SSL server section :

    # server {#     server_name ${NGINX_HOST};##     listen 443 ssl;#     fastcgi_param HTTPS on;#     ...# }

Configure Xdebug

If you use another IDE thanPHPStorm orNetbeans, go to theremote debugging section of Xdebug documentation.

For a better integration of Docker to PHPStorm, use thedocumentation.

  1. Get your own local IP address :

    sudo ifconfig
  2. Edit php fileetc/php/php.ini and comment or uncomment the configuration as needed.

  3. Set theremote_host parameter with your IP :

    xdebug.remote_host=192.168.0.1# your IP

Run the application

  1. Copying the composer configuration file :

    cp web/app/composer.json.dist web/app/composer.json
  2. Start the application :

    docker-compose up -d

    Please wait this might take a several minutes...

    docker-compose logs -f# Follow log output
  3. Open your favorite browser :

  4. Stop and clear services

    docker-compose down -v

Use Makefile

When developing, you can useMakefile for doing the following operations :

NameDescription
apidocGenerate documentation of API
cleanClean directories for reset
code-sniffCheck the API with PHP Code Sniffer (PSR2)
composer-upUpdate PHP dependencies with composer
docker-startCreate and start containers
docker-stopStop and clear all services
gen-certsGenerate SSL certificates fornginx
logsFollow log output
mysql-dumpCreate backup of all databases
mysql-restoreRestore backup of all databases
phpmdAnalyse the API with PHP Mess Detector
testTest application with phpunit

Examples

Start the application :

make docker-start

Show help :

makehelp

Use Docker commands

Installing package with composer

docker run --rm -v$(pwd)/web/app:/app composer require symfony/yaml

Updating PHP dependencies with composer

docker run --rm -v$(pwd)/web/app:/app composer update

Generating PHP API documentation

docker run --rm -v$(pwd):/data phpdoc/phpdoc -i=vendor/ -d /data/web/app/src -t /data/web/app/doc

Testing PHP application with PHPUnit

docker-composeexec -T php ./app/vendor/bin/phpunit --colors=always --configuration ./app

Fixing standard code withPSR2

docker-composeexec -T php ./app/vendor/bin/phpcbf -v --standard=PSR2 ./app/src

Checking the standard code withPSR2

docker-composeexec -T php ./app/vendor/bin/phpcs -v --standard=PSR2 ./app/src

Analyzing source code withPHP Mess Detector

docker-composeexec -T php ./app/vendor/bin/phpmd ./app/src text cleancode,codesize,controversial,design,naming,unusedcode

Checking installed PHP extensions

docker-composeexec php php -m

Handling database

MySQL shell access

dockerexec -it mysql bash

and

mysql -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD"

Creating a backup of all databases

mkdir -p data/db/dumps
source .env&& dockerexec$(docker-compose ps -q mysqldb) mysqldump --all-databases -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD">"data/db/dumps/db.sql"

Restoring a backup of all databases

source .env&& dockerexec -i$(docker-compose ps -q mysqldb) mysql -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD"<"data/db/dumps/db.sql"

Creating a backup of single database

Notice: Replace "YOUR_DB_NAME" by your custom name.

source .env&& dockerexec$(docker-compose ps -q mysqldb) mysqldump -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" --databases YOUR_DB_NAME>"data/db/dumps/YOUR_DB_NAME_dump.sql"

Restoring a backup of single database

source .env&& dockerexec -i$(docker-compose ps -q mysqldb) mysql -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD"<"data/db/dumps/YOUR_DB_NAME_dump.sql"

Connecting MySQL fromPDO

<?phptry {$dsn ='mysql:host=mysql;dbname=test;charset=utf8;port=3306';$pdo =newPDO($dsn,'dev','dev');    }catch (PDOException$e) {echo$e->getMessage();    }?>

Help us

Any thought, feedback or (hopefully not!)


[8]ページ先頭

©2009-2025 Movatter.jp