{"id":13483890,"url":"https://github.com/nanoninja/docker-nginx-php-mysql","last_synced_at":"2025-10-25T10:03:53.779Z","repository":{"id":40477215,"uuid":"79038782","full_name":"nanoninja/docker-nginx-php-mysql","owner":"nanoninja","description":"Docker running Nginx, PHP-FPM, MySQL \u0026 PHPMyAdmin","archived":false,"fork":false,"pushed_at":"2025-03-25T08:50:48.000Z","size":4314,"stargazers_count":1769,"open_issues_count":33,"forks_count":865,"subscribers_count":72,"default_branch":"master","last_synced_at":"2025-04-14T19:53:59.453Z","etag":null,"topics":["composer","docker","docker-compose","lemp","mysql","nginx","php-fpm","phpmyadmin"],"latest_commit_sha":null,"homepage":"","language":"Makefile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nanoninja.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-15T14:48:10.000Z","updated_at":"2025-04-05T14:35:36.000Z","dependencies_parsed_at":"2025-03-31T15:10:43.857Z","dependency_job_id":"87a1e41b-d362-4029-8cad-c0262d153efd","html_url":"https://github.com/nanoninja/docker-nginx-php-mysql","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoninja%2Fdocker-nginx-php-mysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoninja%2Fdocker-nginx-php-mysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoninja%2Fdocker-nginx-php-mysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoninja%2Fdocker-nginx-php-mysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nanoninja","download_url":"https://codeload.github.com/nanoninja/docker-nginx-php-mysql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254080769,"owners_count":22011495,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["composer","docker","docker-compose","lemp","mysql","nginx","php-fpm","phpmyadmin"],"created_at":"2024-07-31T17:01:16.511Z","updated_at":"2025-10-25T10:03:48.729Z","avatar_url":"https://github.com/nanoninja.png","language":"Makefile","funding_links":[],"categories":["Makefile","nginx"],"sub_categories":[],"readme":"# Nginx PHP MySQL [![Build Status](https://travis-ci.org/nanoninja/docker-nginx-php-mysql.svg?branch=master)](https://travis-ci.org/nanoninja/docker-nginx-php-mysql) [![GitHub version](https://badge.fury.io/gh/nanoninja%2Fdocker-nginx-php-mysql.svg)](https://badge.fury.io/gh/nanoninja%2Fdocker-nginx-php-mysql)\n\nDocker running Nginx, PHP-FPM, Composer, MySQL and PHPMyAdmin.\n\n## Overview\n\n1. [Install prerequisites](#install-prerequisites)\n\n    Before installing project make sure the following prerequisites have been met.\n\n2. [Clone the project](#clone-the-project)\n\n    We’ll download the code from its repository on GitHub.\n\n3. [Configure Nginx With SSL Certificates](#configure-nginx-with-ssl-certificates) [`Optional`]\n\n    We'll generate and configure SSL certificate for nginx before running server.\n\n4. [Configure Xdebug](#configure-xdebug) [`Optional`]\n\n    We'll configure Xdebug for IDE (PHPStorm or Netbeans).\n\n5. [Run the application](#run-the-application)\n\n    By this point we’ll have all the project pieces in place.\n\n6. [Use Makefile](#use-makefile) [`Optional`]\n\n    When developing, you can use `Makefile` for doing recurrent operations.\n\n7. [Use Docker Commands](#use-docker-commands)\n\n    When running, you can use docker commands for doing recurrent operations.\n\n___\n\n## Install prerequisites\n\nTo run the docker commands without using **sudo** you must add the **docker** group to **your-user**:\n\n```\nsudo usermod -aG docker your-user\n```\n\nFor now, this project has been mainly created for Unix `(Linux/MacOS)`. Perhaps it could work on Windows.\n\nAll requisites should be available for your distribution. The most important are :\n\n* [Git](https://git-scm.com/downloads)\n* [Docker](https://docs.docker.com/engine/installation/)\n* [Docker Compose](https://docs.docker.com/compose/install/)\n\nCheck if `docker-compose` is already installed by entering the following command : \n\n```sh\nwhich docker-compose\n```\n\nCheck Docker Compose compatibility :\n\n* [Compose file version 3 reference](https://docs.docker.com/compose/compose-file/)\n\nThe following is optional but makes life more enjoyable :\n\n```sh\nwhich make\n```\n\nOn 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.\n\n```sh\nsudo apt install build-essential\n```\n\n### Images to use\n\n* [Nginx](https://hub.docker.com/_/nginx/)\n* [MySQL](https://hub.docker.com/_/mysql/)\n* [PHP-FPM](https://hub.docker.com/r/nanoninja/php-fpm/)\n* [Composer](https://hub.docker.com/_/composer/)\n* [PHPMyAdmin](https://hub.docker.com/r/phpmyadmin/phpmyadmin/)\n* [Generate Certificate](https://hub.docker.com/r/jacoelho/generate-certificate/)\n\nYou should be careful when installing third party web servers such as MySQL or Nginx.\n\nThis project use the following ports :\n\n| Server     | Port |\n|------------|------|\n| MySQL      | 8989 |\n| PHPMyAdmin | 8080 |\n| Nginx      | 8000 |\n| Nginx SSL  | 3000 |\n\n___\n\n## Clone the project\n\nTo install [Git](http://git-scm.com/book/en/v2/Getting-Started-Installing-Git), download it and install following the instructions :\n\n```sh\ngit clone https://github.com/nanoninja/docker-nginx-php-mysql.git\n```\n\nGo to the project directory :\n\n```sh\ncd docker-nginx-php-mysql\n```\n\n### Project tree\n\n```sh\n.\n├── Makefile\n├── README.md\n├── data\n│   └── db\n│       ├── dumps\n│       └── mysql\n├── doc\n├── docker-compose.yml\n├── etc\n│   ├── nginx\n│   │   ├── default.conf\n│   │   └── default.template.conf\n│   ├── php\n│   │   └── php.ini\n│   └── ssl\n└── web\n    ├── app\n    │   ├── composer.json.dist\n    │   ├── phpunit.xml.dist\n    │   ├── src\n    │   │   └── Foo.php\n    │   └── test\n    │       ├── FooTest.php\n    │       └── bootstrap.php\n    └── public\n        └── index.php\n```\n\n___\n\n## Configure Nginx With SSL Certificates\n\nYou can change the host name by editing the `.env` file.\n\nIf you modify the host name, do not forget to add it to the `/etc/hosts` file.\n\n1. Generate SSL certificates\n\n    ```sh\n    source .env \u0026\u0026 docker run --rm -v $(pwd)/etc/ssl:/certificates -e \"SERVER=$NGINX_HOST\" jacoelho/generate-certificate\n    ```\n\n2. Configure Nginx\n\n    Do not modify the `etc/nginx/default.conf` file, it is overwritten by  `etc/nginx/default.template.conf`\n\n    Edit nginx file `etc/nginx/default.template.conf` and uncomment the SSL server section :\n\n    ```sh\n    # server {\n    #     server_name ${NGINX_HOST};\n    #\n    #     listen 443 ssl;\n    #     fastcgi_param HTTPS on;\n    #     ...\n    # }\n    ```\n\n___\n\n## Configure Xdebug\n\nIf you use another IDE than [PHPStorm](https://www.jetbrains.com/phpstorm/) or [Netbeans](https://netbeans.org/), go to the [remote debugging](https://xdebug.org/docs/remote) section of Xdebug documentation.\n\nFor a better integration of Docker to PHPStorm, use the [documentation](https://github.com/nanoninja/docker-nginx-php-mysql/blob/master/doc/phpstorm-macosx.md).\n\n1. Get your own local IP address :\n\n    ```sh\n    sudo ifconfig\n    ```\n\n2. Edit php file `etc/php/php.ini` and comment or uncomment the configuration as needed.\n\n3. Set the `remote_host` parameter with your IP :\n\n    ```sh\n    xdebug.remote_host=192.168.0.1 # your IP\n    ```\n___\n\n## Run the application\n\n1. Copying the composer configuration file : \n\n    ```sh\n    cp web/app/composer.json.dist web/app/composer.json\n    ```\n\n2. Start the application :\n\n    ```sh\n    docker-compose up -d\n    ```\n\n    **Please wait this might take a several minutes...**\n\n    ```sh\n    docker-compose logs -f # Follow log output\n    ```\n\n3. Open your favorite browser :\n\n    * [http://localhost:8000](http://localhost:8000/)\n    * [https://localhost:3000](https://localhost:3000/) ([HTTPS](#configure-nginx-with-ssl-certificates) not configured by default)\n    * [http://localhost:8080](http://localhost:8080/) PHPMyAdmin (username: dev, password: dev)\n\n4. Stop and clear services\n\n    ```sh\n    docker-compose down -v\n    ```\n\n___\n\n## Use Makefile\n\nWhen developing, you can use [Makefile](https://en.wikipedia.org/wiki/Make_(software)) for doing the following operations :\n\n| Name          | Description                                  |\n|---------------|----------------------------------------------|\n| apidoc        | Generate documentation of API                |\n| clean         | Clean directories for reset                  |\n| code-sniff    | Check the API with PHP Code Sniffer (`PSR2`) |\n| composer-up   | Update PHP dependencies with composer        |\n| docker-start  | Create and start containers                  |\n| docker-stop   | Stop and clear all services                  |\n| gen-certs     | Generate SSL certificates for `nginx`        |\n| logs          | Follow log output                            |\n| mysql-dump    | Create backup of all databases               |\n| mysql-restore | Restore backup of all databases              |\n| phpmd         | Analyse the API with PHP Mess Detector       |\n| test          | Test application with phpunit                |\n\n### Examples\n\nStart the application :\n\n```sh\nmake docker-start\n```\n\nShow help :\n\n```sh\nmake help\n```\n\n___\n\n## Use Docker commands\n\n### Installing package with composer\n\n```sh\ndocker run --rm -v $(pwd)/web/app:/app composer require symfony/yaml\n```\n\n### Updating PHP dependencies with composer\n\n```sh\ndocker run --rm -v $(pwd)/web/app:/app composer update\n```\n\n### Generating PHP API documentation\n\n```sh\ndocker run --rm -v $(pwd):/data phpdoc/phpdoc -i=vendor/ -d /data/web/app/src -t /data/web/app/doc\n```\n\n### Testing PHP application with PHPUnit\n\n```sh\ndocker-compose exec -T php ./app/vendor/bin/phpunit --colors=always --configuration ./app\n```\n\n### Fixing standard code with [PSR2](http://www.php-fig.org/psr/psr-2/)\n\n```sh\ndocker-compose exec -T php ./app/vendor/bin/phpcbf -v --standard=PSR2 ./app/src\n```\n\n### Checking the standard code with [PSR2](http://www.php-fig.org/psr/psr-2/)\n\n```sh\ndocker-compose exec -T php ./app/vendor/bin/phpcs -v --standard=PSR2 ./app/src\n```\n\n### Analyzing source code with [PHP Mess Detector](https://phpmd.org/)\n\n```sh\ndocker-compose exec -T php ./app/vendor/bin/phpmd ./app/src text cleancode,codesize,controversial,design,naming,unusedcode\n```\n\n### Checking installed PHP extensions\n\n```sh\ndocker-compose exec php php -m\n```\n\n### Handling database\n\n#### MySQL shell access\n\n```sh\ndocker exec -it mysql bash\n```\n\nand\n\n```sh\nmysql -u\"$MYSQL_ROOT_USER\" -p\"$MYSQL_ROOT_PASSWORD\"\n```\n\n#### Creating a backup of all databases\n\n```sh\nmkdir -p data/db/dumps\n```\n\n```sh\nsource .env \u0026\u0026 docker exec $(docker-compose ps -q mysqldb) mysqldump --all-databases -u\"$MYSQL_ROOT_USER\" -p\"$MYSQL_ROOT_PASSWORD\" \u003e \"data/db/dumps/db.sql\"\n```\n\n#### Restoring a backup of all databases\n\n```sh\nsource .env \u0026\u0026 docker exec -i $(docker-compose ps -q mysqldb) mysql -u\"$MYSQL_ROOT_USER\" -p\"$MYSQL_ROOT_PASSWORD\" \u003c \"data/db/dumps/db.sql\"\n```\n\n#### Creating a backup of single database\n\n**`Notice:`** Replace \"YOUR_DB_NAME\" by your custom name.\n\n```sh\nsource .env \u0026\u0026 docker exec $(docker-compose ps -q mysqldb) mysqldump -u\"$MYSQL_ROOT_USER\" -p\"$MYSQL_ROOT_PASSWORD\" --databases YOUR_DB_NAME \u003e \"data/db/dumps/YOUR_DB_NAME_dump.sql\"\n```\n\n#### Restoring a backup of single database\n\n```sh\nsource .env \u0026\u0026 docker exec -i $(docker-compose ps -q mysqldb) mysql -u\"$MYSQL_ROOT_USER\" -p\"$MYSQL_ROOT_PASSWORD\" \u003c \"data/db/dumps/YOUR_DB_NAME_dump.sql\"\n```\n\n\n#### Connecting MySQL from [PDO](http://php.net/manual/en/book.pdo.php)\n\n```php\n\u003c?php\n    try {\n        $dsn = 'mysql:host=mysql;dbname=test;charset=utf8;port=3306';\n        $pdo = new PDO($dsn, 'dev', 'dev');\n    } catch (PDOException $e) {\n        echo $e-\u003egetMessage();\n    }\n?\u003e\n```\n\n___\n\n## Help us\n\nAny thought, feedback or (hopefully not!)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanoninja%2Fdocker-nginx-php-mysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnanoninja%2Fdocker-nginx-php-mysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanoninja%2Fdocker-nginx-php-mysql/lists"}