Docker compose nginx php fpm mysql

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Docker running Nginx, PHP-FPM, MySQL & PHPMyAdmin

nanoninja/docker-nginx-php-mysql

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

- Update PHPUnit, PHPCode_sniffer - Remove apigen

Git stats

Files

Failed to load latest commit information.

README.md

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

  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 use Makefile for doing recurrent operations.
  7. Use Docker Commands When running, you can use docker commands for doing recurrent operations.

To run the docker commands without using sudo you must add the docker group to your-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 if docker-compose is already installed by entering the following command :

Check Docker Compose compatibility :

The following is optional but makes life more enjoyable :

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

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

This project use the following ports :

Server Port
MySQL 8989
PHPMyAdmin 8080
Nginx 8000
Nginx SSL 3000

To install Git, download it and install following the instructions :

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

Go to the project directory :

. ├── 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.

    Generate SSL certificates

source .env && docker run --rm -v $(pwd)/etc/ssl:/certificates -e "SERVER=$NGINX_HOST" jacoelho/generate-certificate
# server # server_name $; # # listen 443 ssl; # fastcgi_param HTTPS on; # . # >

If you use another IDE than PHPStorm or Netbeans, go to the remote debugging section of Xdebug documentation.

For a better integration of Docker to PHPStorm, use the documentation.

    Get your own local IP address :

xdebug.remote_host=192.168.0.1 # your IP
cp web/app/composer.json.dist web/app/composer.json
docker-compose logs -f # Follow log output

When developing, you can use Makefile for doing the following operations :

Name Description
apidoc Generate documentation of API
clean Clean directories for reset
code-sniff Check the API with PHP Code Sniffer ( PSR2 )
composer-up Update PHP dependencies with composer
docker-start Create and start containers
docker-stop Stop and clear all services
gen-certs Generate SSL certificates for nginx
logs Follow log output
mysql-dump Create backup of all databases
mysql-restore Restore backup of all databases
phpmd Analyse the API with PHP Mess Detector
test Test application with phpunit

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-compose exec -T php ./app/vendor/bin/phpunit --colors=always --configuration ./app

Fixing standard code with PSR2

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

Checking the standard code with PSR2

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

Analyzing source code with PHP Mess Detector

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

Checking installed PHP extensions

docker-compose exec php php -m
docker exec -it mysql bash
mysql -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD"

Creating a backup of all databases

source .env && docker exec $(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 && docker exec -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 && docker exec $(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 && docker exec -i $(docker-compose ps -q mysqldb) mysql -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD"  "data/db/dumps/YOUR_DB_NAME_dump.sql"
 try < $dsn = 'mysql:host=mysql;dbname=test;charset=utf8;port=3306'; $pdo = new PDO($dsn, 'dev', 'dev'); > catch (PDOException $e) < echo $e->getMessage(); > ?>

Any thought, feedback or (hopefully not!)

About

Docker running Nginx, PHP-FPM, MySQL & PHPMyAdmin

Источник

Читайте также:  Incorrect Concept of Onclick Event
Оцените статью