Linux下部署php多版本共存
背景說明
自php7問世,身為最新版本控的我馬上升級體驗,但是由於伺服器上還有舊程序在運行,只好部署一個php多版本共存環境。
現有環境是lnmp
- CentOS 6.7
- nginx 1.10.1
- mariadb-10.0.26
- php 7.0.8
為了更好兼容舊的php程序,推薦使用5.4.45. 主要是兼容mysql擴展。
開始安裝
首先要下載php-5.4.45.tar.gz源碼包。
通過源碼安裝
# tar xzvf php-5.4.45.tar.gz
# cd php-5.4.45
# ./configure --prefix=/usr/local/php54 --with-config-file-path=/usr/local/php54/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-intl --with-xsl
# make ZEND_EXTRA_LIBS='-liconv'
# make install
# cp php.ini-proction /usr/local/php/etc/php.ini
------------------------------------------------------------------------------------------------
php.ini 配置
post_max_size = 50M
upload_max_filesize = 50M
date.timezone = PRC
short_open_tag = On
cgi.fix_pathinfo=0
max_execution_time = 300
disable_functions=passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server
------------------------------------------------------------------------------------------------
php-fpm.conf 配置
------------------------------
# vim /usr/local/php/etc/php-fpm.conf1
[global]
pid = /usr/local/php54/var/run/php-fpm.pid
error_log = /usr/local/php54/var/log/php-fpm.log
log_level = notice
[www]
listen = /tmp/php54-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1:9001
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 40
pm.start_servers = 20
pm.min_spare_servers = 20
pm.max_spare_servers = 40
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = var/log/slow.log
----------------------------------------------------------------------------------
啟動 php-fpm
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php54-fpm
# chmod +x /etc/init.d/php54-fpm
# /etc/init.d/php54-fpm start
-------------------------------------------------------------------------------------------
修改nginx配置,對需要的服務配置使用php-5.4.45
location ~ [^/]\.php(/|$)
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php54-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
----------------------------------------------------------------------------------------
配置php-5.4.45 的php54-fpm 開機自動啟動
# chkconfig --add php54-fpm
# chkconfig php54-fpm on
B. linux中 php怎樣開啟pdo擴展
pdo擴展模是有蠻多了,如pdo_mysql也是pdo模塊中的一個了,下文我們就以安裝pdo_mysql為示例幫助大家介紹一下安裝步驟吧,其它的pdo擴展模塊安裝步驟也可以一樣。
假設php目錄為/usr/local/php
mysql目錄為/usr/local/mysql
1. 進入PHP源碼包ext/pdo目錄(http://hounwang.com/lesson.html)
cd ext/pdo
2. 執行/usr/local/php/bin/phpize[假設PHP的安裝目錄為/usr/local/php]
/usr/local/php/bin/phpize
3. 配置擴展pdo
./configure --with-php-config=/usr/local/php/bin/php-config --enable-pdo=shared
4. 編譯 && 安裝pdo
make && make install
成功則出現
Installing shared extensions: /usr/local/php//lib/php/extensions/no-debug-non-zts-20060613/
Installing header files: /usr/local/php//include/php/
Installing PDO headers: /usr/local/php//include/php/ext/pdo/
說明在/usr/local/php//lib/php/extensions/no-debug-non-zts-20060613/目錄下生成了pdo.so文件
5. 在PHP源碼包中進入pdo_mysql
cd ext/pdo_mysql
6. /usr/local/php/bin/phpize
/usr/local/php/bin/phpize
7. 配置pdo_mysql[假設Mysql的安裝目錄為/usr/local/mysql]
1./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
8. 編譯 安裝pdo_mysql
make && make install
成功則出現
Installing shared extensions: /usr/local/php//lib/php/extensions/no-debug-non-zts-20060613/
說明的/usr/local/php//lib/php/extensions/no-debug-non-zts-20060613/目錄下生成了pdo_mysql.so文件
9. 在php配置文件中加上
extension="/usr/local/php//lib/php/extensions/no-debug-non-zts-20060613/pdo_mysql.so";
extension="/usr/local/php//lib/php/extensions/no-debug-non-zts-20060613/pdo.so";
10. 重啟相關服務
/etc/init.d/php-fpm restart
更多問題到問題求助專區http://bbs.hounwang.com/
C. linux下的php到底是怎麼載入mysqli模塊的
添加擴展的基本步驟:
1、進入PHP源代碼目錄:# cd /tmp/php-5.2.14/
2、再進入要添加的mysqli擴展源碼目錄:# cd ext/mysqli/
2、調用已經編譯好的php裡面的phpize:# /usr/local/php/bin/phpize
3、然後configure:# ./configure --with-php-config=/usr/local/php/bin/php-config --with-mysqli=/usr/local/MySQL/bin/mysql_config
(/usr/local/mysql 為mysql的安裝目錄)
4、make && make install
5、編譯之後,自動把mysqli.so放到了默認的php擴展目錄下,我的為 /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
(phpinfo可查看或者執行命令/usr/local/php/bin/php-config --extension-dir )
再修改php.ini 找到extension_dir 默認路徑為 extension_dir="./" 我修改後才啟動載入的
在下面添加extension = "mysqli.so" 保存即可
extension_dir="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
extension = "mysqli.so"
6、重啟apache:# service httpd restart