首先,浏览器发送httprequest请求到服务器(Nginx),服务器响应并处理web请求,将一些静态资源(CSS,图片,视频等)保存服务器上,然后将php脚本通过接口传输协议(网关协议)PHP-FCGI(fast-cgi)传输给PHP-FPM(进程管理程序),PHP-FPM不做处理;然后PHP-FPM调用PHP解析器进程,PHP解析器解析php脚本信息。PHP解析器进程可以启动多个,进行并发执行。然后将解析后的脚本返回到PHP-FPM,PHP-FPM再通过fast-cgi的形式将脚本信息传送给Nginx.服务器再通过Httpresponse的形式传送给浏览器。浏览器再进行解析与渲染然后进行呈现。
主机名 | ip | 说明 |
---|---|---|
Mysql-server | 192.168.10.11 | 数据库节点 |
php-server | 192.168.10.12 | php脚本程序解析 |
Nginx-server | 192.168.10.21 | web服务器 |
系统版本
[root@mysql-server ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
软件版本
[root@mysql-server ~]# mysql -V
mysql Ver 8.0.20 for Linux on x86_64 (MySQL Community Server - GPL)
[root@nginx-server ~]# nginx -v
nginx version: nginx/1.15.0
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
yum install ntp ntpdate -y
ntpdate cn.pool.ntp.org
hwclock --systohc
nginx安装
mysql安装
软件包来源:http://php.net
php-7.3.20需要的依赖:
安装包:https://cmake.org/download/
yum install gcc gcc-c++ -y
yum install openssl-devel gcc gcc-c++ make
tar xzf cmake* -C /usr/local/src
[root@php-server ~]# cd /usr/local/src/cmake-3.18.1/
[root@php-server cmake-3.18.1]# ./bootstrap
[root@php-server cmake-3.18.1]# echo $?
0
[root@php-server cmake-3.18.1]# make && make install
# 安装依赖
[root@php-server src]# yum install gcc zlib zlib-devel openssl openssl-devel perl perl-devel make -y
[root@php-server ~]# tar xzf libzip-1.5.2.tar.gz -C /usr/local/src/
[root@php-server ~]# cd /usr/local/src/libzip-1.5.2/
[root@php-server libzip-1.5.2]# mkdir build
[root@php-server libzip-1.5.2]# cd build
[root@php-server libzip-1.5.2]# cmake ..
[root@php-server libzip-1.5.2]# make && makeinstall
[root@php-server src]# wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
[root@php-server src]# yum -y install gd-devel libjpeg libjpeg-devel libpng libpng-devel libiconv-devel freetype freetype-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel libxslt-devel mhash
[root@php-server ~]# tar -xzf libmcrypt-2.5.7.tar.gz -C /usr/local/src/
[root@php-server ~]# cd /usr/local/src/libmcrypt-2.5.7/
[root@php-server libmcrypt-2.5.7]# ./configure
[root@php-server libmcrypt-2.5.7]# echo $?
0
[root@php-server libmcrypt-2.5.7]# make && make install
[root@php-server libmcrypt-2.5.7]# echo $?
0
[root@php-server libmcrypt-2.5.7]# rpm -qa libcurl
libcurl-7.29.0-51.el7.x86_64
[root@php-server libmcrypt-2.5.7]# rpm -e libcurl-7.29.0-51.el7.x86_64 --nodeps
[root@php-server src]# wget https://curl.haxx.se/download/curl-7.56.0.tar.gz
[root@php-server src]# tar xzf curl-7.56.0.tar.gz
[root@php-server src]# cd curl-7.56.0
[root@php-server curl-7.56.0]#./configure --prefix=/usr/local/curl --with-ssl --with-zlib
[root@php-server curl-7.56.0]# make && make install
[root@php-server ~]# ls
php-7.3.20.tar.gz
[root@php-server libmcrypt-2.5.7]# yum -y install gd-devel libjpeg libjpeg-devel libpng libpng-devel libiconv-devel freetype freetype-d autoconf
[root@php-server ~]# tar xf php-7.3.20.tar.gz -C /usr/local/src/
[root@php-server ~]# cd /usr/local/src/
[root@php-server src]# ls
php-7.3.20
[root@php-server src]# cd php-7.3.20/
[root@php-server php-7.2.0]# ./configure --prefix=/usr/local/php7 \
--with-config-file-path=/usr/local/php7/etc \
--with-curl=/usr/local/curl \
--disable-ipv6 \
--with-pdo-mysql \
--with-openssl \
--with-openssl-dir \
--with-pcre-regex \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir \
--with-mysqli=shared,mysqlnd \
--with-pdo-mysql=shared,mysqlnd \
--with-pdo-sqlite \
--with-gd \
--with-iconv \
--with-zlib \
--with-xmlrpc \
--with-xsl \
--with-pear \
--with-gettext \
--with-png-dir \
--with-jpeg-dir \
--with-freetype-dir \
--with-mcrypt \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-pdo \
--enable-mysqlnd \
--enable-zip \
--enable-inline-optimization \
--enable-shared \
--enable-libxml \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-ftp \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
--enable-soap \
--enable-session \
--enable-opcache \
--enable-fpm \
--enable-maintainer-zts \
--enable-fileinfo \
--enable-gd-jis-conv \
--with-zlib-dir
[root@php-server php-7.2.0]# echo $?
0
[root@php-server php-7.2.0]# make && make install
[root@php-server php-7.2.0]# echo $?
0
[root@php-server php-7.3.20]# cp php.ini-production /usr/local/php7/etc/php.ini
[root@php-server php-7.3.20]# cp php.ini-production /etc/php.ini
[root@php-server php-7.3.20]# cd sapi/fpm/
[root@php-server fpm]# cp -p init.d.php-fpm /etc/init.d/php-fpm
[root@php-server fpm]# cd /etc/init.d/
[root@php-server init.d]# ll
total 44
-rw-r--r--. 1 root root 18281 Aug 24 2018 functions
-rwxr-xr-x. 1 root root 4569 Aug 24 2018 netconsole
-rwxr-xr-x. 1 root root 7923 Aug 24 2018 network
-rw-r--r-- 1 root root 2402 Aug 2 21:46 php-fpm
-rw-r--r--. 1 root root 1160 Oct 31 2018 README
[root@php-server init.d]# chmod +x php-fpm
[root@php-server init.d]# chkconfig php-fpm on
[root@php-server init.d]# vim /etc/profile
[root@php-server init.d]# source /etc/profile
[root@php-server init.d]# php -v
PHP 7.3.20 (cli) (built: Aug 2 2020 22:00:06) ( ZTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.20, Copyright (c) 1998-2018 Zend Technologies
编辑php-fpm的配置文件(/usr/local/php7/etc/php-fpm.conf)
配置fpm相关选项为你所需要的值
[root@php-server ~]# cd /usr/local/php7/etc/
[root@php-server etc]# cp -p php-fpm.conf.default php-fpm.conf
[root@php-server etc]# cd php-fpm.d/
[root@php-server php-fpm.d]# cp www.conf.default www.conf
[root@php-server php-fpm.d]# cat /usr/local/php7/etc/php-fpm.d/www.conf |grep -iv '^\;'
[www]
user = nginx
group = nginx
listen = 0.0.0.0:9000
listen.owner = nginx
listen.group = nginx
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
[root@php-server ~]# useradd nginx
[root@php-server ~]# cd /usr/local/php/sbin
[root@php-server ~]# ./php-fpm
user nginx nginx;
error_log logs/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request"';
server {
listen 80;
server_name 192.168.10.21;
charset koi8-r;
access_log logs/host.access.log main;
location / {
root /www;
index index.html index.htm;
}
location ~ \.php$ {
root html;
fastcgi_pass 192.168.10.10:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
nginx -c /etc/nginx/nginx.conf
nginx -s reload
[root@php-server ~]# mkdir /www
[root@php-server ~]# chown -R nginx:nginx /www
[root@php-server ~]# vim /www/index.php
<?php
phpin
?>
mysql> create user 'super'@'%' identified with mysql_native_password by 'ABC123.com';
Query OK, 0 rows affected (0.50 sec)
mysql> create database memcacher;
Query OK, 1 row affected (0.27 sec)
[root@php-server ~]# cd /usr/local/src/php-7.3.20/ext/
[root@php-server ext]# cd mysql
mysqli/ mysqlnd/
[root@php-server ext]# cd mysql
mysqli/ mysqlnd/
[root@php-server ext]# cd mysqli/
[root@php-server mysqli]# /usr/local/php7/bin/phpize
Configuring for:
PHP Api Version: 20180731
Zend Module Api No: 20180731
Zend Extension Api No: 320180731
[root@php-server mysqli]# ./configure \
> --with-php-config=/usr/local/php7/bin/php-config \
> --enable-embedded-mysqli=shared \
> --enable-shared
[root@php-server mysqli]# echo $?
0
[root@php-server mysqli]# make && make install
[root@php-server mysqli]# echo $?
0
[root@php-server mysqli]# cd /usr/local/php7/lib/php/extensions/no-debug-zts-20180731/
[root@php-server no-debug-zts-20180731]# ls
mysqli.a mysqli.so opcache.a opcache.so pdo_mysql.a pdo_mysql.so
[root@php-server ~]# cd /usr/local/src/php-7.3.20/ext/pdo_mysql
[root@php-server pdo_mysql]# /usr/local/php7/bin/phpize
Configuring for:
PHP Api Version: 20180731
Zend Module Api No: 20180731
Zend Extension Api No: 320180731
[root@localhost pdo_mysql]# ./configure \
--with-php-config=/usr/local/php7/bin/php-config \
--with-pdo-mysql=mysqlnd
[root@php-server pdo_mysql]# make && make install
[root@php-server pdo_mysql]# echo $?
0
[root@php-server php-7.3.20]# cp php.ini-production /usr/local/php7/etc/php.ini
cp: overwrite ‘/usr/local/php7/etc/php.ini’? y
[root@php-server php-7.3.20]# cd /usr/local/php7/etc/
[root@php-server etc]# vim php.ini
[root@php-server etc]# cd /usr/local/php7/lib/php/extensions/
extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-zts-20180731"
extension = mysqli.so
extension = pdo_mysql.so
[root@php-server php7]# cd sbin
[root@php-server sbin]# ps -ef | grep php
# kill php进程号,可能出现进程占用情况,建议这样杀死在启动
[root@php-server ~]# cd /usr/local/php7/sbin/
[root@php-server sbin]# ./php-fpm
#注 php服务器上编辑
[root@php-server ~]# vim /www/index1.php
<?php
$con = new mysqli('192.168.10.11','super','ABC123.com','memcacher');
if(!$con)
echo "faling ...";
else
echo "success connect mysql\n";
?>
configure: error: off_t undefined; check your library configuration
echo '/usr/local/lib64 /usr/local/lib /usr/lib /usr/lib64'>>/etc/ld.so.conf
# 更新配置
ldconfig -v
--with-libdir=lib
将这个模块改为
--with-libdir=lib64
最终发现nginx中nginx.conf配置错误,仔细检查,修改后重启即可。
由于修改配置后,需要重新启动,此时启动失败
ps -ef | grep php
kill php主进程号
再次启动即可
------------------------------------------------------------------------------------------------------- 返回目录