I suppose that a site that discusses PHP and Linux affairs should probably have some sort of documentation or links to reasonable how-tos on the subject. However, the thought of detailing a PHP/Apache/MySQL installation doesn’t appeal to me much either, so I’ll take a different slice on this. Rather than regurgitating the same steps as every other PHP How-To, I’ll talk about some configuration choices based on the machine’s role.
Alright then, you want to install PHP on your PC or “server” type machine. I’d hazard that you’re either already running Linux or have the misfortune of running Windows. While PHP runs on just about on hardware and OS combo, the Unix flavours perform better and seem to be more stable, not to mention there is less voodoo involved in making it work right.
In a nutshell, PHP is typically run in one of two different modes, either in CGI mode or SAPI mode.
In CGI mode, when a PHP page is called the webserver invokes the PHP executable to evaluate and execute the named script. The PHP binary is read into memory each time effectively isolating the execution. This mode is popular with certain ISP’s as it allows PHP to be further secured to client web home and configured to constrain to certain policies such memory and execution restrictions. There is some overhead performance cost with the CGI mode, but it is reliable and unlikely to knock over a shared host when properly configured. Most Windows IIS installations will run in CGI mode.
In SAPI mode things are a little different. The PHP code is complied into both a CGI and library form. This library is configured for use within the webserver and when PHP pages are being rendered, the in-memory library is used instead of an isolated process such as CGI mode. Under Apache, this seems to work great both on Linux and Windows. SAPI under Windows IIS tends to be a frustrating, futile exercise. PHP in SAPI mode tends to perform very well, less disk I/O overhead is achieved by taking full advantage of webserver caches, and optional PHP OpCode caches that further boost performance. In a shared environment it can be somewhat more complicated to configure some client restrictions and access rights, but there are many resources dedicated to locking-down PHP in these such configurations.
If you are a Windows user running IIS, don’t waste your time. Go with the standard CGI installation and save yourself the agony of running the SAPI module. PHP in CGI mode under Windows is bomb-proof and is very easy to install. Getting the SAPI to work under IIS isn’t all that difficult but it never seems to be very stable; no matter what, it will begin to complain about exception errors, and will open pop-up windows on the server complaining about something or other, sometimes locking up the webserver altogether. It just doesn’t seem to be very robust or clear if PHP is supposed to be production quality under IIS.
If you’re a Linux user, life is good for you in this regard. Check the details of your distribution, chances are there is a PHP package that can installed with only a few clicks of your mouse. Recently, Fedora Core has been my distro of choice and its PHP packages are great; they come compiled with all sorts of extras such as GD, LDAP and a few other neat-o extensions.
The next question that may come up is which version of PHP to install? PHP is currently being developed in 3 major versions, both 4, 5 and 6. At this time, PHP 4 support will be discontinued by the end of 2007 with only critical security fixes applied on a case-by-case basis until August 2008. PHP 5 is the way to go, its stable, production quality and has a future.
Compiling PHP from scratch is a good way to go on Linux but can be nuisance if it gets installed along side a pre-packaged file such as an RPM or if you have a lot of dependencies for extensions you need to include.
If you decide to roll-your-own PHP, I recommend starting from scratch; remove any repackaged webserver and PHP if already installed. Acquire the sources for PHP, Apache and any additional (-devel) dependencies for the extensions you want to build. I can’t really speak to compiling PHP under Win32 as I’ve never attempted it; there just doesn’t seem to be a good reason to do so, most extensions are precompiled and available from PHP.net directly.
Recommendations?
For a Windows based PHP developer, the PHP CGI under IIS works great and is easy to install and upgrade while not performing as well as similar hardware under Linux and Apache. Every time someone uses a Windows IIS MySQL PHP (WIMP) configuration in production, God kills a kitten. Just don’t do it.
For a Linux based PHP developer. You most likely have it the easiest of all. Depending on your distribution, it’ll probably only take you a few clicks using the package manager. If not, roll-your-own.
For Production purposes, a scratch built Apache 2.x and PHP5 SAPI running on Solaris/BSD/Linux compiled with only the required extensions. This is then optimized with an OpCode cache such as APC (Alternative PHP Cache) providing a robust and extremely fast PHP server capable of making short work of even the most complex PHP scripts.
Where to get platform specific installation info? Go straight to the horse’s mouth: PHP Installation Documentation