CentOS编译安装PHP7.2
介绍:
久闻PHP7的速度以及性能那可是比PHP5系列的任何一版本都要快,具体性能有多好,建议还是先尝试下再说。如果你是升级或新安装,那你首先需要考虑PHP7和程序是否存在兼容性,如果程序是基于PHP5开发的,那么就需要考虑PHP7是否适合你当前的生产环境,今天我就实操并安装用于生产中。
先安装PHP依赖包,否则在编译安装PHP7的过程当中会出现各种报错,安装完成后即可进入下一个环节。
安装扩展包并更新系统内核:
yum install epel-release -y yum update
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
cd /tmp groupadd www useradd -g www www wget http://am1.PHP.net/distributions/PHP-7.2.1.tar.gz tar xvf PHP-7.2.1.tar.gz cd PHP-7.2.1
设置变量并开始源码编译:
cp -frp /usr/lib64/libldap* /usr/lib/
./configure --prefix=/usr/local/PHP72 --with-config-file-path=/usr/local/PHP72/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 --with-apxs2=/usr/bin/apxs
开始安装:
make && make install
cp PHP.ini-development /usr/local/PHP72/etc/PHP.ini cp /usr/local/PHP72/etc/PHP-fpm.conf.default /usr/local/PHP72/etc/PHP-fpm.conf cp /usr/local/PHP72/etc/PHP-fpm.d/www.conf.default /usr/local/PHP72/etc/PHP-fpm.d/www.conf
vim /usr/local/PHP/etc/PHP.ini
expose_PHP = Off short_open_tag = ON max_execution_time = 300 max_input_time = 300 memory_limit = 128M post_max_size = 32M date.timezone = Asia/Shanghai mbstring.func_overload=2 extension = "/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.so opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=4000 opcache.revalidate_freq=60 opcache.fast_shutdown=1 opcache.enable_cli=1 #设置PHP安全函数 ;disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru disable_functions = eval,assert,passthru,escapeshellarg,escapeshellcmd,pfsockopen,leak,popepassthru,stream_socket_server,proc_close,PHPinfo #配置www.conf listen = /var/run/www/php-cgi.sock listen.owner = www listen.group = www listen.mode = 0660 listen.allowed_clients = 127.0.0.1 pm = dynamic listen.backlog = -1 pm.max_children = 180 pm.start_servers = 50 pm.min_spare_servers = 50 pm.max_spare_servers = 180 request_terminate_timeout = 120 request_slowlog_timeout = 50 slowlog = 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已经安装完成。
说明:禁用PHP函数,如果程序需要这些函数,可以取消禁止,新手建议忽略此步骤。
vim /usr/lib/systemd/system/PHP-fpm.service
[Unit] Description=The PHP FastCGI Process Manager After=syslog.target network.target [Service] Type=simple PIDFile=/usr/local/PHP/var/run/PHP-fpm.pid ExecStart=/usr/local/PHP/sbin/PHP-fpm --nodaemonize --fpm-config /usr/local/PHP/etc/PHP-fpm.conf ExecReload=/bin/kill -USR2 $MAINPID [Install] WantedBy=multi-user.target
启动PHP-fpm服务并加入开机自启动:
systemctl enable PHP-fpm.service systemctl restart PHP-fpm.service