Installation of Lnmp (Multi-PHP Version and Pagoda)

[info] Just a little bit of understanding. It's not really like this. It's all done by docker-compose.

Install Lnmp (multiple PHP versions)

Download the corresponding mirror version

https://hub.docker.com/ Search mirroring

docker pull mysql:8.0
docker pull mysql:5.7
docker pull php:7.2-fpm
docker pull php:5.6-fpm
docker pull nginx:1.15

Create containers, map working directories and ports

# Create a php:5.6-fpm container and name it php56. Map the container's 9000 port to the host's 9000 port.
# Note: Host on the left and docker on the right
# Note: The mounted directory should be the same as the root directory of the nginx configuration
docker run -d -p 9000:9000 --name php56 -v /home/docker/wwwroot:/usr/share/nginx/html php:5.6-fpm

# Stop the previous version and create another version of PHP
# After entering the container, install the corresponding extended docker-php-ext-install mysqli through docker-php-ext-install
docker run -d -p 9000:9000 --name php72 -v /home/docker/wwwroot:/usr/share/nginx/html php:7.2-fpm

# Create mysql containers, and the same image creates multiple containers (mirrors are like classes, containers are like instances)
docker run -d -p 3307:3306 --name mysql57-master  -e  MYSQL_ROOT_PASSWORD=123456  mysql:5.7
docker run -d -p 3308:3306 --name mysql57-slave  -e  MYSQL_ROOT_PASSWORD=123456 mysql:5.7

# Create nginx containers
# 1. The first "-v" is the location of the project. Just put the project in the mounted directory.
# 2. The second "-v" is the main configuration file "nginx.conf" mounted. Note that there is a line in the "nginx.conf" file.
#    "include /etc/nginx/conf.d/*.conf;" ,
#     This include points to the path of the subconfiguration file. Note here that the path followed by the include must not go wrong.
# 3. The third "-v" mounts the path of the sub-configuration file in docker, noting that it is the same as the include pointing path in "2."
# 4. nginx.conf mounts a file (docker is not recommended for this purpose), and conf.d mounts a directory.
# Note that you must create directories before mounting them
docker run \
    --name nginx115 \
    -d -p 80:80  \
    -v /home/docker/wwwroot:/usr/share/nginx/html  \
    -v /home/docker/nginx/nginx.conf:/etc/nginx/nginx.conf \
    -v /home/docker/nginx/vhost:/etc/nginx/conf.d  \
nginx:1.15

[info] 1. Mounted directories can be viewed in containers with the nsenter command. Be careful not to use docker attach. You can even use docker exec-i-t container_name/bin/bash

  1. To understand the mapping directory, the host directory is only mapped to the container directory, and the corresponding configuration should be done from the perspective of the container directory!
  2. Note that php's mount directory should be consistent with nginx's mount directory, otherwise File not found. Error will occur!

To configure

[danger] Note that all configurations start with the container root directory; do not set it to the mapped host directory.

nginx.conf

user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;
    include /etc/nginx/conf.d/*.conf;
}

hello_world.conf

server {

  listen 80;
  server_name  localhost;

  # Here is the location of the container!
  root  /usr/share/nginx/html;
  index index.php index.html;

  location / {
    index index.php index.html index.htm;
    if (!-e $request_filename) {
      rewrite ^/(.*)$ /index.php?$1 last;
      break;
    }
  }

  location ~ \.php$ {
    # Here the ip is the ip address of the container corresponding to the PHP version
    # Docker inspect-f'{Network Settings.IPAddress}'container name
    # Version switching means stopping and starting the container for the corresponding version.
    fastcgi_pass 172.17.0.2:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }
}

Install PHP extensions

docker exec -it php5.6 /bin/bash
docker-php-ext-install mysqli (mysql,gd,curl,...)

Install non-native PHP extensions in mirrors: for example, php-redis extensions:
php-redis Extended Download Address: https://github.com/phpredis/p... (Select the appropriate version to download)
You can download it in a php container using wget, or you can download it in ubuntu and copy it into the container.

#Copy / data / PHP redis 3.1.2 from ubuntu to the container's / usr/src/php/ext / directory and rename it redis.
docker cp /data/phpredis3.1.2 php5.6:/usr/src/php/ext/redis

PHP links mysql to other containers

<?php
$dbms='mysql';     //Database type
$host='172.17.0.3'; //Container ip
$port=3306;
/*
$host='172.28.3.199'; //Host ip
$port=3307;

Be careful:
Port mapping: 3307:3306
 Container ip: 172.17.0.3
 Host ip: 172.28.3.199
 If you want to link through container ip, port should fill in port 3306 of container ip.
Instead of mapping to port 3307 of the host.
If you want to link through the host ip, the port is written to port 3307 mapped to the host.
*/

$dbName='test';    //The database used
$user='root';      //Database Connection User Name
$pass='123456';          //The corresponding password
$dsn="$dbms:host=$host;port=$port;dbname=$dbName";
try {
    $dbh = new PDO($dsn, $user, $pass); //Initialize a PDO object
    echo "Successful connection<br/>";
    foreach ($dbh->query('SELECT * from test') as $row) {
        print_r($row);
    }
    $dbh = null;
} catch (PDOException $e) {
    die ("Error!: " . $e->getMessage() . "<br/>");
}

Installation of docker pagoda panel (not recommended for testing)

docker pull centos:7

# Because it's for swoole development, there are many ports open
# Use only in development environments
docker run -it -p 20:20 -p 21:21 -p 80:80 -p 8080:8080 -p 443:443 -p 3366:3306 -p 6399:6379 -p 888:888 -p 8888:8888 -p 9500:9500 -p 9501:9501 -p 9502:9502 -p 9503:9503 -p 9504:9504 -p 9505:9505 --name bt_panel  -v /home/docker/wwwroot:/home/wwwroot centos:7

# Download the necessary tools
yum -y update  && yum -y install initscripts screen wget

# To prevent network dropout or accidental exit, you can use screen tool
screen -S install_bt

# Installation of pagoda panel
wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh

Output the following after installation

==================================================================
Congratulations! Installed successfully!
==================================================================
# Self-replacing intranet ip
Bt-Panel: http://180.168.76.242:8888/6a863329
username: vzsybxji
password: 455e4a2a

# Pagoda command
https://www.bt.cn/btcode.html

Tags: Linux Docker PHP Nginx MySQL

Posted on Mon, 07 Oct 2019 08:41:43 -0700 by power3