One Apache installs multiple versions of PHP

Source: Internet
Author: User
Tags gettext install php mcrypt phpinfo sapi

My server centos6.5 has the xampp,php6.5 version installed. There have been several sites running on it, but to install the damned ecshop, but php5.2, so I want to install multiple versions of PHP on an Apache, and then find this article, and in the local environment test success. Halfway compile Php5.2, install Mod_fcgid, encountered a lot of small problems, Baidu Google a basic solution, but compiled Php5.2 enable OpenSSL if there is a problem not resolved, directly remove the option of OpenSSL.

Reprinted from: Http://linuxplayer.org/2011/05/intall-multiple-version-of-php-on-one-server

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

Based on the 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 has php-5.1 in box, simply install it with yum, eg:

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 I s not difficult, and the point was to install PHP at different.

However, when install PHP as a Apache module, we can only use one version of PHP at the same time. If we need to run different version of PHP in the same server, at the same time, for example, different virtual host may n Eed different version of PHP. Fortunately, the coolfastcgi and PHP-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/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-rec Ommended/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 was mainly to uncomment some settings, and 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}; Doweb_root=/var/www/web$imkdir $web _rootecho "" > $web _root/index.phpdone

Note:the Empty/var/www/fcgi-bin Directory is required, does 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 Processlifetim E 7200 maxprocesscount maxrequestsperprocess ipcconnecttimeout ipccommtimeout 90< /ifmodule># mod_fastcgi with Php-fpm<ifmodule mod_fastcgi.c> fastcgiexternalserver/var/www/fcgi-bin/php-f Pm-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_p hp5.c> <filesmatch \.php$> AddHandler php5-script. PHP </ filesmatch> </IfModule> <directory "/var/www/web1" > DirectoryIndex index.php I ndex.html index.htm OptIons-indexes followsymlinks Order Allow,deny allow from all </directory></v irtualhost>################################################################# #2nd Virtual Host, use Mod_fcgid, Run Php-5.2#################################################################<virtualhost *:80> ServerName we b2.example.com documentroot "/var/www/web2" <ifmodule mod_fcgid.c> AddHandler FCGID-SCR IPT. PHP fcgiwrapper/usr/local/php52/bin/fcgiwrapper.sh </IfModule> <directory "/va R/www/web2 "> DirectoryIndex index.php index.html index.htm options-indexes followsymlink S +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:

      • mod_fastcgi Document
      • Mod_fcgid Document
      • PHP-FPM Wiki

  

 

One Apache installs multiple versions of PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.