PHP 5 Upgrade Walkthrough


Upgrading to (or installing) PHP 5 on a Debian testing system running Apache 2 and MySQL.

DISCLAIMER 0: This walkthrough was written in 2004, when Debian stable was still Woody and testing was Sarge. At that time, PHP 5 was not available even for testing (Sarge), a situation that has since changed. As a result, this walkthrough is basically obsolete; it is now fairly easy to install PHP 5 and Apache 2 and MySQL 5 on Debian using whichever variant of apt is favored.

DISCLAIMER 1: I am not associated with Debian, Apache, MySQL, or PHP to any extent other than my usage of their software. If you have problems, I'll gladly try to help, but I'm no expert. This is a generalized walkthrough of my experience installing PHP 5 on my system. If you notice an egregious error, or even a minor one, drop me a line.

NOTE: Throughout this walkthrough, I refer to "the Debian XXX installation," I'm referring to XXX being installed using some variant of apt, including apt itself. I personally use aptitude; others may like synaptic or kpackage or even dselect.

PHP 5 has been out for some time now, and I've been curious to try it out. It's got new object-oriented programming features, it's supposed to perform better than PHP 4 (by being more secure/less buggy than PHP 4), and it could potentially trash my server, so the appeal should be obvious.

The PHP documentation warns against using PHP 5 with Apache 2 in a production environment; apparently, the thread safety of PHP interacting with Apache 2 is an issue. Since I'm running what is in essence a development server, I am not worried about it going down catastrophically so long as the hardware survives. More importantly, I have the pre-fork non-threaded installation of Apache 2, so thread interaction should not be an issue.

NOTE: This walkthrough assumes that we're installing PHP 5 on a machine that already has Apache 2 and MySQL installed and working properly. Some may argue that having Apache and MySQL on the same server breaks the "working properly" part of my assumption; that's an argument for another day.

The basic steps to get PHP 5 running on your system are

  1. Download the source
  2. Unzip the source
  3. Enter the directory containing the just-unzipped files
  4. Stop Apache
  5. Run the configuration tool
  6. Run make
  7. Run make install
  8. Restart Apache
  9. Test to see if PHP is running

And now, the details including the problems I encountered in steps 5 and 7:

1. Download the source
Go to the PHP homepage and locate their downloads section. I accidentally started to download PHP 4, as it was at the top of the page; scroll down to find the latest version of PHP 5. After selecting a mirror, save the file to the directory of your choice. I put mine in /usr/share, which is where Debian likes to put applications.

2. Unzip the source
Unzip the files using either tar jxvf php-NN.tar.bz2 or tar zxvf php-NN.tar.gz, depending on whether you downloaded the bzipped or gzipped source archive. The NN, by the way, is a place-holder for the version of the source you downloaded. Anyway, the source files will unzip into a new directory in the current directory called php-NN. In my case, that would be /usr/share/php-NN

3. Enter the directory containing the just-unzipped files
In my case, cd /usr/share/php-NN or since I'm already in /usr/share, cd php-NN

4. Stop Apache
For a Debian installation, the command is apache2ctl stop. If you don't have a standard Debian installation, the command might be httpd stop or apache stop or something to that effect; make sure you are running the correct command before proceeding.

5. Run the configuration tool
Here's where things get interesting/hairy. We're in the php-NN directory, so we're going to run ./configure with whatever options we want enabled. In my case, I ran

./configure --with-config-file-path=/etc/php5 --disable-short-tags --with-apxs2=/usr/bin/apxs2 --with-openssl --with-gd --with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib --with-zlib-dir=/usr/lib --with-mysql --with-pear --with-xsl

--with-config-file-path determines where the php.ini file will be located; this can be arbitrary, and I like /etc/php5 to match where the apt PHP 4 installation put the php.ini.

--disable-short-tags lets me disable short tags by default, something I can later override if I want to in the php.ini file. Short tags are used to mark where a PHP script starts and ends, but they are short because you use < ? ... ?> instead of < ?php ... ?>. I prefer to turn this off because I have no need for it and I don't want to fall into lazy habits.

--with-apxs2 tells it we want the Apache2 webserver module and we also give it the path to apxs, which in a Debian install, would be /usr/bin/apxs2.

--with-openssl enables openssl support.

--with-gd enables dynamic graphics support. Here's where things got tricky for me. I'd like to be able to dynamically generate thumbnails and other graphics files in various formats. The GD extension allows this, but with the Debian install, I had to make sure I had all the dev packages for png support, jpg support, zlib support, etc. The same applies to xsl; you need to install libxslt-dev (or whatever variant of libxslt is appropriate) in addition to obviously having the libxslt package installed. I suppose that if you don't have the libxslt package installed, and you try to install libxslt-dev, apt would automatically install libxslt as a dependency, but I didn't bother to check. The same applies to libpng (you need libpng-dev), libjpeg (libjpeg-dev), zlib (zlib-dev) and libmysqlclient (libmysqlclient-dev).

--with-mysql enables mysql database support. The configuration tool will try to locate the mysql binaries and libraries it requires to provide mysql support; if it has trouble finding these, it either needs the dev libraries or it needs you to point it at the proper mysql directories.

--with-pear enables the PEAR API if I want to play with it later.

--with-xsl enables xsl/xslt support. See the information for graphics support above if you have trouble getting this to work; it is likely a dev library issue.

6. Run make
This ran with no problems. A shock, I know, after all the issues ./configure gave me.

7. Run make install
Here's where I encountered a pseudo-bug in going outside of the Debian package management system. When the make install script tried to create/install the PHP 5 Apache module by calling apxs2 (the Apache utility that is used for this purpose), it failed with an error claiming that because no LoadModule directives existed, the installation could not continue (I paraphrase here; your error may vary, but the gist should be the same). The cause of this is a quirk in the Debian Apache package: it loads modules from a directory, rather than from a *.conf file.

Traditionally, Apache configuration directives live in a file called httpd.conf. Debian places these directives in a file called apache2.conf and leaves httpd.conf as a blank file that can be filled with specific, overriding directives. Indeed, one of the apache2.conf directives is to load directives from the httpd.conf file. Another of the apache2.conf directives is an include directive that loads any module listed in the modules-enabled directory. The result of this is that no LoadModule directive actually appears in either file. The PHP installation, encounters this as an error, apparently assuming that the Apache installation is faulty somehow.

The work-around is to put a commented LoadModule directive in either file. I put mine in the httpd.conf file; others recommend the apache2.conf file. The actual directive that I used is

#LoadModule dummy_module /usr/lib/apache2/modules/mod_dummy.so

You don't need to create a mod_dummy.so file; and it doesn't have to be uncommented for this to work. This single line should allow the make install process to proceed normally.

A link to the Debian "bug" report/solution: https://lists.debian.org/debian-apache/2004/02/msg00056.html

8. Restart Apache
The command for this is apache2ctl start for my Debian installation. Replace stop with start for whichever command you used to stop Apache earlier on.

9. Test to see if PHP is running
My favorite way to do this and make sure that my options were accepted is to place a file called info.php with the phpinfo command. That single line of PHP should, if the file is opened in a browser, display information about PHP, the webserver, the database, and other systems that were enabled in the configuration.

Copyright © 2004 Jose Marquez

Creative Commons License
This work is licensed under a Creative Commons License.

2004Jose MarquezJose Marquez


--> ]]>

Latest poll

Which do you favor?

Choices

Twitter