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

How to use rem adaptation in Vue

1. Development environment vue 2. Computer system...

Two usages of iFrame tags in HTML

I have been working on a project recently - Budou...

Software Testing - MySQL (VI: Database Functions)

1.MySQL functions 1. Mathematical functions PI() ...

JavaScript implements a box that follows the mouse movement

This article shares the specific code of JavaScri...

Similar to HTML tags: strong and em, q, cite, blockquote

There are some tags in XHTML that have similar fu...

Vue commonly used high-order functions and comprehensive examples

1. Commonly used high-order functions of arrays S...

React useMemo and useCallback usage scenarios

Table of contents useMemo useCallback useMemo We ...

Several common methods of sending requests using axios in React

Table of contents Install and introduce axios dep...

How to start a Java program in docker

Create a simple Spring boot web project Use the i...

Complete steps to install Anaconda3 in Ubuntu environment

Table of contents Introduction to Anaconda 1. Dow...

Vue implements picture verification code when logging in

This article example shares the specific code of ...

Specific use of the wx.getUserProfile interface in the applet

Recently, WeChat Mini Program has proposed adjust...