参考视频教程:
**全方位深度剖析PHP7底层源码 **
编译安装
系统版本CentOS V7.6
PHP V7.3.3
yum安装PHP编译时的依赖库
shell>yum install libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel net-snmp net-snmp-devel openssl openssl-devel libcurl libcurl-devel
创建PHP用户和用户组(php用户没有登录权限)
shell>groupadd -r php && useradd -r -g php -s /bin/false -d /usr/local/php -M php
下载PHP主程序
shell>wget -c -P /opt/tmp/ http://ee1.php.net/distributions/php-7.3.3.tar.gz
进入目录并解压缩
shell>cd /opt/tmp
shell>tar zxvf php-7.3.3.tar.gz
shell>cd php-7.3.3
配置PHP并编译安装
shell>./configure \
–prefix=/usr/local/php \
–enable-bcmath \
–enable-mbstring \
–enable-sockets \
–enable-ctype \
–enable-opcache \
–enable-fpm \
–enable-mysqlnd \
–with-gd \
–with-png-dir \
–with-jpeg-dir \
–with-freetype-dir \
–with-libxml-dir \
–with-gettext \
–with-snmp \
–with-openssl-dir \
–with-curl \
–with-fpm-user=nginx \
–with-fpm-group=nginx \
–with-mysqli=mysqlnd \
–with-pdo-mysql=mysqlnd \
–with-mysql-sock=/var/lib/mysql/mysql.sock \
–without-pear \
–disable-phar
shell>make -j 4
shell>make install
下载pear.phar并安装
shell>wget http://pear.php.net/go-pear.phar
shell>/usr/local/php/bin/php go-pear.phar
查看编译成功后的PHP安装目录(需要确保至少存在mysqli.so、pdo_mysql.so这两个动态库文件)
shell>ls -lrt /usr/local/php/lib/php/extensions/no-debug-non-zts-20180731
设置PHP7的配置文件跟脚本php.ini、php-fpm.conf、www.conf、php-fpm
shell>cp -rv php.ini-production /usr/local/php/etc/php.ini
shell>cp -rv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
shell>cp -rv /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
shell>cp -R ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
添加PHP7的环境变量
shell>echo -e ‘\nexport PATH=/usr/local/php/bin:/usr/local/php/sbin:$PATH\n’ >> /etc/profile && source /etc/profile
设置PHP日志目录和php-fpm的运行进程ID文件(php-fpm.sock)目录
shell>mkdir -p /var/log/php-fpm/ && mkdir -p /var/run/php-fpm && cd /var/run/ && chown -R nginx:nginx php-fpm
修改session的目录配置
shell>mkdir -p /var/lib/php/session && chown -R nginx:nginx /var/lib/php
配置开机自启动,增加到主机sysV服务
shell>chmod +x /etc/init.d/php-fpm
shell>chkconfig –add php-fpm
shell>chkconfig php-fpm on
测试PHP的配置文件是否正确合法
shell>php-fpm -t
启动php服务
shell>service php-fpm start
查看PHP-FPM进程
shell>ps -aux|grep php-fpm
查看PHP7版本信息
shell>php -v
PHP与nginx整合
进入到nginx配置文件中修改
在localtion中增加index.php
location / {
root html;
index index.html index.htmi index.php;
}
在location~\.php$去掉全部注释并更改$document_root
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
保存后退出
在网站根目录下编写PHP测试文件
vim index.php
<?php
echo phpinfo();
?>
保存退出并重启nginx服务器
注意!!!测试完毕后删除该文件
nginx与php整合问题
nginx 报错 connect() failed (111: Connection refused) while connecting to upstream
环境Centos 8 、Nginx 1.16.1、PHP 7.2.11
查看监听端口
netstat -ant|grep 9000
查看服务
ps -ef|grep php
ps -ef|grep nginx
systemctl status php-fpm.service
nginx 配置文件:/usr/local/nginx/conf/nginx.conf
user nginx
取消注释($document_root)
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
php-fpm 配置文件
/etc/php-fpm.d/www.conf
user = nginx
group = nginx
在; Note: This value is mandatory.文件后找到listen
listen = 127.0.0.1:9000;