nginx-php configuration dynamic and static separation

Experimental purpose: nginx-php configuration dynamic and static separation

Experimental environment:
host 192.168.88.100 NGINX server
host 192.168.88.102 PHP and MYSQL server
Note: If you want to compile manually, you must install gcc gcc-c++ make these three plugins
and close the firewall
service firewalld stop
systemctl disable firewalld

http://nginx.org/en/download.htmlHere is the download address of the latest version of nginx

1. Manually compile and install the nginx server on 88.100

yum -y install \
pcre-devel \
zlib-devel

useradd -M -s /sbin/nologin nginx

Upload the prepared nginx source package to linux and decompress and compile
tar xzvf nginx-1.13.7.tar.gz -C /usr/src/
cd /usr/src/nginx-1.13.7

./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module

make && make install

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ //Make a soft connection to the system to manage nginx commands

nginx -t //Configuration file syntax check
nginx //Start service
killall -1 nginx //Safe restart
killall -3 nginx //Stop service

-------Make a management script------- //Let the systemctl service of the linux system recognize commands such as start restart stop
vi /etc/init.d/nginx
#!/bin/bash

chkconfig: 35 99 20

description: Nginx Service Control Script

PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
;;
stop)
kill -s QUIT $(cat $PIDF)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0

chmod +x /etc/init.d/nginx
chkconfig --add nginx

vi /usr/local/nginx/conf/nginx.conf

user nginx nginx;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html/webphp;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ .php$ {
root /var/www/html/webphp;
fastcgi_pass 192.168.88.102: 9000; // Give the dynamic page ending with php in the page to port 9000 of the 88.102 server, which is the php-fpm module to process
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/webphp$fastcgi_script_name;
include fastcgi_params;
}
}
}

service nginx restart

2. After manually compiling mysql on 88.102, compile PHP
to install and compile the required plugins
yum -y install \
ncurses \
ncurses-devel \
bison \
cmake

Add the mysql user to the system
useradd -s /sbin/nologin mysql

Unzip the mysql installation package uploaded to the server and compile
tar xf mysql-boost-5.7.20.tar.gz
cd mysql-5.7.20/

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1

make && make install

chown -R mysql.mysql /usr/local/mysql/

Modify the mysql main configuration file
vi /etc/my.cnf in /etc

[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES

chown mysql:mysql /etc/my.cnf

Set the environment variables required by mysql
echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
echo 'export PATH' >> /etc/profile
source /etc/profile

cd /usr/local/mysql/

bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data

cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start mysqld
netstat -anpt | grep 3306

systemctl enable mysqld

mysqladmin -u root -p password "abc123" //Set a password for the root account

mysql -u root -p


3. Also manually compile php on 88.102
The following are the plugins needed to manually compile php
yum -y install \
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 \
libxml2-devel \
zlib zlib-devel \
curl curl-devel\
openssl openssl-devel

Unzip the php source code package uploaded to the server and compile and install
tar xjvf php-7.1.10.tar.bz2
cd php-7.1.10
./configure \
--prefix=/usr/local/php \
--with-mysql -sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--enable-fpm \ //Open php's fpm The module is also the core of the dynamic and static separation of nginx and php
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-mbstring \
--enable -xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip

make && make install

cp php.ini-development /usr/local/php/lib/php.ini
vi /usr/local/php/lib/php.ini

mysqli.default_socket = /usr/local/mysql/mysql.sock //Modify line 1020, specify mysql's sock file
date.timezone = Asia/Shanghai //Modify line 939, specify the time zone

/usr/local/php/bin/php -m //Verify the installed modules and find that the fpm module is not displayed, but the fpm module is actually installed

-------------Configure and optimize FPM module -------
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf //will The template file becomes the configuration file
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf //The template file becomes the configuration file
vi www.conf // Modify line 36
192.168 .88.102:9000

cd /usr/local/php/etc/
vi php-fpm.conf

pid = run/php-fpm.pid // remove comments


/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini
netstat -anpt | grep 9000

ln -s /usr/local/php/bin/* /usr/local/bin/

ps aux | grep -c "php-fpm" //result

4 //result is 4

mkdir -p /var/www/html/webphp //created here is the root directory of the .php file defined on the nginx configuration file
vi /var/www/html/webphp/index.php //edit the test page

<?php
phpinfo();
?>
Enter the IP of the nginx server in the browser, i.e. 192.168.88.100/index.php, to access the dynamic PHP page

nginx-php configuration dynamic and static separation

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324654289&siteId=291194637