1,从 php官网: http://cn2.php.net/downloads.php 选择需要的php版本,选择.tar.gz 的下载包,选择7.2以上版本
2,安装php所需要的依赖
yum install gcc
yum install libxml2
yum install libxml2-devel -y
yum install openssl openssl-devel -y
yum -y install curl-devel
yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y
yum install bzip2-devel.x86_64 -y
yum install libXpm-devel -y
yum install gmp-devel -y
yum install -y icu libicu libicu-devel
yum install php-mcrypt libmcrypt libmcrypt-devel -y
yum install postgresql-devel -y
yum install libxslt-devel -y
yum -y install libjpeg-devel
yum -y install readline-devel
3,解压编译
tar -xzxvf php-7.2.0.tar.gz
cd php-7.2.0
设置编译需要加载的模块
./configure \
--prefix=/data/service/php\
--enable-fpm\
--with-fpm-user=www\
--with-fpm-group=www\
--with-config-file-path=/data/conf/php\
--disable-rpath\
--enable-soap\
--with-libxml-dir\
--with-xmlrpc\
--with-openssl\
--with-mhash\
--with-pcre-regex\
--with-zlib\
--enable-bcmath\
--with-bz2\
--enable-calendar\
--with-curl\
--enable-exif\
--with-pcre-dir\
--enable-ftp\
--with-gd\
--with-openssl-dir\
--with-jpeg-dir\
--with-png-dir\
--with-zlib-dir\
--with-freetype-dir\
--enable-gd-jis-conv\
--with-gettext\
--with-gmp\
--with-mhash\
--enable-mbstring\
--with-onig\
--with-mysqli\
--with-pdo-mysql\
--with-zlib-dir\
--with-readline\
--enable-shmop\
--enable-sockets\
--enable-sysvmsg\
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx\
--with-xsl\
--enable-zip\
--with-pear\
--enable-pcntl\
--with-iconv\
--enable-opcache\
--enable-mbregex\
--with-pcre-regex
编译:
make clean && make && make install
安装成功
-----------------------------------------------------------------------------
配置php
1. 复制配置文件
cp php.ini-development /data/service/php/etc/php.ini
2. 设置全局的php命令
vim /etc/profile
在文件最后添加:
PATH=$PATH:/data/service/php/bin
export PATH
然后执行 命令 source /etc/profile
此时php就是全局命令了,可以通过php -v 查看php版本信息或者php -m 看看刚刚编译加载的模块了
3,配置PHP-fpm
cp /data/service/php/etc/php-fpm.conf.default /data/service/php/etc/php-fpm.conf
cp /data/service/php/etc/php-fpm.d/www.conf.default /data/service/php/etc/php-fpm.d/www.conf
cp /usr/src/php-7.2.0/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
新建www 用户组:
groupadd www
useradd -g www www
启动php-fpm
/etc/init.d/php-fpm start
(可选)配置php-fpm自启动,如果存在这个文件,这步省略
创建php-fpm启动脚本
vim /etc/init.d/php-fpm
1
插入如下内容:
#!/bin/sh
# chkconfig: 2345 15 95
# description: PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation \
# with some additional features useful for sites of any size, especially busier sites.
# DateTime: 2016-09-20
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
phpfpm="/usr/local/php/sbin/php-fpm"
prog=$(basename ${phpfpm})
lockfile=/var/lock/subsys/phpfpm
start() {
[ -x ${phpfpm} ] || exit 5
echo -n $"Starting $prog: "
daemon ${phpfpm}
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc ${phpfpm} -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
${phpfpm} -t
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|configtest}"
exit 2
esac
添加到开机启动项
chkconfig --add php-fpm
此时也可以使用service来启动php-fpm了
service php-fpm start
service php-fpm stop