PHP DevCenter
oreilly.comSafari Books Online.Conferences.

advertisement


PHP Cookbook

PHP 4.3 and Mac OS X

by Adam Trachtenberg, coauthor of PHP Cookbook
01/16/2003

With the recent release of PHP 4.3, Macintosh users can now configure and build PHP themselves. This is a great boon. Finally, Mac OS X users have the same level of PHP support that people who run Linux and Windows enjoy.

If you wanted to use earlier versions of PHP on Mac OS X, you either needed to run the pre-compiled module provided by Apple or download a special, hand-built version made by helpful users. Apple only supplies PHP 4.0.6, so it's extremely out of date. Plus, it only supports a minimal set of extensions. Despite the heroism of some, Marc Liyanage in particular, these user-created versions of PHP run only with Apple's version of Apache, and you can't modify them to support new extensions.

But now, thanks to the hard work of many contributors, version 4.3 allows you to customize PHP with your favorite configuration. And, after reading this article, you'll know how to download, configure, and install your very own PHP on Mac OS X.

Note: These instructions have been tested only under Mac OS X 10.2.3. However, it is likely that these steps will work under any Mac OS X 10.2.x version. If you have had success or difficulty with earlier versions, please share your knowledge in the discussion at the end of this article.

Also, before proceeding, you need to install the files on the Developer's Tools CD, which supplements the main Mac OS X distribution. I suggest installing the complete set of recommended files because it's simple and easy. That's what I did. If that CD isn't handy, you can download the files from Apple's Developer Web site.

The first step is to retrieve 4.3.0 from the PHP Web site. To select the closest mirror to you to download with your Web browser, go to www.php.net/downloads.php. Or, to retrieve the file from the main PHP Web site directly from the command line, use cURL:

[benlev:~] adam% curl -O http://www.php.net/distributions/php-4.3.0.tar.gz

Now you need to unpack the files. If you used your Web browser, it's possible that StuffIt Expander did this automatically. Otherwise, use tar:

[benlev:~] adam% tar xvfz php-4.3.0.tar.gz

This creates a directory named php-4.3.0. Using Terminal, change into that folder. (If you're unfamiliar with the command line, read Chris Stone's tutorial.)

[benlev:~] adam% cd php-4.3.0

Here's the point in the process where you configure PHP. By default, PHP includes, in addition to its core functions, the session tracking module, basic XML support, and the MySQL extension. However, PHP supports a number of other extensions, including: the Oracle, MSSQL, and PostgreSQL databases; the IMAP, LDAP, and SNMP protocols; and JPEG, PNG, and PDF file formats.

To configure PHP, run the configure program and pass its arguments. Each argument begins with two hyphens followed by a word. To see a list of all possible options, use --help:

[benlev:~/php-4.3.0] adam% ./configure --help | less

For instance, to link in support for reading and writing XML using the DOM, using the FTP module, and communicating with LDAP servers, use the command:

[benlev:~/php-4.3.0] adam% ./configure --with-dom --enable-ftp --with-ldap

If a command argument begins with "with," it means PHP does not directly support a feature natively. Instead, it interfaces with an external program and uses that program's library of functions to perform those tasks. Therefore, in the example above, you need to install both the libxml extension and a LDAP library, if you want to use these features with PHP. The FTP extension, in contrast, is built-in to PHP.

Luckily, Apple bundles many of these programs with Mac OS X. Unfortunately, in some (or even many) cases, these programs are obsolete. Since PHP 4.3 uses many of a program's latest features, it often requires the latest version. If you need to upgrade, try using fink or another package manager. In some cases, you may even need to install programs by hand.

PHP tries to locate libraries no matter where they're stored on your hard drive. But, if your package manager places its files in a special location, tell PHP where to find them by placing an equal sign and the path after the command name:

--with-gd=/sw

This lets PHP find the GD graphics library in the /sw directory, which is where fink places files.

Pages: 1, 2

Next Pagearrow




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: