(Ping! Zine Issue 9) – PHP rocks. Ranking higher than ASP and Cold Fusion, PHP is by far the most popular scripting language on the net and its number are only getting higher. Apple has been nice enough to include PHP 4 and Apache with every new Mac, but now it’s time to move on and install your own update.
On July 13, 2004 developers around the world rejoiced with the news of the final release of PHP 5.0.0. We can now say goodbye forever to our old friend register_globals, and usher in a new age of Object Oriented programming, Web Services interoperability, SQLite, and many more features prominently listed on the home page of php.net. But we’re not here to discuss the features of PHP 5. I know you want it, you know you want it, so let’s get on with the gettin’ on.
First, some disclaimers:
• This article assumes you already have PHP 4 and Apache running on Mac OS X.3. I will not be showing you how to install Apache, so if you don’t have that running stop reading this and head over to Apple’s Apache page at http://www.apple.com/downloads/macosx/unix_open_source/apache.html.
• These procedures were created for Mac OS X.3 or higher. Older systems have not been tested.
• You will need a C compiler (part of the Developer Tools) to create your build. If you do not have the Developer Tools installed, registered users can download them for free from the Apple Developer Connection at http://developer.apple.com.
• Most importantly, PHP 5 was created to be backward compatible with previous versions, but there have been many changes which can and most likely will render your code useless or even cause fatal errors. Be sure to review the change log (http://www.zend.com/php5/articles/engine2-php5-changes.php) before continuing.
Those of you familiar with Marc Liyanage and his fantastic site over at www.entropy.ch may be wondering why I’m going through these steps when you can just download the pre-compiled module and save yourself the headache of doing all the work yourself. The short answer is because you will never learn anything that way! So stop complaining and let’s continue…
Your first step is to create a directory to download the PHP 5 tar file to and then to uncompress it. Open up a new terminal window and type the following:
user% mkdir php5
user% cd php5
user% curl -O http://ie.php.net/distributions/php-5.0.0.tar.gz
user% gnutar -xzf php-5.0.0.tar.gz
user% cd php-5.0.0
Our next step will be to create the build. We will assume that you want to use MySQL, so we will include the necessary step to enable it.
user% ./configure \
user% sudo make
user% sudo make install
Those last 2 steps make take a few minutes. Wait patiently, and pay close attention to any errors that may appear. In the rare instance that you do get any errors, they will most likely be caused by not having the Developer Tools installed.
Once PHP 5 has been installed, you may want to add the php.ini file. This is not necessary, but it will allow you more customization with your PHP configuration. You can just copy the php.ini file that came with the distribution to your /usr/local/lib/ directory:
% sudo cp php.ini-dist /usr/local/lib/php.ini
If you have been using a version of PHP that came bundled with Mac OS X, you will need to comment out a few lines of your httpd.conf file. In the terminal type the following:
sudo vi /private/etc/httpd/httpd.conf
Then look for the following lines and comment them out by adding a ‘#’ before them, and then save the file:
#LoadModule hfs_apple_module libexec/httpd/mod_hfs_apple.so
#LoadModule rendezvous_apple_module #libexec/httpd/mod_rendezvous_apple.so
After you close and save the file, restart apache:
PHP 5 should be up and running. To make sure, open a new text document and type the following:
<? phpinfo(); ?>
Then save the document to /Library/WebServer/Documents or wherever you keep your http docs and browse to it locally on your system. You should see something similar to this screenshot:
And that’s all there is to it. PHP 5 should be running smoothly.
If this is your first time developing with PHP 5 it would be a good idea to visit php.net to learn about all of the new capabilities. The inclusion of SQLite in itself will simplify building those smaller, db-driven sites, and it wouldn’t hurt to review some of its commands at http://sqlite.org.
And most of your old PHP 4 scripts should work, unless you’ve been coding with register_globals = ON. If you have, or if you have no idea what I’m talking about, head on over to http://us2.php.net/reserved.variables and do some studying.
To help learn some of the new tricks in PHP 5, here is a list of some helpful sites:
• Function list- http://www.zend.com/manual/migration5.functions.php
• PHP 5 Change Log – http://www.php.net/ChangeLog-5.php
• Downloads – http://www.php.net/downloads.php#v5
• Apple’s Apache info – http://www.apple.com/downloads/macosx/unix_open_source/apache.html
• SQLite downloads – http://sqlite.org/download.html
• Classes and Objects guide – http://us2.php.net/zend-engine-2.php
• Entropy quick and easy download – http://www.entropy.ch/software/macosx/php/
Writer’s Bio: Jay Staton sticks with us to bring new tricks and tools to the Mac hosting community. Jay works as the Senior Developer for Satori Group and spends his free time gaming, drumming, and trying to get the other 95% to switch.