Detailed explanation of the process of using Docker to build a PHP operating environment in CentOS7 environment

Detailed explanation of the process of using Docker to build a PHP operating environment in CentOS7 environment

Related articles:

Install Docker using yum under CentOS7

Using Docker to build a PHP operating environment in Win10 environment

1. Create a private network

docker network create lnmp

The private network is created successfully:

2. Install Nginx

Mirror address: https://hub.docker.com/_/nginx?tab=tags

You can install the latest version of Nginx. Here, you can search for tags and pull the Nginx1.18.0 image:

docker pull nginx:1.18.0

Use the docker images command to check that the Nginx image is installed successfully:

Run Nginx:

#Run the container docker run --name nginx -p 8080:80 -v /root/docker/nginx/html:/usr/share/nginx/html -d nginx:1.18.0
 
#Move to the configuration directory cd /root/docker/nginx
 
#Copy the configuration file docker cp nginx:/etc/nginx/conf.d conf.d
 
#Stop the container docker stop nginx
 
#Delete the container docker rm nginx 
 
#Run again docker run --name nginx -p 8080:80 --network lnmp -v /root/docker/nginx/html:/usr/share/nginx/html -v /root/docker/nginx/conf.d:/etc/nginx/conf.d/ -d nginx:1.18.0

Test: Create an index.html file in the html directory of the Nginx site root directory and write the following text:

echo "Nginx Server" >> /root/docker/nginx/html/index.html

The browser accesses the host address 127.0.0.1:8080 as follows, and Nginx is installed successfully:

3. Install MySQL

Mirror address: https://hub.docker.com/_/mysql?tab=tags , pull the MySQL5.7.34 image here:

docker pull mysql:5.7.35

Run MySQL:

docker run --name mysql5.7 --network lnmp -v /root/docker/mysql/:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d --privileged=true mysql:5.7.35

4. Install PHP

Mirror address: https://hub.docker.com/_/php?tab=tags, pull the PHP7.4 image here:

docker pull php:7.4-fpm

Run PHP:

#Run the image docker run --name php7.4 --network lnmp -d php:7.4-fpm
 
#Create directory mkdir -p /root/docker/php
 
#Move directory cd /root/docker/php/
 
#Copy www.conf
docker cp php7.4:/usr/local/etc/php-fpm.d/www.conf www.conf
 
#Enter the container docker exec -it php7.4 bash
 
#Move directory cd /usr/src/
 
#Unzip the file xz -d php.tar.xz
 
#Unzip the file tar -xvf php.tar
 
#Exit the image exit
 
#Copy php.ini
docker cp php7.4:/usr/src/php-7.4.22/php.ini-production php.ini
 
#Stop the image docker stop php7.4
 
#Delete the image docker rm php7.4
 
#Run the image again docker run --name php7.4 --network lnmp -v /root/docker/nginx/html:/var/www/html -v /root/docker/php/www.conf:/usr/local/etc/php-fpm.d/www.conf -v /root/docker/php/php.ini:/usr/local/etc/php/php.ini -d php:7.4-fpm

Edit the Nginx configuration file vim /root/docker/nginx/conf.d:

server {
    listen 80;
    server_name localhost;
    
    #charset koi8-r;
    #access_log /var/log/nginx/log/host.access.log main;
 
    location / {
        root /usr/share/nginx/html;
        index index.php index.html index.htm;
        try_files $uri $uri/ =404;
    }
 
    error_page 404 /404.html;
    location = /40x.html {
        root /user/share/nginx/html;
    }
 
    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
 
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root /var/www/html/;
        fastcgi_pass php7.4:9000;
        fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 
    }
}

Create the index.php file: vim /root/docker/nginx/html/index.php

<?php
    phpinfo();

Restart the Nginx image: (The process ID is viewed through the docker ps command)

docker restart 43aea5a90446

At this time, the browser accesses the host address 127.0.0.1:8080 as follows, and PHP is installed successfully:

This is the end of this article about using Docker to build a PHP operating environment in a CentOS7 environment. For more information about using Docker to build a PHP operating environment, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • The whole process of using docker to build php7 and nginx operating environment (official image)
  • Implementation of Centos7+Docker+Jenkins+ASP.NET Core 2.0 automated release and deployment
  • Centos7 uses docker to build gitlab server
  • How to build a docker private warehouse in centos7 (kubernetes)
  • CentOS7 Nvidia Docker environment construction

<<:  User-centered design

>>:  Example of implementing grouping and deduplication in MySQL table join query

Recommend

Vue implements irregular screenshots

Table of contents Image capture through svg CSS p...

Several ways to update batches in MySQL

Typically, we use the following SQL statement to ...

Discussion on CSS style priority and cascading order

In general : [1 important flag] > [4 special fl...

wget downloads the entire website (whole subdirectory) or a specific directory

Use wget command to download the entire subdirect...

Native js realizes the drag and drop of the nine-square grid

Use native JS to write a nine-square grid to achi...

How to solve the problem that the project in eclipse cannot be added to tomcat

1. Right-click the project and select properties ...

Javascript Basics: Detailed Explanation of Operators and Flow Control

Table of contents 1. Operator 1.1 Arithmetic oper...

Basic use of javascript array includes and reduce

Table of contents Preface Array.prototype.include...

jQuery implements ad display and hide animation

We often see ads appear after a few seconds and t...

How to use the yum command

1. Introduction to yum Yum (full name Yellow dogU...

Detailed explanation of CSS text decoration text-decoration &amp; text-emphasis

In CSS, text is one of the most common things we ...

Docker custom network detailed introduction

Table of contents Docker custom network 1. Introd...

Detailed explanation of the execution plan explain command example in MySQL

Preface The explain command is the primary way to...