mod_php -> php_fpm : apache2+centos

安装PHP到/opt/php7.1.12

./configure
--enable-shared 
--enable-mysqlnd 
--disable-rpath
--disable-short-tags
--enable-bcmath
--enable-calendar
--enable-exif
--enable-fileinfo
--enable-fpm
--enable-ftp
--enable-gd-native-ttf
--enable-inline-optimization
--enable-maintainer-zts
--enable-mbregex
--enable-mbstring
--enable-opcache
--enable-pcntl
--enable-shmop
--enable-soap
--enable-sockets
--enable-sysvsem
--enable-sysvshm
--enable-xml
--enable-zip
--enable-phpdbg
--prefix=/opt/php7.1.12
--with-bz2
--with-curl
--with-fpm-group=www-data
--with-fpm-user=www-data
--with-freetype-dir
--with-gd
--with-gettext
--with-imap
--with-imap-ssl
--with-jpeg-dir=/usr
--with-kerberos
--with-libdir=/lib64
--with-libxml-dir=/usr
--with-mcrypt
--with-mhash
--with-mysql-sock=/var/lib/mysql/mysql.sock
--with-mysqli
--with-openssl
--with-pcre-regex
--with-pdo-mysql
--with-png-dir=/usr
--with-webp-dir=/usr/include/webp
--with-xmlrpc
--with-xsl
--with-zlib
--with-zlib-dir

make && make install

# add php-fpm to service
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod o+x /etc/init.d/php-fpm
chkconfig --add php-fpm

配置 php-fpm

激活配置文件

# enable conf file
ls /opt/php7.1.12/etc/php-fpm.conf.default
cp  $_ ${_//.default/}
# enable pool conf file
ls /opt/php7.1.12/etc/php-fpm.d/www.conf.default
cp $_ ${_//.default/}
# edit conf file
vim $_

编辑 /opt/php7.1.12/etc/php-fpm.d/www.conf, daemon必须是系统中存在的用户,其他用户也可以,主要是listen的配置,路径可以指定其他的路径

user = daemon
group = daemon
listen = /dev/shm/php-fpm.sock
listen.owner = daemon
listen.group = daemon
pm = dynamic
pm.max_requests = 2048

配置 apache2

我的apache2安装在/usr/local下

vim /usr/local/apache2/conf/httpd.conf

注释掉

LoadModule php7_module        modules/libphp7.so

去掉proxy modules的注释

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
LoadModule proxy_scgi_module modules/mod_proxy_scgi.so

添加 php-fpm配置


    ProxySet disablereuse=off



    SetHandler proxy:fcgi://php-fpm

启动php-fpm 重启apache

service php-fpm start
apachectl -k stop
apachectl -k start

引用

  1. FastCGI 进程管理器(FPM)
  2. PHP-FPM配置及使用总结
  3. 从apache mod_php到php-fpm[转]

你可能感兴趣的:(mod_php -> php_fpm : apache2+centos)