多个版本php要共存,必须使用不同的安装路径,这里使用源码编译安装
**php编译参数详解:http://blog.oldboyedu.com/php-compiler-parameters/
安装php71
cd /usr/local/src/
wget http://cn2.php.net/distributions/php-7.1.1.tar.gztar xf php-7.1.1.tar.gz
cd /usr/local/src/php-7.1.1/
./configure --prefix=/usr/local/php71 --with-config-file-path=/usr/local/php71/etc --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gd --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-pear --with-gettext --enable-session --with-mcrypt --with-curl
make && make install
php7.1编译安装时碰到 undefined reference to `libiconv_open’ 问题解决方法: https://bbs.xiuno.com/thread-15263.htm
安装成功后提示:
Installing shared extensions: /usr/local/php71/lib/php/extensions/no-debug-non-zts-20160303/
Installing PHP CLI binary: /usr/local/php71/bin/
Installing PHP CLI man page: /usr/local/php71/php/man/man1/
Installing PHP FPM binary: /usr/local/php71/sbin/
Installing PHP FPM config: /usr/local/php71/etc/
Installing PHP FPM man page: /usr/local/php71/php/man/man8/
Installing PHP FPM status page: /usr/local/php71/php/php/fpm/
Installing phpdbg binary: /usr/local/php71/bin/
Installing phpdbg man page: /usr/local/php71/php/man/man1/
Installing PHP CGI binary: /usr/local/php71/bin/
Installing PHP CGI man page: /usr/local/php71/php/man/man1/
Installing build environment: /usr/local/php71/lib/php/build/
Installing header files: /usr/local/php71/include/php/
Installing helper programs: /usr/local/php71/bin/
编辑php-fpm.conf
cd /usr/local/php71/etc
cp php-fpm.conf.default php-fpm.conf
vi php-fpm.conf
php-fpm.conf 配置文件内容:
[global]
pid = /usr/local/php71/var/run/php-fpm.pid
error_log = /usr/local/php71/var/log/php-fpm.log
log_level = notice
[www]
listen = /var/run/php71-cgi.sock
listen.backlog = 1024listen.allowed_clients = 127.0.0.1listen.owner = www
listen.group = www
listen.mode = 0666user = www
group = www
pm = dynamic
pm.max_children = 300pm.start_servers = 15pm.min_spare_servers = 5pm.max_spare_servers = 35pm.max_requests = 4096
安装php56
wget http://cn2.php.net/distributions/php-5.6.21.tar.xztar xf php-5.6.21.tar.xz
cd /usr/local/src/php-5.6.0/
./configure --prefix=/usr/local/php56 --with-config-file-path=/usr/local/php56/etc --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gd --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-pear --with-gettext --enable-session --with-mcrypt --with-curl
make && make install
php5.6 编译安装时碰到 undefined reference to `libiconv_open’ 问题解决方法: https://bbs.xiuno.com/thread-15263.htm
安装成功后提示:
Installing shared extensions: /usr/local/php56/lib/php/extensions/no-debug-no
Installing PHP CLI binary: /usr/local/php56/bin/
Installing PHP CLI man page: /usr/local/php56/php/man/man1/
Installing PHP FPM binary: /usr/local/php56/sbin/
Installing PHP FPM config: /usr/local/php56/etc/
Installing PHP FPM man page: /usr/local/php56/php/man/man8/
Installing PHP FPM status page: /usr/local/php56/php/php/fpm/
Installing PHP CGI binary: /usr/local/php56/bin/
Installing PHP CGI man page: /usr/local/php56/php/man/man1/
Installing build environment: /usr/local/php56/lib/php/build/
Installing header files: /usr/local/php56/include/php/
Installing helper programs: /usr/local/php56/bin/
编辑php-fpm.conf
cd /usr/local/php56/etc
cp php-fpm.conf.default php-fpm.conf
vi php-fpm.conf
php-fpm.conf 配置文件内容:
[global]
pid = /usr/local/php56/var/run/php-fpm.pid
error_log = /usr/local/php56/var/log/php-fpm.log
log_level = notice
[www]
listen = /var/run/php56-cgi.sock
listen.backlog = 1024listen.allowed_clients = 127.0.0.1listen.owner = www
listen.group = www
listen.mode = 0666user = www
group = www
pm = dynamic
pm.max_children = 300pm.start_servers = 15pm.min_spare_servers = 5pm.max_spare_servers = 35pm.max_requests = 4096
启动php56-fpm和php71-fpm
/usr/local/php56/sbin/php-fpm
/usr/local/php71/sbin/php-fpm
添加php-fpm系统服务
vi /etc/init.d/php56-fpm (php71类似)
set -e
PHPVERSION=php56
NAME=php56-fpm
DAEMON=/usr/local/$PHPVERSION/sbin/php-fpm
CONFIGFILE=/usr/local/$PHPVERSION/etc/php-fpm.conf
PIDFILE=/usr/local/$PHPVERSION/var/run/php-fpm.pid
SCRIPTNAME=/etc/init.d/$NAME
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0d_start() {
$DAEMON || echo -n " already running"}
d_stop() {
kill -INT `cat $PIDFILE` || echo -n " not running"}
d_reload() {
kill -USR2 `cat $PIDFILE` || echo -n " can't reload"}case "$1" in
start)
echo -n "Starting $NAME is success"
d_start
echo "."
;;
stop)
echo -n "Stopping $NAME is success"
d_stop
echo "."
;;
reload)
echo -n "Reloading $NAME configuration..."
d_reload
echo "reloaded."
;;
restart)
echo -n "Restarting $NAME is success"
d_stop
sleep 1
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
修改权限
chmod 755 /etc/init.d/php56-fpm
chmod 755 /etc/init.d/php71-fpm
php-fpm进程管理
启动服务:service php56-fpm start ; service php71-fpm start
停止服务:service php56-fpms stop ; service php71-fpm stop
重启服务:service php56-fpm reload ; service php71-fpm reload
加入开机启动
vi /etc/rc.local
service php56-fpm start
service php71-fpm start
安装扩展
安装扩展成功后,添加extension = xxx.so 到相应的php.ini 文件里
安装memcache
cd /usr/local/src #进入软件包存放目录
wget http://pecl.php.net/get/memcache-2.2.6.tgz #下载tar zxvf memcache-2.2.6.tgz #解压
cd memcache-2.2.6 #进入安装目录
/usr/local/php56/bin/phpize #用phpize生成configure配置文件
./configure --with-php-config=/usr/local/php56/bin/php-config
make && make install
安装mysql驱动 (如果编译安装php时没有with-mysql,就需要单独安装下扩展)
cd /usr/local/src/php-5.6.21/ext/mysql
/usr/local/php56/bin/phpize # 生成configure文件
./configure --with-php-config=/usr/local/php56/bin/php-config --with-mysqli=/usr/local/mysql/bin/mysql_config
make && make install
配置网站nginx.conf
使用php71的网站
fastcgi_pass unix:/var/run/php71-cgi.sock;
使用php56的网站
fastcgi_pass unix:/var/run/php56-cgi.sock;
配置cli中使用的php版本
ln -s /usr/local/php71/bin/php php
网友评论