Nginx支持php脚本解释需要安装php-fpm进程管理器,在php5.3之前版本,php-fpm需要单独安装,之后版本php-fpm集成到PHP解释器之中,编译PHP解释器时需要特别指定配置,不同的PHP解释器版本编译经常出现兼容错误,在此可以成功编译php 7.2.15版本,其他版本(php 7.2.18)没有测试成功.
wget php-7.2.15.tar.bz2 http://cn2.php.net/distributions/php-7.2.15.tar.bz2
tar -xjvf php-7.2.15.tar.bz
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo
yum clean all && yum makecache
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
./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
make && make install
groupadd www
useradd -g www -s /sbin/nologin www
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
配置文件:/usr/local/php/etc/php.ini
session.save_path = “/usr/local/php/tmp”
date.timezone = PRC
配置文件:/usr/local/php/etc/php-fpm.d/www.conf
修改如下内容:
user = www
group = www
/usr/local/php/sbin/php-fpm
php-fpm服务端口是9000,在/usr/local/php/etc/php-fpm.d/www.conf中配置
在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;
}
chmod -R 777 /php_site