Multiple versions of PHP, MySQL and Apache under Debian Linux

If you’ve been the administrator of a Linux web server for as long as I have, you’ve inevitably run into the problem of what to do when significant upgrades of software come out that may break web sites you currently host. The easy solution is to just build a new server and maintain a legacy server for the older version, but this gets to be expensive and tedious. Wouldn’t it be nice to be able to host multiple versions of these server packages on one machine?

I’ve looked around for various ways to do it and I’ve come across different suggestions such as virtualization or running PHP in CGI mode, but it’s still a hassle and virtualization is, in my experience .. slower!

So what can we do to accomplish this goal? My solution was to set up a chroot environment and maintain it that way, sort of a server within a server. I’m sure if you’re reading this, you may have worked with chroot jails before or have heard of it at least. My goal with this guide is to walk you through the step by step process which you can repeat for any combination of servers you want to run! You are limited only by the number of IP addresses your machine has available, the memory and the disk space.

Setting Up The Server

Step 1.

Install the debootstrap package ( do an “apt-get update” first, as always )

#apt-get install debootstrap

Step 2.

Create a folder for this “server”, I created /lenny-php53 for this example because I’m going to be installing the Lenny base and I will be running php 5.3 under this server.

#mkdir /lenny-php53

Step 3.

Now we will use debootstrap to pull down the latest Lenny base install into the folder we created. I am using the US mirror for this example.

#debootstrap lenny /lenny-php53 http://ftp.us.debian.org/debian

Step 4.

Now we want to mount proc into our virtual system, this is required for process management under our chroot environment.

#mount -o bind /proc /lenny-php53/proc

Step 5.

Now we will “log in” to our environment using the chroot command, this will put us into our new “server” where we can begin installing software without affecting the host.

#chroot /lenny-php53

Step 6.

Now we will want to add our lenny sources so that apt functions properly.

#echo deb http://ftp.us.debian.org/debian/ lenny main > /etc/apt/sources.list

#echo deb http://security.debian.org/ lenny/updates main >> /etc/apt/sources.list

Step 7.

Perform an upgrade of the system using apt, again this is only affecting our chroot jail and not the host system, so no need to panic.

#apt-get update

#apt-get upgrade

Step 8.

Install the locales package and configure your default language settings. I didn’t have to do this when I was setting this up on a different machine, but I did run into this on another so I included this step in the process.

#apt-get install locales

#dpkg-reconfigure locales ( en US UTF8 is what I chose )

Step 9.

Since Lenny only goes up to PHP 5.2, we’ll want to add the dotdeb repository to our sources list and then add their GPG key so that apt doesn’t complain.

#echo deb http://php53.dotdeb.org stable all > /etc/apt/sources.list

#echo deb-src http://php53.dotdeb.org stable all /etc/apt/sources.list

#gpg –keyserver keys.gnupg.net –recv-key 89DF5277

#gpg -a –export 89DF5277 | apt-key add -

Step 10.

Perform an update using apt, then install your packages!

#apt-get update

#apt-get install apache2 php5 php5-mysql

Network Considerations

Now that you have all of your packages installed, you will want to take special consideration of your network configuration. If you’re running apache2 on the host machine already and are not specifically declaring which IP addresses you’re listening on you will want to do that now.

in /etc/apache2/ports.conf there is a line that by default says:

Listen 80

This line binds apache2 port 80 to every single IP address on your machine which will prevent you from launching apache in your chroot environment, so you will want to modify the ports.conf on your host machine ( use exit to get out of your chroot environment first ).

You will need to specify a listen line for every ip address that your host server will be handling and exclude the IP address(s) that you want your chroot server to handle, which will look something like this:

NameVirtualHost *:80

Listen 192.168.0.130:80
Listen 192.168.0.68:80
Listen 192.168.0.73:80
Listen 192.168.0.74:80

Now reload apache using /etc/init.d/apache2 reload and then chroot back into your jailed environment using chroot /lenny-php53 so that you can configure the jailed server’s ports.conf file.

You will need to do the same thing, replace the “Listen 80″ line to specify the IP address(s) you want to use on this server.

NameVirtualHost *:80

Listen 192.168.0.100:80

Now that you’ve done that, you can start apache2 with /etc/init.d/apache2 start and then browse to your IP address to see the famous “It Works!” page!

192.168.0

Related Search Terms:

  • dabian multiple php
  • debian multiple php versions
  • debian multiple php
  • multiple PHP versions apache linux
  • apache multiple php versions linux
  • multiple php versions linux
  • apache multiple php
  • debian multiple versions
  • chroot vserver
  • linux multiple php versions
  • debian two versions of php
  • debian lenny multiple php
  • debian two php versions
  • debian multiple php version
  • debian multiple version php

Written by Lonnie Waugh

Related Posts

  • No Related Posts

Leave a Reply