Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ubuntu14.04.5; Apache2.4; Multi PHP Version

Ubuntu14.04.5, Install Apache2.4 with Multi PHP Version.

Install Apache 2.4.7

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install build-essential
$ sudo apt-get install apache2

Install FastCGI

$ sudo apt install \
libapache2-mod-fastcgi \
apache2-mpm-worker \
apache2-suexec 
$ sudo a2enmod actions fastcgi suexec
$ sudo mkdir /var/lib/apache2/fastcgi

Install PHP 5.5.9-1ubuntu4.20

$ sudo apt install php5 \
libapache2-mod-php5 \
php5-common \
php5-dev \
php5-curl \
php5-mcrypt
php5-cgi \
php5-cli \
php5-gd \
php5-mysql \
php5-json

Install PHP 5.3.29

$ sudo apt install git \
pkg-config \
wget \
vim
$ cd /opt
$ sudo git clone git://git.code.sf.net/p/phpfarm/code phpfarm

$ sudo vim /opt/phpfarm/src/options.sh

#!/bin/bash
# You can override config options very easily.
# Just create a custom options file; it may be version specific:
# - custom-options.sh
# - custom-options-5.sh
# - custom-options-5.3.sh
# - custom-options-5.3.1.sh
#
# Don't touch this file here - it would prevent you to just "svn up"
# your phpfarm source code.

version=$1
vmajor=$2
vminor=$3
vpatch=$4

#gcov='--enable-gcov'
configoptions="\
--enable-bcmath \
--enable-gd-native-ttf \
--enable-calendar \
--enable-exif \
--enable-ftp \
--enable-mbstring \
--enable-pcntl \
--enable-soap \
--enable-sockets \
--enable-sqlite-utf8 \
--enable-wddx \
--enable-zip \
--enable-cgi \
--with-mysqli \
--with-mysql \
--with-curl \
--with-png \
--with-gd \
--with-pdo-mysql \
--with-openssl \
--with-zlib \
--with-gettext \
--with-mcrypt \
--with-libdir=/usr/lib/x86_64-linux-gnu \
--with-jpeg-dir=/usr/lib/x86_64-linux-gnu \
$gcov"

echo $version $vmajor $vminor $vpatch

custom="custom-options.sh"
[ -f $custom ] && source "$custom" $version $vmajor $vminor $vpatch
custom="custom-options-$vmajor.sh"
[ -f $custom ] && source "$custom" $version $vmajor $vminor $vpatch
custom="custom-options-$vmajor.$vminor.sh"
[ -f $custom ] && source "$custom" $version $vmajor $vminor $vpatch
custom="custom-options-$vmajor.$vminor.$vpatch.sh"
[ -f $custom ] && source "$custom" $version $vmajor $vminor $vpatch

Compile

$ cd /opt/phpfarm/src
$ sudo ./compile.sh 5.3.29

Install all Requirement

$ sudo apt install \
libxml2 \
libxml2-dev \
libssl-dev \
libcurl4-openssl-dev \
libicu-dev \
libmcrypt-dev \
libgeoip-dev \
libmagickwand-dev \
libjpeg-dev \
libpng12-dev \
libmysqlclient-dev

Compile

cd /opt/phpfarm/src
$ sudo ./compile.sh 5.3.29

Verify the installation

$ sudo /opt/phpfarm/inst/bin/php-5.3.29 --version

Configuration

Apache Configuration

$ sudo vim /etc/apache2/apache2.conf

# fastcgi_module
LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so

# php5_module
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so

# Custom Config
IncludeOptional conf-enabled/*.conf

# VHost Config
IncludeOptional sites-enabled/*.conf

PHP Configuration

$ sudo vim /etc/apache2/conf-enabled/php5_module.conf

<IfModule php5_module>
  AddType application/x-httpd-php .php
  AddType application/x-httpd-php-source .phps
</IfModule>

FastCGI Configuration

$ sudo vim /etc/apache2/conf-enabled/fastcgi_module.conf

<IfModule fastcgi_module>
  #FastCgiWrapper /usr/lib/apache2/suexec
  ScriptAlias /cgi-bin-php/ /usr/lib/cgi-bin-php/
  AddHandler fastcgi-script .fcgi
  <Directory "/usr/lib/cgi-bin-php">
    AllowOverride None
    Require all granted
  </Directory>
  # mkdir /var/lib/apache2/fastcgi
  FastCgiIpcDir /var/lib/apache2/fastcgi
</IfModule>

$ sudo vim /usr/lib/cgi-bin-php/php-cgi-5.3.29.fcgi

#!/bin/sh
PHPRC="/etc/php5/cgi/5.3.29/"
export PHPRC

PHP_FCGI_CHILDREN=3
export PHP_FCGI_CHILDREN

PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_MAX_REQUESTS

exec /opt/phpfarm/inst/bin/php-cgi-5.3.29

$ sudo chmod 755 /usr/lib/cgi-bin-php/php-cgi-5.3.29.fcgi

VHost Configuration

$ sudo vim /etc/apache2/vhosts/php53.siswadi.com.conf

<VirtualHost *:80>
  ServerName php53.siswadi.com
  ServerAlias www.php53.siswadi.com
  DocumentRoot "/home/siswadi/php53.siswadi.com/public_html"
  <Directory "/home/siswadi/php53.siswadi.com/public_html">
    AllowOverride All
    allow from all
    Options +FollowSymLinks
  </Directory>
  <IfModule fastcgi_module>
    AddHandler php-cgi .php
    Action php-cgi /cgi-bin-php/php-cgi-5.3.29.fcgi
    <FilesMatch "\.php$">
      SetHandler php-cgi
    </FilesMatch>
    <Directory "/usr/lib/cgi-bin-php/">
        Order allow,deny
        Allow from all 
        Require all granted
    </Directory>
  </IfModule>
  ErrorLog "/usr/local/var/log/apache2/php53.siswadi.com-error_log"
  CustomLog "/usr/local/var/log/apache2/php53.siswadi.com-access_log" common
</VirtualHost>

$ sudo vim /etc/apache2/vhosts/php70.siswadi.com.conf

<VirtualHost *:80>
  ServerName php70.siswadi.com
  ServerAlias www.php70.siswadi.com
  DocumentRoot "/home/siswadi/php70.siswadi.com/public_html"
  <Directory "/home/siswadi/php70.siswadi.com/public_html">
    AllowOverride All
    allow from all
    Options +FollowSymLinks
  </Directory>
  ErrorLog "/usr/local/var/log/apache2/php70.siswadi.com-error_log"
  CustomLog "/usr/local/var/log/apache2/php70.siswadi.com-access_log" common
</VirtualHost>

$ sudo vim /etc/hosts

127.0.0.1 php53.siswadi.com
127.0.0.1 php56.siswadi.com
127.0.0.1 php70.siswadi.com

$ sudo vim /home/siswadi/php53.siswadi.com/public_html/index.php

<? phpinfo() ?>

$ sudo vim /home/siswadi/php70.siswadi.com/public_html/index.php

<? phpinfo() ?>

Restart Apache

$ sudo service apache2 restart

Testing

PHP Version 5.3.29
PHP Version 5.5.9
PHP Version 5.6.0
PHP Version 7.0.13
  • Done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment