Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing PHP 5.3.29 from Sources on Ubuntu 14 with Apache 2 Module

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/distributions/php-5.3.29.tar.bz2
tar -xvf php-5.3.29.tar.bz2
cd php-5.3.29
./configure
make
make install

However, PHP and Apache do not seem to have any linkage. That means I have installed both Apache and PHP, but Apache does not run PHP.

What I have tried:

From this site: https://docs.moodle.org/28/en/Compiling_PHP_from_source
"Configuring Apache and PHP", it asked me to add this in the Apache configuration file:

LoadModule php5_module modules/libphp5.so

However, I do not have "libphp5.so" module.

Some people asked me to run this:

sudo apt-get install libapache2-mod-php5

But after running the command, it installed PHP 5.5.9 for me, but I need PHP 5.3.29.

How can I make Apache run PHP 5.3.29 which I have installed?

like image 433
dondonhk Avatar asked Mar 03 '15 02:03

dondonhk


People also ask

Do I need to install PHP after Apache?

The PHP module for Apache is not bundled with Apache. As such, it must be installed in addition to the Apache package. Once installed the module will have to be enabled. We accomplish this using the a2enmod command.

What is Apache PHP module?

mod_php means PHP, as an Apache module. Basically, when loading mod_php as an Apache module, it allows Apache to interpret PHP files (those are interpreted by mod_php ).


1 Answers

This works for me:

sudo -s

Download source

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

Install all necessary dependencies

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

Compile PHP

./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

Activate Apache module

a2enmod cgi fastcgi actions
service apache2 restart

Create corresponding configuration file

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

like image 179
wittich Avatar answered Oct 05 '22 06:10

wittich