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.
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.
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
This project is currently available under the MIT License.
You can get the sources:
git clone https://github.com/congcoi123/docker-php-nginx.git
Include all of the environment’s settings by Docker for this project.
Reference to Redis cache ‘s data. The data in this folder will be removed when the Redis’s container is destroyed.
Reference to MySQL ‘s data. The data in this folder will be removed when MySQL’s container is destroyed.
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.
Reference to the /tmp
folder in the application container.
This folder can be empty. Hold the dummy database for local testing.
Include all necessary scripts for setting up a development environment by Docker for this project. It must be seen first!
Hold the project’s source code. All the changes here will be updated immediately to all services in containers.
Hold the environment variables for the development environment.
Define the services that make up your app. So they can be run together in an isolated environment.
Saved in the startup folder. Only docker_setup.sh
script is necessary for this setup.
Automatic setup of the development environment. Take about 10 minutes for all processes. You can check the log in your console screen.
Quick access to the development’s container (amazon-linux:2
)
Quick access to the web service container (nginx
)
This script is automatically called in the docker_setup.sh
process. But you can use it manually for running a composer setting.
Check the status of the current containers.
Check the current OS’s name of your host machine.
Migrations all the scripts that hold in /sample-app/migrations
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 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
Start all services.
Stop all services.
All the environment is saved in the .env
file.
The project’s name and identification. Please do not modify it.
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/
Same with WEB_PORT
but for SSL.
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.
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. - Step 3:
Make some changes in
/docker/web/conf/nginx.conf
. All thefastcgi_pass
definition must be set to new patternsample_app:<your_new_port>;
In my case isfastcgi_pass sample_app:9001;
Run the following instructions for the starting setup.
$cd /docker-php-nginx/docker/startup
$bash docker_setup.sh
- 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 !