一个Apache安装多个版本的PHP

我的服务器centos6.5安装了xampp,php6.5版本的。已经有好几个网站在上面运行了,但是后面要安装该死的ecshop,无奈要装php5.2,因此就想如何能在一个apache上安装多个版本的php,然后就找到这篇文章,并且在本地环境测试成功。中途编译Php5.2,安装mod_fcgid,碰到很多小问题,百度谷歌一下基本解决,但是编译Php5.2启用openssl的话有问题没解决,就直接去掉openssl的选项了。

转载自:http://linuxplayer.org/2011/05/intall-multiple-version-of-php-on-one-server

This article is about how to install php-5.1, php-5.2 and php-5.3 on one server, and use them simultaneously

Based on CentOS 5.6, for Apache only

1. Enable rpmforge and epel yum repository

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
wget http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
sudo rpm -ivh rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
sudo rpm -ivh epel-release-5-4.noarch.rpm

2. Install php-5.1

CentOS/RHEL 5.x series have php-5.1 in box, simply install it with yum, eg:

sudo yum install php php-mysql php-mbstring php-mcrypt

Compile and install php 5.2 and 5.3 from source

For php 5.2 and 5.3, we can find many rpm packages on the Internet. However, they all conflict with the php which comes with CentOS, so, we’d better build and install them from soure, this is not difficult, the point is to install php at different location.

However, when install php as an apache module, we can only use one version of php at the same time. If we need to run different version of php on the same server, at the same time, for example, different virtual host may need different version of php. Fortunately, the coolFastCGI andPHP-FPM can help.

Build and install php-5.2 with fastcgi enabled

1) Install required dev packages

yum install gcc libxml2-devel bzip2-devel zlib-devel 	curl-devel libmcrypt-devel libjpeg-devel 	libpng-devel gd-devel mysql-devel

2) Compile and install

wget http://cn.php.net/get/php-5.2.17.tar.bz2/from/this/mirror
tar -xjf php-5.2.17.tar.bz2
cd php-5.2.17
./configure --prefix=/usr/local/php52 	--with-config-file-path=/etc/php52 	--with-config-file-scan-dir=/etc/php52/php.d 	--with-libdir=lib64 	--with-mysql 	--with-mysqli 	--enable-fastcgi 	--enable-force-cgi-redirect 	--enable-mbstring 	--disable-debug 	--disable-rpath 	--with-bz2 	--with-curl 	--with-gettext 	--with-iconv 	--with-openssl 	--with-gd 	--with-mcrypt 	--with-pcre-regex 	--with-zlib
make -j4 > /dev/null
sudo make install
sudo mkdir /etc/php52
sudo cp php.ini-recommended /etc/php52/php.ini

3) create a fastcgi wrapper script
create file /usr/local/php52/bin/fcgiwrapper.sh

#!/bin/bash
PHP_FCGI_MAX_REQUESTS=10000
export PHP_FCGI_MAX_REQUESTS
exec /usr/local/php52/bin/php-cgi
chmod a+x /usr/local/php52/bin/fcgiwrapper.sh

Build and install php-5.3 with fpm enabled

wget http://cn.php.net/get/php-5.3.6.tar.bz2/from/this/mirror
tar -xjf php-5.3.6.tar.bz2
cd php-5.3.6
./configure --prefix=/usr/local/php53 	--with-config-file-path=/etc/php53 	--with-config-file-scan-dir=/etc/php53/php.d 	--enable-fpm 	--with-fpm-user=apache 	--with-fpm-group=apache 	--with-libdir=lib64 	--with-mysql 	--with-mysqli 	--enable-mbstring 	--disable-debug 	--disable-rpath 	--with-bz2 	--with-curl 	--with-gettext 	--with-iconv 	--with-openssl 	--with-gd 	--with-mcrypt 	--with-pcre-regex 	--with-zlib 

make -j4 && sudo make install
sudo mkdir /etc/php53
sudo cp php.ini-production /etc/php53/php.ini

sed -i -e ‘s#php_fpm_CONF=\${prefix}/etc/php-fpm.conf#php_fpm_CONF=/etc/php53/php-fpm.conf#‘ 	sapi/fpm/init.d.php-fpm
sudo cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
sudo chmod a+x /etc/init.d/php-fpm
sudo /sbin/chkconfig --add php-fpm
sudo /sbin/chkconfig php-fpm on

sudo cp sapi/fpm/php-fpm.conf /etc/php53/

Configue php-fpm
Edit /etc/php53/php-fpm.conf, change some settings. This step is mainly to uncomment some settings, you can adjust the value if you like.

pid = run/php-fpm.pid
listen = 127.0.0.1:9000
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20

Then, start fpm

sudo /etc/init.d/php-fpm start

Install and setup mod_fastcgi, mod_fcgid

sudo yum install libtool httpd-devel apr-devel
wget http://www.fastcgi.com/dist/mod_fastcgi-current.tar.gz
tar -xzf mod_fastcgi-current.tar.gz
cd mod_fastcgi-2.4.6
cp Makefile.AP2 Makefile
sudo make top_dir=/usr/lib64/httpd/ install
sudo sh -c "echo ‘LoadModule fastcgi_module modules/mod_fastcgi.so‘ > /etc/httpd/conf.d/mod_fastcgi.conf"
yum install mod_fcgid

Setup and test virtual hosts

1) Add the following line to /etc/hosts

127.0.0.1 web1.example.com web2.example.com web3.example.com

2) Create web document root and drop an index.php under it to show phpinfo
switch to user root, run

mkdir /var/www/fcgi-bin
for i in {1..3}; do
	web_root=/var/www/web$i
	mkdir $web_root
	echo "" > $web_root/index.php
done

Note: The empty /var/www/fcgi-bin directory is required, DO NOT REMOVE IT LATER

3) Create Apache config file(append to httpd.conf)

NameVirtualHost *:80

# module settings
# mod_fcgid
<IfModule mod_fcgid.c>
        idletimeout 3600
        processlifetime 7200
        maxprocesscount 17
        maxrequestsperprocess 16
        ipcconnecttimeout 60
        ipccommtimeout 90
</IfModule>
# mod_fastcgi with php-fpm
<IfModule mod_fastcgi.c>
        FastCgiExternalServer /var/www/fcgi-bin/php-fpm -host 127.0.0.1:9000
</IfModule>

# virtual hosts...

#################################################################
#1st virtual host, use mod_php, run php-5.1
#################################################################
<VirtualHost *:80>
        ServerName web1.example.com
        DocumentRoot "/var/www/web1"

        <ifmodule mod_php5.c>
                <FilesMatch \.php$>
                        AddHandler php5-script .php
                </FilesMatch>
        </IfModule>

        <Directory "/var/www/web1">
                DirectoryIndex index.php index.html index.htm
                Options -Indexes FollowSymLinks
                Order allow,deny
                Allow from all
        </Directory>

</VirtualHost>
#################################################################
#2nd virtual host, use mod_fcgid, run php-5.2
#################################################################
<VirtualHost *:80>
        ServerName web2.example.com
        DocumentRoot "/var/www/web2"

        <IfModule mod_fcgid.c>
                AddHandler fcgid-script .php
                FCGIWrapper /usr/local/php52/bin/fcgiwrapper.sh
        </IfModule>

        <Directory "/var/www/web2">
                DirectoryIndex index.php index.html index.htm
                Options -Indexes FollowSymLinks +ExecCGI
                Order allow,deny
                Allow from all
        </Directory>

</VirtualHost>
#################################################################
#3rd virtual host, use mod_fastcgi + php-fpm, run php-5.3
#################################################################
<VirtualHost *:80>
        ServerName web3.example.com
        DocumentRoot "/var/www/web3"

        <IfModule mod_fastcgi.c>
                ScriptAlias /fcgi-bin/ /var/www/fcgi-bin/
                AddHandler php5-fastcgi .php
                Action php5-fastcgi /fcgi-bin/php-fpm
        </IfModule>

        <Directory "/var/www/web3">
                DirectoryIndex index.php index.html index.htm
                Options -Indexes FollowSymLinks +ExecCGI
                Order allow,deny
                Allow from all
        </Directory>

</VirtualHost>

4) restart apache. visit the 3 sites respectly to view phpinfo
and validate the result. ie:
http://web1.example.com
http://web2.example.com
http://web3.example.com
If all OK, you can use one of the 3 virtual host as template to create new virtual host, with the desired php version.

References:

  

 

时间: 2024-10-31 14:08:40

一个Apache安装多个版本的PHP的相关文章

linux apache 2.4.20版本安装

centos  6.7_64位                apache 2.4.20版本 yum install   gcc     gcc-c++   make    uuid-devel    libuuid-devel    unzip    -y apr中包含了一些通用的开发组件,包括mmap,DSO等等 apr-util该目录中也是包含了一些常用的开发组件.这些组件与apr目录下的相比,它们与apache的关系更加密切一些.比如存储段和存储段组,加密等等. apr-iconv包中的

apache+php+mysql最新版本安装

上一随笔简单介绍了通过安装AppServ一次性简洁安装apache,php,mysql的方法,但是安装的弊端就是虽然简单,但是不能单独进行软件的更新,导致不够方便,所以,现在我重新尝试单个软件安装,并配置. 1.首先还是推荐网上的非常好的一篇文章,相关链接如下:http://blog.csdn.net/lyrebing/article/details/8587054.如果你英文还可以的话,可以根据这篇文章的介绍,轻松的完成相关软件的下载.安装.配置.2.如果你英文不够好,那么我再用汉语简单描述一

Ubuntu+apache安装redmin

0 切换到root sudo su 1 依赖包 sudo apt-get install mysql-server libmysqlclient-dev git-core subversion imagemagick libmagickwand-dev libcurl4-openssl-dev sudo apt-get install apache2 libapache2-mod-passenger sudo apt-get install mysql-server mysql-client 2

apache安装(适用于初学者)

应用系统是centos 6.x  httpd 2.2 (apache2.4版本对apr版本要求在1.4以上, [[email protected] httpd-2.2.31]# rpm -q apr apr-1.3.9-5.el6_2.x86_64 yum安装的是1.3.9版主,安装2.4版本需要源码包安装apr) 为了不影响实验效果,提前可以把selinux 和iptables 关闭 [[email protected] ~]# chkconfig iptables off [[email p

在centos7上安装openstack mitaka版本

前言:openstack真是一个庞然大物,想要吃透还真不容易,所以在对openstack大概有了一个了解的时候,就应该是部署,虽然openstack的安装方式有rdo或者devstack等一键安装工具,但是最好浅尝辄止,有了大概的使用经验之后就应该是从头到尾的安装一遍了,不然对于那些报错,以及故障的解决一定是不够气定神闲的,因此,当你有了openstack的基本认识后,开始安装吧~ 注:openstack的官方文档写得真的是,好的不要不要的,但是看英文总是感觉有点不溜,因此在官方文档的基础上写得

Apache、Web软件、Apache安装、常用配置项、区域配置、日志分析

Apache 安装 具体步骤: 1.准备工作 为了避免发生端口冲突.程序冲突等现象,建议将使用rpm方式安装的httpd及相关依赖包(如果有的话)卸载.如图所示: 2.源码编译及安装 插入安装光盘并挂载,进入到光盘目录中,将httpd源码包释放到/usr/src/目录下,并且切换到展开后的源码目录中. 根据服务器的实际应用需要,可以灵活设置不同的定制选项. 上述配置命令中,各选项的含义如下: --prefix:指定将httpd服务程序安装到哪个目录. --enable-so:启用动态加载模块支持

apache 安装及配置

近期想用apache运行网站,在网上查询windows 版本的中文说明文档有特别少,所以将学习到的在这里做个笔记,以便日后学习以及大家相互交流. 相关文档:http://httpd.apache.org/docs/2.4/ 指令:http://httpd.apache.org/docs/2.4/mod/core.html 首先在官网下载apache :http://www.apachelounge.com/download/,其中有两个版本,根据你的版本来下载相应的版本,然后解压放在你的安装目录

Apache和Tomcat整合(一个Apache 不同域名处理多个不同业务)

一.简介 在项目中,几乎任何一个项目都包括静态资源和动态请求两大部分.特别对于门户网站这样的项目,静态内容资源会更多,我们使用一般的 Tomcat 部署时,Tomcat 对静态资源的处理能力比较慢,至少比 Apache 要慢很多. 为了提高项目的访问速度,降低服务器负载提高性能,我们使用Apache来处理静态资源,把动态资源和请求交给 Tomcat 处理. 当然,在单纯处理并发和静态资源指标方面,Nginx要比Apache好,至于Nginx和Apache的具体区别,以及什么项目使用Nginx.什

Apache搭建http协议版本库

1.Apache安装程序 软件包:apache_2.2.14-win32-x86-no_ssl.msi 路径:\\10.202.101.23\10.Utility\01.Development\01.Development\CI\Apache\apache_2.2.14-win32-x86-no_ssl.msi2.Subversion安装程序 软件包:Setup-Subversion-1.6.9.msi 路径:\\10.202.101.23\10.Utility\01.Development\0