nginx-php configuration static and dynamic separation

Source: Internet
Author: User

Experimental purpose: nginx-php configuration static and dynamic separation

Lab Environment:
Host 192.168.88.100 Nginx Server
Host 192.168.88.102 PHP and MySQL server
Note: To manually compile the three plugins that must be installed GCC gcc-c++ make
And shut down the firewall
Service Firewalld Stop
Systemctl Disable FIREWALLD

Http://nginx.org/en/download.html, this is 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 unzip the compilation
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///Manage Nginx commands in a soft connection to the system

NGINX-T//config file Syntax check
Nginx//Start-up service
KILLALL-1 nginx//safe restart
Killall-3 nginx//Stop service

-------Production Management corner of the--------//Let Linux system Systemctl service can recognize the start restart stop and other commands
Vi/etc/init.d/nginx
#!/bin/bash

chkconfig:35 20description:nginx Service Control Script

Prog= "/usr/local/nginx/sbin/nginx"
pidf= "/usr/local/nginx/logs/nginx.pid"
Case "$" in
Start
$PROG
;;
Stop
Kill-s QUIT $ (cat $PIDF)
;;
Restart
$ stop
$ start
;;
Reload
Kill-s HUP $ (cat $PIDF)
;;
*)
echo "Usage: $ {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 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}
Location ~. php$ {
root/var/www/html/webphp;
Fastcgi_pass 192.168.88.102:9000; The page in PHP to the end of the dynamic page to 88.102 Server 9000 port, that is, the PHP-FPM module to handle
Fastcgi_index index.php;
Fastcgi_param Script_filename/var/www/html/webphp$fastcgi_script_name;
Include Fastcgi_params;
}
}
}

Service Nginx Restart

2. Compile php after manually compiling MySQL on 88.102
Install the plugins required for compilation
Yum-y install \
ncurses \
Ncurses-devel \
Bison \
CMake

Add a MySQL user to the system
Useradd-s/sbin/nologin MySQL

Unzip and compile the MySQL installation package uploaded to the server
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/

Modifying the MySQL master configuration file in/etc
Vi/etc/my.cnf

[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

Setting the environment variables required for 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 password for 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 and compile the PHP source code package uploaded to the server
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 FPM module, also the core of the static and dynamic 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 1020 lines, specify the MySQL sock file
Date.timezone = Asia/shanghai//Modify 939 lines, specify time zone

/USR/LOCAL/PHP/BIN/PHP-M//Verify the installed module and found no display to install the FPM module, but the FPM module is actually installed

-----------Configuring and optimizing the FPM module--------
cd/usr/local/php/etc/
CP Php-fpm.conf.default php-fpm.conf//change template file to config file
cd/usr/local/php/etc/php-fpm.d/
CP Www.conf.default www.conf//change template file to config file
VI www.conf//Modify 36 lines
192.168.88.102:9000

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

PID = run/php-fpm.pid//Remove Comment

/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"//Results

4//result is 4

Mkdir-p/var/www/html/webphp//The root directory of the. php file that is defined on the Nginx configuration file is created here.
vi/var/www/html/webphp/index.php//Edit Test page

<?php
Phpinfo ();
?>
Enter the IP of the Nginx server in the browser 192.168.88.100/index.php can access the dynamic PHP page

nginx-php configuration static and dynamic separation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.