Giter Site home page Giter Site logo

docker-npmp's Introduction

NPMP Nginx Php Mysql Phpmyadmin

███████████████████████████████████████████████████████████████ █─▄▄▄▄██▀▄─██▄─█─▄█▄─▄███▄─█─▄████▀▄─██▄─█─▄█─▄▄─█▄─██─▄█▄─▄─▀█ █▄▄▄▄─██─▀─███─▄▀███─██▀██▄─▄█████─▀─███▄─▄██─██─██─██─███─▄─▀█ ▀▄▄▄▄▄▀▄▄▀▄▄▀▄▄▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▀▀▄▄▀▄▄▀▀▄▄▄▀▀▄▄▄▄▀▀▄▄▄▄▀▀▄▄▄▄▀▀

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

Install prerequisites

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 :

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 :

Server Port
MySQL 3306
PHPMyAdmin 8080
Nginx 80
Nginx SSL 443

Clone the project

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

git clone https://github.com/saklyayoub/docker-npmp.git

Go to the project directory :

cd docker-nginx-php-mysql

Project tree

├── docker
│   ├── Dockerfile-7.0FPM
│   ├── Dockerfile-7.4FPM
│   └── Dockerfile-latest
├── docker-compose.yml
├── etc
│   ├── nginx
│   │   ├── default.template.conf
│   │   ├── nginx.conf
│   │   ├── nginx.http.conf
│   │   └── nginx.https.conf
│   ├── php
│   │   └── php.ini
│   └── ssl
├── README.md
└── web
    ├── mysql
    |   ├── backups
    |   |   └── sample.sql
    |   └── init
    |       └── sample.sql
    ├── app
    │   ├── composer.json
    │   ├── composer.json.dist
    │   ├── phpunit.xml.dist
    │   ├── src
    │   │   └── Foo.php
    │   └── test
    │       ├── bootstrap.php
    │       └── FooTest.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 the etc/nginx/default.conf file, it is overwritten by etc/nginx/default.template.conf

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. Stop and clear services

    docker-compose down -v

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 exec $(docker-compose ps -q php) php ./app/vendor/bin/phpunit --colors=always --configuration ./public

Fixing standard code with PSR2

docker exec $(docker-compose ps -q php) php ./app/vendor/bin/phpcbf -v --standard=PSR2 ./public

Checking the standard code with PSR2

docker exec $(docker-compose ps -q php) php ./app/vendor/bin/phpcs -v --standard=PSR2 ./public

Analyzing source code with PHP Mess Detector

docker exec $(docker-compose ps -q php) php ./app/vendor/bin/phpmd ./public text cleancode,codesize,controversial,design,naming,unusedcode

Checking installed PHP extensions

docker-compose exec php php -m

Handling database

MySQL shell access

docker exec -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 && docker exec $(docker-compose ps -q mysql) mysqldump --all-databases -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" > "/web/mysql/backups/db.sql"

Restoring a backup of all databases

source .env && docker exec -i $(docker-compose ps -q mysql) mysql -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" < "/web/mysql/backups/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 mysql) mysqldump -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" --databases YOUR_DB_NAME > "/web/mysql/backups/YOUR_DB_NAME_dump.sql"

Restoring a backup of single database

source .env && docker exec -i $(docker-compose ps -q mysql) mysql -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" < "/web/mysql/backups/YOUR_DB_NAME_dump.sql"

docker-npmp's People

Contributors

saklyayoub avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.