Ry’s Blog

May 25, 2007

Install PHP4 on Ubuntu 7.04

Filed under: Web Dev, Linux, Tutorials — Ry @ 2:35 am

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.

  1. 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:

  1. sudo apt-get install build-essential (stuff you’ll need to compile from source)
  2. sudo apt-get install flex (also needed for the build process)

Step 3: Install Apache

  1. sudo apt-get install apache2
  2. sudo apt-get install apache2-threaded-dev (includes apxs2 binary, which we will need later when we compile PHP)

Step 4: Install Mysql

  1. sudo apt-get install mysql-server
  2. 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

  1. tar -xjvf php-4.4.7
  2. cd php-4.4.7/
  3. ./configure –with-apxs2=/usr/bin/apxs2 –with-mysql=/usr –with-pear
  4. make
  5. 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:

  1. sudo gedit /etc/apache2/httpd.conf
  2. On line 1, insert an empty line (this is seriously important, make sure there is a blank line!)
  3. 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.

  4. 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:

  1. sudo cp php.ini-dist /usr/local/lib/php.ini

Step 7: Update Your Apache Configuration

  1. sudo gedit /etc/apache2/httpd.conf
  2. 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

  3. Save the file
  4. sudo /etc/init.d/apache2 restart

Congratulations, You’re Done

Now, bask in the glory of your archaic PHP4 server.

1 Comment »

  1. got this error when I tried to compile:sudo ./configure –with-apxs2=/usr/bin/apxs2 –with-mysql=/usr –with-pear
    configure: warning: –with-apxs2=/usr/bin/apxs2: invalid host type
    configure: warning: –with-mysql=/usr: invalid host type
    configure: error: can only configure for one host and one target at a time
    hawodi@sparks:~/downloads/php-4.4.8$ sudo ./configure –with-apxs2=/usr/bin/apxs2 –with-pear
    configure: warning: –with-apxs2=/usr/bin/apxs2: invalid host type
    configure: warning: –with-pear: invalid host type
    configure: error: can only configure for one host and one target at a time
    hawodi@sparks:~/downloads/php-4.4.8$ sudo ./configure –with-apxs2=/usr/bin/apxs2
    configure: warning: –with-apxs2=/usr/bin/apxs2: invalid host type
    creating cache ./config.cache
    checking for egrep… grep -E
    checking for a sed that does not truncate output… /bin/sed
    checking host system type… Invalid configuration `–with-apxs2=/usr/bin/apxs2′: machine `–with’ not recognized

    checking for gcc… gcc
    checking whether the C compiler (gcc ) works… yes
    checking whether the C compiler (gcc ) is a cross-compiler… no
    checking whether we are using GNU C… yes
    checking whether gcc accepts -g… yes
    checking whether gcc and cc understand -c and -o together… yes
    checking how to run the C preprocessor… gcc -E
    checking for AIX… no
    checking if compiler supports -R… no
    checking if compiler supports -Wl,-rpath,… yes
    checking for re2c… exit 0;
    checking whether ln -s works… yes
    checking for gawk… gawk
    checking for bison… no
    checking for byacc… no
    configure: warning: You will need bison if you want to regenerate the PHP parsers.
    checking for flex… lex
    checking for yywrap in -ll… no
    checking lex output file root… ./configure: 1: lex: not found
    configure: error: cannot find output from lex; giving up
    hawodi@sparks:~/downloads/php-4.4.8$

    Comment by naijadev — May 4, 2008 @ 11:47 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress