GithubHelp home page GithubHelp logo

nicolasbagatello / docker-php-slim Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 4.04 MB

Dockerized nginx mysql php slim redis

Makefile 42.40% PHP 51.91% Shell 5.68%
docker-commands makefile psr2 composer mysql nginx slim-framework php phinx phinx-migrations

docker-php-slim's Introduction

All credits to https://github.com/nanoninja/docker-nginx-php-mysql (@nanoninja) who did an incredible job. I added a bunch of stuff that I think is really useful when creating a new project on php.

Nginx PHP MySQL

Docker running Nginx, PHP-FPM, Composer and MySQL. Added slim 4, php-unit, phinx, php_codesniffer and more

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. Run the application

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

  4. Use Makefile [Optional]

    When developing, you can use Makefile for doing recurrent operations.

  5. Use Docker Commands

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


Install prerequisites

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

Ports

Server Port
MySQL 8989
Nginx 8000
Nginx SSL 3000

Clone the project

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

git clone [email protected]:nicolasbagatello/docker-php-slim.git

Go to the project directory :

cd docker-php-slim

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
    │   ├── db
    │   │   └── migrations
    │   │   │   └── 20191209155649_testing_Migration.php
    │   │   └── seeds
    │   │       └── TestingSeed.php
    │   ├── src
    │   │   └── Foo.php
    │   └── test
    │       ├── FooTest.php
    │       └── bootstrap.php
    └── public
        └── index.php
    ├── phinx.yml

Run the application

  1. Copying the composer configuration file :

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

    sudo docker-compose up -d

    Please wait this might take a several minutes...

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

  4. Stop and clear services

    sudo docker-compose down -v

Use Makefile

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

  • Probably outdated command list :( so make sure to check make help toget the latest
Name Description
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
logs Follow log output
mysql-dump Create backup of all databases
mysql-restore Restore backup of all databases
test Test application with phpunit
run-migrations Run all migrations
run-seeds Run all seeds

Examples

Start the application :

sudo make docker-start

Show help :

make help

Migrations (updated to use sphinx) http://docs.phinx.org/en/latest/commands.html

sudo make run-migrations

Use Docker commands

Installing package with composer

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

Updating PHP dependencies with composer

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

Testing PHP application with PHPUnit

sudo docker-compose exec -T php ./app/vendor/bin/phpunit --colors=always --configuration ./app

Fixing standard code with PSR2

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

Checking the standard code with PSR2

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

Checking installed PHP extensions

sudo docker-compose exec php php -m

Handling database

MySQL shell access

sudo 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 && sudo docker exec $(sudo 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 && sudo docker exec -i $(sudo 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 && sudo docker exec $(sudo 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 && sudo docker exec -i $(sudo docker-compose ps -q mysqldb) mysql -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" < "data/db/dumps/YOUR_DB_NAME_dump.sql"

docker-php-slim's People

Contributors

nicolasbagatello avatar

Stargazers

 avatar

Watchers

 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.