新的程序需要php7才能支持,老程序必须用php5.x
准备安装php7
之前已经用yum安装了php5.4了,因为有老程序必须使用
所以需要保留php5.4采用源码编译安装
wget http://am1.php.net/distributions/php-7.2.0.tar.bz2
tar -jxvf php-7.2.0.tar.bz2
cd php-7.2.0安装依赖库
yum -y install libxml2-devel curl-devel libpng libpng-devel libxslt libxslt-devel
./configure --prefix=/usr/local/php7 --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath -enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvshm --enable-sysvmsg --enable-sysvsem --enable-xml --enable-zip --with-fpm-user=nginx --enable-ftp --enable-exif --enable-session --with-mhash --with-ldap
–prefix=/usr/local/php7 单独安装在php7的文件夹,避免和php5冲突*
--with-ldap 增加ldap支持编译
make
然后可以测试一下
make test #测试时间要十几分钟,可以跳过
安装
make install
准备配置文件
cp php.ini-production /usr/local/php7/etc/php.ini
cd /usr/local/php7/etc/
cp php-fpm.conf.default php-fpm.conf
cd php-fpm.d
cp www.conf.default www.conf
vi www.conf #修改端口号9001创建php7-fpm的服务
cd /usr/lib/systemd/system
cp php-fpm.service php-fpm7.service #拷贝php5的服务
cp /etc/sysconfig/php-fpm /usr/local/php7/etc/
vi php-fpm7.service #修改路径
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=notify
PIDFile=/run/php-fpm/php-fpm7.pid
EnvironmentFile=/usr/local/php7/etc/php-fpm
ExecStart=/usr/local/php7/sbin/php-fpm --nodaemonize
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
这个方式启动有点问题
启动后一直等等,这个时候php网站可以访问
然后一段时间会超时失败。失败后php网站无法访问。
init.d的方式启动
vi /etc/init.d/php-fpm7
\# ! /bin/sh
\# chkconfig: 2345 80 90
\# Comments to support chkconfig on CentOS
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="php-fpm7 daemon"
NAME=php-fpm7
DAEMON=/usr/local/php7/sbin/$NAME
CONFIGFILE=/usr/local/php7/etc/php-fpm.conf
PIDFILE=/usr/local/php7/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
\# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
d_start() {
$DAEMON -y $CONFIGFILE || echo -n " already running"
}
d_stop() {
kill -QUIT `cat $PIDFILE` || echo -n " not running"
}
d_reload() {
kill -HUP `cat $PIDFILE` || echo -n " can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC is success"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC is success"
d_stop
echo "."
;;
reload)
echo -n "Reloading $DESC configuration..."
d_reload
echo "reloaded."
;;
restart)
echo -n "Restarting $DESC is success"
d_stop
sleep 1
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
启动
chmod +x /etc/init.d/php-fpm7
/etc/init.d/php-fpm7 start
开机启动
chkconfig --add php-fpm7
chkconfig php-fpm7 on
chkconfig --list #检查是否成功