Apache多虚拟主机多版本PHP(5.3+5.6+N)共存运行配置全过程

摘要: 为须要实如今同一台Linux服务器上面,同时运行多个不一样版本的PHP程序,本文咱们将使用FastCGI方式加载,并把过程详细记录下来方便你们参考。

常规的PHP配置方式有不少种,例如CGI、fast-cgi、apache module handle、cli、isapi这些。php

  • CGI (通用网关接口 / Common Gateway Interface)
  • Fast CGI (常驻型CGI / Long-Live CGI)
  • CLI (命令行运行 / Command Line Interface)
  • Module handle (Apache等Web服务器运行的模式,php5_module)
  • ISAPI (专门用于IIS 上面加载PHP dll的一种方式 Internet Server Application Program Interface)

因为各类配置方式的不一样,会表现出各自不一样的优劣。常常在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.31nginx

注:本文涉及的工具包软件都会在文末提供。c++

安装服务基础组件

1.安装编译相关依赖web

yum install httpd-devel apr apr-devel libtool

2.pr:sql

tar xf apr-1.5.2.tar.bz2
cd apr-1.5.2 ./configure --prefix=/usr/local/apr make && make install

3.apr-util:apache

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-develapi

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编译过程当中出现的错误,没有安装的须要预先安装。ruby

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编译过程当中出现的错误,没有安装的须要预先安装。

编译安装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>

 

编译安装PHP

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

 

测试结果

php5.6.29

加载默认的phpinfo,平均速度在1s左右。

输出普通字符,平均速度在95ms左右。

php5.3.4

加载默认的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

https://my.oschina.net/u/2366984/blog/809833

相关文章
相关标签/搜索