Nginx支持php脚本解释需要安装php-fpm进程管理器,在php5.3之前版本,php-fpm需要单独安装,之后版本php-fpm集成到PHP解释器之中,编译PHP解释器时需要特别指定配置,不同的PHP解释器版本编译经常出现兼容错误,在此可以成功编译php 7.2.15版本,其他版本(php 7.2.18)没有测试成功.
1. 下载php 7.2.15
wget php-7.2.15.tar.bz2 http://cn2.php.net/distributions/php-7.2.15.tar.bz2
2. 解压
tar -xjvf php-7.2.15.tar.bz
3. 安装YUM源
wget -O /etc/yum.repos.d/CentOS-Base.repo https://baitexiaoyuan.oss-cn-zhangjiakou.aliyuncs.com/updatecrm/php/20230824/Centos-vault-6.10.repo
yum clean all && yum makecache
4. 安装yum依赖
yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel
5. 配置编译脚本
./configure \
--prefix=/usr/local/php \
--enable-fpm \
--with-config-file-path=/usr/local/php/etc \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-pdo \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir= \
--enable-xml \
--enable-session \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--enable-intl \
--enable-pcntl \
--enable-ftp \
--with-gd \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--disable-fileinfo \
--enable-opcache \
--enable-maintainer-zts \
--with-xsl \
--enable-tokenizer
6. 编译并安装
make && make install
7.添加www用户
groupadd www
useradd -g www -s /sbin/nologin www
8.复制配置文件
cp php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
9.修改PHP的session文件存放目录
配置文件:/usr/local/php/etc/php.ini
session.save_path = “/usr/local/php/tmp”
10.修改PHP默认UTC时区改成中国时区
date.timezone = PRC
11.修改 php-fpm 用户组
配置文件:/usr/local/php/etc/php-fpm.d/www.conf
修改如下内容:
user = www
group = www
11.启动 php-fpm 服务
/usr/local/php/sbin/php-fpm
php-fpm服务端口是9000,在/usr/local/php/etc/php-fpm.d/www.conf中配置
12.Nginx配置
在server中添加如下
root /php_site/; location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
13.修改网站目录属性
chmod -R 777 /php_site
发表评论 取消回复