常規的PHP配置方式有不少種,例如CGI、fast-cgi、apache module handle、cli、isapi這些。php
因爲各類配置方式的不一樣,會表現出各自不一樣的優劣。常常在web開發上用到的也就是FastCGI和Module handle這種模塊加載的方式,還有一些其餘的配置方式細節本文再也不說起,請在文末尋找相關文章進行查閱。html
爲須要實如今同一臺Linux服務器上面,同時運行多個不一樣版本的PHP程序,本文咱們將使用FastCGI方式加載,並把過程詳細記錄下來方便你們參考,另外關於Window上面配置一樣多版本的請參考以前發佈的文章 Apache多虛擬主機多版本PHP(5.2+5.3+5.4)共存運行配置全過程。mysql
Centos7.1(其餘版本大同小異)、mod_fcgid2.3.六、httpd-2.2.31c++
注:本文涉及的工具包軟件都會在文末提供。web
1.安裝編譯相關依賴sql
yum install httpd-devel apr apr-devel libtool
2.pr:apache
tar xf apr-1.5.2.tar.bz2 cd apr-1.5.2 ./configure --prefix=/usr/local/apr make && make install
3.apr-util:api
tar xf apr-util-1.5.4.tar.bz2 cd apr-util-1.5.4 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ --with-apr=/usr/local/apr/ make && make install
4.安裝pcre-develbash
yum -y install pcre-devel
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/ ——解決httpd編譯過程當中出現的錯誤,沒有安裝的須要預先安裝。服務器
5.安裝SSL
yum install openssl-devel yum update openssl
checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures ——解決httpd編譯過程當中出現的錯誤,沒有安裝的須要預先安裝。
./configure --prefix=/usr/local/apache \ --sysconfdir=/etc/httpd \ --enable-so \ --enable-ssl \ --enable-cgi \ --enable-rewrite \ --with-zlib \ --with-pcre \ --with-apr=/usr/local/apr \ --with-apr-util=/usr/local/apr-util \ --enable-modules=all \ --enable-mpms-shared=all \ --with-mpm=event make && make install
編譯安裝mod_fcgid.so-2.3.6
[root@localhost mod_fcgid-2.3.6]# APXS=/usr/local/apache/bin/apxs ./configure.apxs [root@localhost mod_fcgid-2.3.6]# make && make install
APXS="賦值的路徑爲你的httpd目錄下apxs文件位置"
編譯安裝完成以後會自動將其編入httpd目錄下的modules裏面
在這裏須要說明下,使用apxs -i -a -c mod_fcgid.so 去安裝的話會出現一些問題,致使httpd加載conf的時候終止進行。
使用mod_fcgid高於2.3.6版本以上,如2.3.9(官網提供的版本)經測試,在httpd2.4.2三、httpd2.2.31都會出現一個未定義符號錯誤,內容以下:
undefined symbol: set_access_info
另外錯誤說明:
[root@localhost mod_fcgid-2.3.6]# make && make install
Makefile:29: /rules.mk: No such file or directory
make: *** No rule to make target `/rules.mk'. Stop.
出現相似錯誤,最快捷的是刪除當前文件夾,從新解壓mod_fcgid或者httpd 後進行編譯。
1.配置主httpd.conf
vi /etc/httpd/httpd.conf #在DSO下增長如下內容 LoadModule fcgid_module modules/mod_fcgid.so #在文件尾部增長 Include "vhost/*.conf"
如:
# # Dynamic Shared Object (DSO) Support # # To be able to use the functionality of a module which was built as a DSO you # have to place corresponding `LoadModule' lines at this location so the # directives contained in it are actually available _before_ they are used. # Statically compiled modules (those listed by `httpd -l') do not need # to be loaded here. # # Example: # LoadModule foo_module modules/mod_foo.so # LoadModule fcgid_module modules/mod_fcgid.so AddHandler fcgid-script .fcgi .php #映射fcgi執行腳本 # 設置PHP_FCGI_MAX_REQUESTS大於或等於FcgidMaxRequestsPerProcess,防止php-cgi進程在處理完全部請求前退出 FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000 #php-cgi每一個進程的最大請求數 FcgidMaxRequestsPerProcess 1000 #php-cgi最大的進程數 FcgidMaxProcesses 3 #最大執行時間 FcgidIOTimeout 120 FcgidIdleTimeout 120 #限制最大請求字節 (單位b) FcgidMaxRequestLen 2097152 <IfModule !mpm_netware_module> <IfModule !mpm_winnt_module> ... 省略內容 .... NameVirtualHost *:80 Include "vhost/*.conf"
2.配置虛擬主機conf
建立虛擬主機配置目錄
mkdir /usr/local/apache/vhost/ vi /usr/local/apache/vhost/default.conf vi /usr/local/apache/vhost/php534.conf
~vhost/default.conf
<VirtualHost *:80> ServerName default DocumentRoot "/mnt/web/default/wwwroot" ServerAlias php5629.hk.explame.com ErrorLog "/mnt/web/default/log/error.log" CustomLog "/mnt/web/default/log/access.log" common FcgidInitialEnv PHPRC "/usr/local/php/php5.6.29/" FcgidWrapper "/usr/local/php/php5.6.29/bin/php-cgi" .php #採用fcgid將再也不支持 php_admin_value open_basedir .:/tmp/ 設置方式。 #設置目錄訪問權限,如出現上傳寫入問題,請設置php.ini中 upload_tmp_dir = /tmp/ </VirtualHost>
~vhost/php534.conf
<VirtualHost *:80> ServerName php534 DocumentRoot "/mnt/web/php534/wwwroot" ServerAlias php534.hk.explame.com ErrorLog "/mnt/web/php534/log/error.log" CustomLog "/mnt/web/php534/log/access.log" common FcgidInitialEnv PHPRC "/usr/local/php/php5.3.4/" FcgidWrapper "/usr/local/php/php5.3.4/bin/php-cgi" .php </VirtualHost>
1.準備依賴
# c和c++編譯器 yum install -y gcc gcc-c++ # PHP擴展依賴 yum install -y libxml2-devel openssl-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel openldap-devel
1.安裝PHP5.6.29
wget -O php-5.6.29.tar.bz2 http://cn2.php.net/get/php-5.6.29.tar.bz2/from/this/mirror tar -xvjf php-5.6.29.tar.bz2 cd php-5.6.29 ./configure --prefix=/usr/local/php/php5.6.29/\ --with-libdir=lib64\ --enable-fpm\ --with-fpm-user=php-fpm\ --with-fpm-group=www\ --enable-mysqlnd\ --with-mysql=mysqlnd\ --with-mysqli=mysqlnd\ --with-pdo-mysql=mysqlnd\ --enable-opcache\ --enable-pcntl\ --enable-mbstring\ --enable-soap\ --enable-zip\ --enable-calendar\ --enable-bcmath\ --enable-exif\ --enable-ftp\ --enable-intl\ --with-openssl\ --with-zlib\ --with-curl\ --with-gd\ --with-zlib-dir=/usr/lib\ --with-png-dir=/usr/lib\ --with-jpeg-dir=/usr/lib\ --with-gettext\ --with-mhash\ --with-ldap make && make install
2.安裝PHP5.3.3
wget http://museum.php.net/php5/php-5.3.4.tar.bz2 tar -xvjf php-5.3.4.tar.bz2 cd php-5.3.4 #php5.3 額外安裝 yum -y install libevent libevent-dev libevent-devel ./configure \ --prefix=/usr/local/php/php5.3.4/ \ --with-openssl \ --enable-mbstring \ --with-freetype-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib \ --with-libxml-dir \ --enable-xml make && make install
其餘版本配置及編譯方式類同,至少安裝完2個PHP版本進行配置多虛擬主機多PHP版本配置。
PHP低版本在安裝的過程當中會遇到不少問題,本文忽略掉一些常見的,請查閱網絡解決。
後續擴充5.3編譯參數
./configure \ --prefix=/usr/local/php/php5.3.28/ \ --with-freetype-dir \ --with-png-dir \ --with-libxml-dir \ --with-iconv=/usr/local\ --enable-xml \ --enable-mysqlnd\ --with-mysql=mysqlnd\ --with-mysqli=mysqlnd\ --with-pdo-mysql=mysqlnd\ --enable-pcntl\ --enable-mbstring\ --enable-soap\ --enable-zip\ --enable-calendar\ --enable-bcmath\ --enable-exif\ --enable-ftp\ --enable-intl\ --with-openssl\ --with-zlib\ --with-curl\ --with-gd\ --with-zlib-dir=/usr/lib\ --with-png-dir=/usr/lib\ --with-jpeg-dir=/usr/lib\ --with-gettext\ --with-mhash\ --with-ldap
編譯時遇到的錯誤解決方式:
undefined reference to symbol '__gxx_personality_v0@@CXXABI_1.3'
https://www.cnblogs.com/ttiandeng/p/7867226.html
加載默認的phpinfo,平均速度在1s左右。
輸出普通字符,平均速度在95ms左右。
加載默認的phpinfo,平均速度在500ms左右,相對5.6快了一倍。
輸出普通字符,平均速度在100ms左右。
PHP5.6在此過程當中加載了比PHP5.3更多的模塊,而在速度上面總體來講仍是提高了很多,實際項目測試,請自行研究。
經實測最終可用的版本爲
Centos7.1 + mod_fcgid-2.3.6 + httpd-2.2.31 + PHP*
本文爲實測內容,僅我的觀點,若有疑問,請在文末下方留言。謝謝!
PHP運行模式 http://blog.csdn.net/hguisu/article/details/7386882
Apache 鏡像站 http://mirrors.cnnic.cn/apache/httpd/
PHP歷史版本 http://php.net/releases/
mod_fcgid-2.3.6 ftp://ftp.ucsb.edu/pub/mirrors/apache/httpd/mod_fcgid/mod_fcgid-2.3.6.tar.bz2