Basic Installation of PHP on a Unix System
Pages: 1, 2
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.
The last few lines of this should look something like:
TEST RESULT SUMMARY ============================= 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:
That last command seals the deal, and you now have PHP installed as an Apache module.
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
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
/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:
Place that code in a file called
<?php // Display a list of PHP?s compile-time features phpinfo(); ?>
info.phpand 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:
Discuss this article in the O'Reilly Network PHP Forum.
Return to the PHP DevCenter.