Skip to content

This project helps you quickly create a web development environment with PHP-FPM, Nginx, MySQL, and Redis.

License

Notifications You must be signed in to change notification settings

congcoi123/docker-php-nginx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

This project helps you quickly create a web development environment with PHP-FPM, Nginx, MySQL, and Redis. The environment is based on Amazon Linux 2.

Technology

Docker is a set of the platform as service products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels.

Test Environment

Host machine

  • MacBook Pro (13-inch, 2017, Two Thunderbolt 3 ports)
  • OS: macOS Mojave (10.14.2)

Docker

  • Version: 2.1.0.4 (39773)
  • Channel: stable
  • Engine: 19.03.4

License

This project is currently available under the MIT License.

Installation

You can get the sources:

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

Manual

Project Structure

Project Structure

a. docker/ app cache db web

Include all of the environment’s settings by Docker for this project.

b. docker/gen/cache

Reference to Redis cache ‘s data. The data in this folder will be removed when the Redis’s container is destroyed.

c. docker/gen/data

Reference to MySQL ‘s data. The data in this folder will be removed when MySQL’s container is destroyed.

d. docker/gen/logs

Reference to all necessary logs by several services (Nginx, MySQL, PHP-fpm, Redis, Xhprof). The logging data will be removed with the destruction of the reference containers.

e. docker/gen/tmp

Reference to the /tmp folder in the application container.

f. docker/db/dump

This folder can be empty. Hold the dummy database for local testing.

g. docker/startup

Include all necessary scripts for setting up a development environment by Docker for this project. It must be seen first!

h. sample-app

Hold the project’s source code. All the changes here will be updated immediately to all services in containers.

i. .env

Hold the environment variables for the development environment.

j. docker-compose.yml

Define the services that make up your app. So they can be run together in an isolated environment.

Scripts

Scripts

Saved in the startup folder. Only docker_setup.sh script is necessary for this setup.

a. docker_setup.sh

Automatic setup of the development environment. Take about 10 minutes for all processes. You can check the log in your console screen.

b. access_application.sh

Quick access to the development’s container (amazon-linux:2)

c. access_nginx.sh

Quick access to the web service container (nginx)

d. env_setup.sh

This script is automatically called in the docker_setup.sh process. But you can use it manually for running a composer setting.

e. env_status.sh

Check the status of the current containers.

f. get_os_name.sh

Check the current OS’s name of your host machine.

g. mysql_migrations

Migrations all the scripts that hold in /sample-app/migrations

MySQL Migration

h. restart_application.sh

Restart the current application service. It can be helpful when you want to change some configurations in php.ini or www.conf (Please make the changes before restarting)

Restart Application

i. restart_nginx.sh

Restart the current web service (Nginx). It can be helpful when you want to change some configurations in nginx.conf file or any files in web/conf/ folder

Restart Nginx

k. start

Start all services.

l. stop

Stop all services.

Environment Variables

All the environment is saved in the .env file.

Environment Variables

COMPOSE_PROJECT_NAME

The project’s name and identification. Please do not modify it.

WEB_PORT

Nginx service port, because of the containers and host machine share resources. So you can access the program by your browser. Just use: localhost:<port>/ . In my case, I can use localhost:8000/

WEB_SSL_PORT

Same with WEB_PORT but for SSL.

DB_PORT

For preventing conflict with your in-use port in your host machine, you can change the MySQL’s port.

  • Step 1: Change the DB_PORT definition with your new port.
  • Step 2: Make the change in /docker/db/conf/my.cnf file with the same new port. my.cnf

FPM_PORT

For preventing conflict with your in-use port in your host machine, you can change the PHP-fpm port. FPM is a process manager to manage the FastCGI SAPI (Server API) in PHP. Basically, it replaces the need for something like SpawnFCGI . It spawns the FastCGI children adaptively (meaning launching more if the current load requires it). Otherwise, there's not much operating difference between it and FastCGI (The request pipeline from the start of the request to end is the same). It's just there to make implementing it easier.

  • Step 1: Change the FPM_PORT definition with your new port.
  • Step 2: Make the same change in /docker/app/conf/www.conf file at listen definition. www.conf
  • Step 3: Make some changes in /docker/web/conf/nginx.conf . All the fastcgi_pass definition must be set to new pattern sample_app:<your_new_port>; In my case is fastcgi_pass sample_app:9001; nginx.conf

Start

Run the following instructions for the starting setup.

$cd /docker-php-nginx/docker/startup
$bash docker_setup.sh

Notes

  • When you get errors when running the database container, you can delete the old docker/gen/data folder and retry again Please note that the data folder holds your real MySQL backup. But if it’s not important for you, it should be deleted (In some case, that folder make some troubles)
  • Access the URL below for starting: http://localhost:< WEB_PORT > . In my case: http://localhost:8000

Happy coding !

About

This project helps you quickly create a web development environment with PHP-FPM, Nginx, MySQL, and Redis.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published