Published on (
 See this if you're having trouble printing code examples

PHP Admin Basics

Basic Installation of PHP on a Unix System


The configuration system that PHP uses for installation is one of those nice, simple things in life that makes it rosy. At first it might seem a little confusing, but it's really very easy. So let's dive right in.

To download PHP, visit the download page and click the link under the heading "Complete Source Code."

The first thing to do after downloading and unpacking your source archive is to kick the tires a little bit.

You can unpack the archive using:

gunzip php-x.x.x.tar.gz;
tar xvf php-x.x.x.tar

(Substitute x.x.x for the actual version number of the php archive you downloaded.)

After which, you should see a directory called php-x.x.x, where x.x.x is the version number or some variation thereof. Then, cd into this directory and type:

./configure --help | more

to get a list of all available configuration options. The first few lines of output should look something like this:

Usage: configure [options] [host]
Options: [defaults in brackets after descriptions]
--cache-file=FILE cache test results in FILE
--help print this message
--no-create do not create output files
--quiet, --silent do not print "checking..." messages
--version print the version of autoconf that created configure

Also this week:

Achieving Low-Latency Response Times Under Linux

LAMP Lighter: The Apache Toolbox

Exploring the /proc/net/ Directory

BSD Tricks: Linux Compatibility, the Hard Way

Before compiling PHP you must first decide whether you're going to install it as a CGI binary or as an Apache module. I'll discuss compiling as an Apache module, as the two are virtually identical.

Next you must decide what additional PHP modules you wish to have built at compile time. An example of these modules might be mCrypt or FTP. I'll use these two as examples, but there are many more available. A complete list of supported modules can be found in the PHP documentation or by executing the above configure command.

To configure PHP with the mCrypt and FTP modules built in, type the following command:

./configure --with-apache=/tmp/apache_1.3.12 --with-mcrypt --with-ftp

Here I use /tmp/apache_1.3.12 as an example. You should replace it with the actual location of your Apache source. The configuration script will now go through a series of checks to see what you have installed on your system. If something the compiler will need is missing, it will let you know of your grievous error and stop abruptly with an error like:

configure: error: Please reinstall libmcrypt - I cannot find mcrypt.h

This is the configuration system's way of telling you it loves you, but you only have twenty-four hours to save the earth. That, and it couldn't find the mCrypt libraries anywhere on your system. So, go download and install any necessary libraries.

Once you've installed all the necessary dependencies, we can proceed on course. Re-run the configure script with the same options as above, and you should see something like "Thank you for using PHP." The PHP core development team is nothing if not gracious.

This little note means you can now compile PHP by typing:


I told you it was simple. Next, you probably want to test the compile just to make sure everything is kosher before proceeding to a full install. If anything should go wrong, you will probably be notified with a line that begins with "ERROR" and contains information about what went wrong (the scope of which couldn't possibly be covered in this article). Suffice it to say that if configure didn't give you any errors, then you're probably good to go now.

make test

The last few lines of this should look something like:

Number of tests:    95
Tests skipped:       6 (6.3%)
Tests failed:       16 ( 18%)
Tests passed:       73 ( 82%)

Just as a side note, the make test command just performs a few tests on PHP itself to make sure the various functions contained within work as they should. This command isn't required to install PHP. It's just handy to make sure it ain't misbehavin'.

To complete the install, you simply type:

make install

That last command seals the deal, and you now have PHP installed as an Apache module. Specifically, make install creates a directory in /usr/local/lib called php where it places a copy of PEAR (PHP Extension Add-on Repository) and the php.ini file. It also places a copy of the PHP/Apache modules in the Apache source directory provided with --with-apache=.

In case you were wondering, all you have to do to install PHP as a CGI binary is execute the above configure command without the --with-apache part, and it will default to compiling as a binary. When you do the make install part, it will most likely put the actual binary in /usr/local/bin. You should then copy the executable to your cgi-bin directory by typing the command:

cp /usr/local/bin/php /usr/local/apache/cgi-bin/php.cgi

where /usr/local/apache is the location of your Apache installation. This allows you to execute PHP as a CGI from Apache.

Some things to look out for: In my experience, Sun's Solaris flavor of Unix doesn't come with much, if any, GNU software by default. This may have changed with Solaris 8, but if it hasn't, then you'll pretty much need to get some GNU lovin' before you even start configuring PHP.

If you're compiling a module along with PHP, such as mCrypt, always make sure that you have the needed module library files before starting your configuration. PHP only comes with the source code necessary to get it running in a relatively basic form. If you want to extend the functionality of PHP, you might need to download the files for the particular module you wish to use (such as mCrypt in the example above). Doing this will save you that dreaded feeling everyone gets when compilation breaks and leaves you with cryptic error messages.

One thing to keep in mind when compiling PHP as a CGI binary: Make sure you execute the make install part as root. If you are not installing PHP as root, you'll get a permissions error and it won't install.

A final test of your install is best handled with a sample PHP script. The following PHP code will output (in HTML) the installation information for your particular copy of PHP:

        // Display a list of PHP?s compile-time features
Place that code in a file called info.php and save it somewhere in your Apache document root. Next, if you installed PHP as an Apache module, you can call that page in your browser by going to

If you installed PHP as a CGI, then point your browser to

So there you go. See how simple installing PHP can be? Enjoy the power of PHP!

Darrell Brogdon is a web developer for SourceForge at VA Linux Systems and has been using PHP since 1996.

Also this week:

Achieving Low-Latency Response Times Under Linux

LAMP Lighter: The Apache Toolbox

Exploring the /proc/net/ Directory

BSD Tricks: Linux Compatibility, the Hard Way

Discuss this article in the O'Reilly Network PHP Forum.

Return to the PHP DevCenter.


Copyright © 2009 O'Reilly Media, Inc.