博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
一个Apache安装多个版本的PHP
阅读量:5051 次
发布时间:2019-06-12

本文共 7368 字,大约阅读时间需要 24 分钟。

我的服务器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.rpmwget http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpmsudo rpm -ivh rpmforge-release-0.5.2-2.el5.rf.x86_64.rpmsudo 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 cool and 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/mirrortar -xjf php-5.2.17.tar.bz2cd 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-zlibmake -j4 > /dev/nullsudo make installsudo mkdir /etc/php52sudo cp php.ini-recommended /etc/php52/php.ini

3) create a fastcgi wrapper script

create file /usr/local/php52/bin/fcgiwrapper.sh

#!/bin/bashPHP_FCGI_MAX_REQUESTS=10000export PHP_FCGI_MAX_REQUESTSexec /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/mirrortar -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 installsudo mkdir /etc/php53sudo cp php.ini-production /etc/php53/php.inised -i -e 's#php_fpm_CONF=\${prefix}/etc/php-fpm.conf#php_fpm_CONF=/etc/php53/php-fpm.conf#' \	sapi/fpm/init.d.php-fpmsudo cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmsudo chmod a+x /etc/init.d/php-fpmsudo /sbin/chkconfig --add php-fpmsudo /sbin/chkconfig php-fpm onsudo 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.pidlisten = 127.0.0.1:9000pm.start_servers = 10pm.min_spare_servers = 5pm.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-develwget http://www.fastcgi.com/dist/mod_fastcgi-current.tar.gztar -xzf mod_fastcgi-current.tar.gzcd mod_fastcgi-2.4.6cp Makefile.AP2 Makefilesudo make top_dir=/usr/lib64/httpd/ installsudo 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-binfor i in {1..3}; do	web_root=/var/www/web$i	mkdir $web_root	echo "" > $web_root/index.phpdone

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
idletimeout 3600 processlifetime 7200 maxprocesscount 17 maxrequestsperprocess 16 ipcconnecttimeout 60 ipccommtimeout 90
# mod_fastcgi with php-fpm
FastCgiExternalServer /var/www/fcgi-bin/php-fpm -host 127.0.0.1:9000
# virtual hosts...##################################################################1st virtual host, use mod_php, run php-5.1#################################################################
ServerName web1.example.com DocumentRoot "/var/www/web1"
AddHandler php5-script .php
DirectoryIndex index.php index.html index.htm Options -Indexes FollowSymLinks Order allow,deny Allow from all
##################################################################2nd virtual host, use mod_fcgid, run php-5.2#################################################################
ServerName web2.example.com DocumentRoot "/var/www/web2"
AddHandler fcgid-script .php FCGIWrapper /usr/local/php52/bin/fcgiwrapper.sh
DirectoryIndex index.php index.html index.htm Options -Indexes FollowSymLinks +ExecCGI Order allow,deny Allow from all
##################################################################3rd virtual host, use mod_fastcgi + php-fpm, run php-5.3#################################################################
ServerName web3.example.com DocumentRoot "/var/www/web3"
ScriptAlias /fcgi-bin/ /var/www/fcgi-bin/ AddHandler php5-fastcgi .php Action php5-fastcgi /fcgi-bin/php-fpm
DirectoryIndex index.php index.html index.htm Options -Indexes FollowSymLinks +ExecCGI Order allow,deny Allow from all

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:

  

 

转载于:https://www.cnblogs.com/bushe/p/5142380.html

你可能感兴趣的文章
CentOS笔记-用户和用户组管理
查看>>
Mongodb 基本命令
查看>>
Qt中QTableView中加入Check列实现
查看>>
“富豪相亲大会”究竟迷失了什么?
查看>>
控制文件的备份与恢复
查看>>
返回代码hdu 2054 A==B?
查看>>
Flink独立集群1
查看>>
iOS 8 地图
查看>>
20165235 第八周课下补做
查看>>
[leetcode] 1. Two Sum
查看>>
iOS 日常工作之常用宏定义大全
查看>>
PHP的SQL注入技术实现以及预防措施
查看>>
MVC Razor
查看>>
软件目录结构规范
查看>>
Windbg调试Sql Server 进程
查看>>
linux调度器系列
查看>>
mysqladmin
查看>>
解决 No Entity Framework provider found for the ADO.NET provider
查看>>
SVN服务器搭建和使用(三)(转载)
查看>>
Android 自定义View (三) 圆环交替 等待效果
查看>>