centos7编译安装PHP7.2(与Nginx搭配的安装方式)

一、下载源码包

二、安装php依赖组件

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 jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel

 

三、创建用户和组

groupadd www
useradd -g www www

四、设置变量并开始源码编译

cp -frp /usr/lib64/libldap* /usr/lib/

  

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mysqlnd-compression-support --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --with-libmbfl --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --with-pear --enable-maintainer-zts --with-ldap=shared --without-gdbm

五、开始编译

make && make install

六、完成安装后配置php.ini文件:

cp php.ini-development /usr/local/php/etc/php.inicp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.confcp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

修改 php.ini 相关参数:

vim /usr/local/php/etc/php.ini

 

expose_php = Offshort_open_tag = ONmax_execution_time = 300max_input_time = 300memory_limit = 128Mpost_max_size = 32Mdate.timezone = Asia/Shanghaimbstring.func_overload=2extension = "/usr/local/php/lib/php/extensions/no-debug-zts-20170718/ldap.so"#OPcache 缓存[opcache]zend_extension=/usr/local/php/lib/php/extensions/no-debug-zts-20170718/opcache.soopcache.memory_consumption=128opcache.interned_strings_buffer=8opcache.max_accelerated_files=4000opcache.revalidate_freq=60opcache.fast_shutdown=1opcache.enable_cli=1

七、配置www.conf

listen = /var/run/www/php-cgi.socklisten.owner = wwwlisten.group = wwwlisten.mode = 0660listen.allowed_clients = 127.0.0.1pm = dynamiclisten.backlog = -1pm.max_children = 180pm.start_servers = 50pm.min_spare_servers = 50pm.max_spare_servers = 180request_terminate_timeout = 120request_slowlog_timeout = 50slowlog = var/log/slow.log

八、创建php-cgi.sock存放目录

mkdir /var/run/www/chown -R www:www /var/run/www

九、配置php-fpm.conf

vim /usr/local/php/etc/php-fpm.conf

取下以下注释并填写完整路径:

pid = /usr/local/php/var/run/php-fpm.pid

至此php7已经安装完成。

十、创建system系统单元文件php-fpm启动脚本:

vim /usr/lib/systemd/system/php-fpm.service

添加如下变量内容:

[Unit]Description=The PHP FastCGI Process ManagerAfter=syslog.target network.target[Service]Type=simplePIDFile=/usr/local/php/var/run/php-fpm.pidExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.confExecReload=/bin/kill -USR2 $MAINPID[Install]WantedBy=multi-user.target

启动php-fpm服务并加入开机自启动:

systemctl enable php-fpm.servicesystemctl restart php-fpm.service

  

相关文章