安装扩展包并更新系统内核
yum install epel-release -y
yum -y update
安装php依赖组件(包含Nginx依赖):
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
创建用户和组,并下载php安装包解压:
cd /usr/local/src/
groupadd www
useradd -g www www
wget http://cn2.php.net/distributions/php-7.2.8.tar.gz
tar xvf php-7.2.1.tar.gz
cd php-7.2.8
设置变量并开始源码编译:
cp -frp /usr/lib64/libldap* /usr/lib/
./configure --enable-fpm --prefix=/usr/local/php --sysconfdir=/usr/local/php/etc --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/php.d --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --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 --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --with-bz2 --enable-opcache --enable-soap --without-pear
报错:configure: error: Please reinstall the BZip2 distribution,执行:
yum -y install bzip2 bzip2-devel
然后充值配置
若无报错执行下一步安装,如果编译过程中出现错误,根据报错安装依赖包,通常不会出现这种问题。
开始安装:
make -j 4 && make install
若无报错执行下一步,如果编译过程中出现错误libtool: link: `ext/standard/info.lo' is not a valid libtool object删除源码目录,重新解压源码,编译、安装,如果出现其他错误,根据错误自行解决。
完成安装后配置php.ini文件:
cp php.ini-development /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
修改 php.ini 相关参数:
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
配置www.conf
vi /usr/local/php/etc/php-fpm.d/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函数,如果程序需要这些函数,可以取消禁止,新手建议忽略此步骤。
创建system系统单元文件php-fpm启动脚本:
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
网友评论