PHP DevCenter
oreilly.comSafari Books Online.Conferences.

advertisement


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:

make

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:

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:

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:

<?php
        // Display a list of PHP?s compile-time features
        phpinfo();
?>
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 http://yourdomain.com/yoursubdirectory/info.php.

If you installed PHP as a CGI, then point your browser to http://yourdomain.com/cgi-bin/php.cgi?info.php.

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.

 




Valuable Online Certification Training

Online Certification for Your Career
Earn a Certificate for Professional Development from the University of Illinois Office of Continuing Education upon completion of each online certificate program.

PHP/SQL Programming Certificate — The PHP/SQL Programming Certificate series is comprised of four courses covering beginning to advanced PHP programming, beginning to advanced database programming using the SQL language, database theory, and integrated Web 2.0 programming using PHP and SQL on the Unix/Linux mySQL platform.

Enroll today!


Sponsored by: