I successfully installed PHP 5.3.29 on Ubuntu 14 with Apache 2 separately.
I installed PHP with the following method:
sudo -i
wget http://in1.php.net
Wittich's answer is fabulous! I used it in order to replace php 5.1 with php 5.6 on my unix website. Unlike Wittich, I wasn't trying to get two versions running simultaneously; I was simply trying to do an upgrade from an older version of php that was integrated with apache to a newer version that would run from cgi.
For some reason, several of Wittich's commands (such as the SetHandler command) prevented Apache from loading after I tried them. I ended up having to simplify his answer so that Apache would run correctly. I made 6 changes in Wittich's procedures:
I used yum instead of apt-get because apt-get wouldn't run on my Unix system.
Since I was installing php 5.6 not php 5.3, I changed all instances of "php53" to "php56" in the configure command's switches. This was not necessary for everything to work, but it will help you understand my paths below:
In one of my httpd configuration folders (/etc/httpd/conf.d), I found a file that was already set up for a cgi implementation of php (php_cgi.conf). Its contents were:
scriptAlias /phppath/ "/var/www/cgi-bin/cgi_wrapper/"
Action php-script /phppath/cgi_wrapper
The contents and existence of this file let me skip or change several of Wittich's steps. I neither created php53-cgi, nor did I create php53.conf.
\#!/bin/sh
exec /usr/bin/php56/php-cgi
AddHandler php-script .php
So, in summary, it is easy to convert Wittich's answer into a way to upgrade from an older apache based php version to a newer cgi-based version if you have an existing php_cgi.conf file that you can hijack and use as a guide.
I found a posting by David Brogdon to be a good complement to Wittich's answer for those who are new to the configure, make, and make install commands:
http://www.onlamp.com/pub/a/php/2000/11/17/php_admin.html
I searched the Internet for hours and never found anything as helpful as Brogdon's post and Wittich's answer. Wittich's answer must have worked perfectly on his Unix system, but I had to modify it a bit in order to get it to work on mine.
I do this:
# wget wget http://in1.php.net/distributions/php-5.3.29.tar.bz2
# tar -xvf php-5.3.29.tar.bz2
# cd php-5.3.29
# ./configure --with-apxs2=/usr/local/apache2/bin/apxs
# make
# sudo make install
# sudo cp php.ini-development /usr/local/lib/php.ini.
Then change php.ini. Change the option,
short_open_tag = Off
to
short_open_tag = On
Check and modify the httpd.conf module php5
:
LoadModule php5_module modules/libphp5.so
Add in httpd.conf:
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Restart apache2
, default install in: /usr/local/apache2
# sudo /usr/local/apache2/bin/apachectl start
Check phpinfo is now read in your Apache installation like:
http://localhost
This works for me:
sudo -s
mkdir /usr/local/src/php5-build
cd /usr/local/src/php5-build
wget -O php-5.3.29.tar.gz http://de1.php.net/get/php-5.3.29.tar.gz/from/this/mirror
tar -xzf php-5.3.29.tar.gz
cd php-5.3.29
apt-get install apache2 php5 php5-common php5-cli php5-mysql php5-gd php5-mcrypt php5-curl libapache2-mod-php5 php5-xmlrpc mysql-server mysql-client libapache2-mod-fastcgi
apt-get install build-essential php5-dev libbz2-dev libmysqlclient-dev libxpm-dev libmcrypt-dev libcurl4-gnutls-dev libxml2-dev libjpeg-dev libpng12-dev
./configure --prefix=/usr/share/php53 --datadir=/usr/share/php53 --mandir=/usr/share/man --bindir=/usr/bin/php53 --includedir=/usr/include/php53 --sysconfdir=/etc/php53/apache2 --with-config-file-path=/etc/php53/apache2 --with-config-file-scan-dir=/etc/php53/conf.d --enable-bcmath --with-curl=shared,/usr --with-mcrypt=shared,/usr --enable-cli --with-gd --with-mysql --with-mysqli --enable-libxml --enable-session --enable-xml --enable-simplexml --enable-filter --enable-inline-optimization --with-jpeg-dir --with-png-dir --with-zlib --with-bz2 --with-curl --enable-exif --enable-soap --with-pic --disable-rpath --disable-static --enable-shared --with-gnu-ld --enable-mbstring
make && make install
a2enmod cgi fastcgi actions
service apache2 restart
vi /etc/apache2/php53.conf
Insert:
#Include file for virtual hosts that need to run PHP 5.3
SetHandler application/x-httpd-php5
ScriptAlias /php53-cgi /usr/lib/cgi-bin/php53-cgi
Action application/x-httpd-php5 /php53-cgi
AddHandler application/x-httpd-php5 .php
Create environment script to start the additional PHP version
vi /usr/lib/cgi-bin/php53-cgi
Insert:
#!/bin/sh
PHPRC="/etc/php53/apache2/"
export PHPRC
PHP_FCGI_CHILDREN=4
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_MAX_REQUESTS
exec /usr/bin/php53/php-cgi
Configure Apache 2's virtual hosts
Include php53.conf
ServerName example.org
DocumentRoot /var/www/sites/example.org
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Require all granted
Last, restart...
service apache2 restart
Source: https://erdfisch.de/en/multiple-versions-php-apache-under-linux
This works for me on a scratch Ubuntu 14.04:
Update the systems packages
apt-get update
apt-get upgrade -y
Install the dependencies and prepare environment
apt-get install -y build-essential libxml2-dev apache2 apache2-dev
echo "export PATH=/usr/local/bin:/usr/local/sbin:$PATH" >> ~/.bashrc
apt-get install -y libapache2-mod-php5 --no-install-recommends
Download PHP 5.3.29
apt-get install -y wget && cd /tmp && wget http://php.net/distributions/php-5.3.29.tar.bz2
Unzip and configure apache's module apxs2
tar -xvf php-5.3.29.tar.bz2 && cd php-5.3.29 && ./configure --with-apxs2=/usr/bin/apxs2
Install it
make && make install
Check if works
service apache2 restart && php -v