Install PHP4 on Ubuntu 7.04
It appears they decided to remove PHP4 from the Ubuntu 7.04 (Feisty) repositories. Oh well, that’s why we have source code. This tutorial well help you get set up and running using a source distribution of PHP4, and apt-get for everything else.
Step 1: Download Stuff
For this tutorial, I downloaded the BZ2 package, so if you want to follow my command lines exactly, I suggest doing the same. If you are comfortable extracting any kind of package, just grab your favorite.
- Download PHP4 from http://www.php.net/downloads.php
Step 2: Download Build Utilities
Ubuntu does not come with everything you need to compile from source out of the box. You’ll need to apt-get the following:
- sudo apt-get install build-essential (stuff you’ll need to compile from source)
- sudo apt-get install flex (also needed for the build process)
Step 3: Install Apache
- sudo apt-get install apache2
- sudo apt-get install apache2-threaded-dev (includes apxs2 binary, which we will need later when we compile PHP)
Step 4: Install Mysql
- sudo apt-get install mysql-server
- sudo apt-get install libmysql++-dev
Step 2 will install the headers for Mysql, which we will need when we compile PHP in the next step.
Step 5: Extract and Compile PHP4
- tar -xjvf php-4.4.7
- cd php-4.4.7/
- ./configure –with-apxs2=/usr/bin/apxs2 –with-mysql=/usr –with-pear
- make
- sudo make install
At this point you might get an error that looks like this:
apxs:Error: Activation failed for custom /etc/apache2/httpd.conf file..
apxs:Error: At least one `LoadModule’ directive already has to exist..
make: *** [install-sapi] Error 1
Don’t worry, this is apparently a known bug. Also, we can thank Darren Beale for finding a very simple solution to this problem. The proceeding fix is a slight variation on his fix, but it ultimately does the exact same thing:
- sudo gedit /etc/apache2/httpd.conf
- On line 1, insert an empty line (this is seriously important, make sure there is a blank line!)
- On line 2, insert the following:
#LoadModule foo_module /usr/lib/apache2/modules/foo.so
The “#” comments the line out, so it’s totally harmless. You can remove it later if you feel like it.
- Save the file and attempt “sudo make install” again. The script should complete without any errors this time.
Step 6: Create php.ini
I won’t go into detail about how to configure php.ini. Just do this generic step unless you have more detailed configuring to do:
- sudo cp php.ini-dist /usr/local/lib/php.ini
Step 7: Update Your Apache Configuration
- sudo gedit /etc/apache2/httpd.conf
- Now insert the following lines (the first of which will most likely already be present, just grab the last two lines if it is):
LoadModule php4_module /usr/lib/apache2/modules/libphp4.so
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps - Save the file
- sudo /etc/init.d/apache2 restart
Congratulations, You’re Done
Now, bask in the glory of your archaic PHP4 server.