virzen / notes-php

Home Page:http://139.59.159.218

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Notes in PHP

Project based on docker-nginx-php-mysql template.

Overview

  1. Install prerequisites

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

  2. Run the application

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

  3. Use Makefile [Optional]

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

  4. 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

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 8989
PHPMyAdmin 8080
Nginx 8000
Nginx SSL 3000

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 :

Name Description
clean Clean directories for reset
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

Examples

Start the application :

sudo make docker-start

Show help :

make help

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

Generating PHP API documentation

sudo docker-compose exec -T php php -d memory_limit=256M -d xdebug.profiler_enable=0 ./app/vendor/bin/apigen generate app/src --destination ./app/doc

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

Analyzing source code with PHP Mess Detector

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

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"

Connecting MySQL from PDO

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

About

http://139.59.159.218


Languages

Language:PHP 79.0%Language:Makefile 11.2%Language:CSS 7.6%Language:Shell 2.3%