PHP DevCenter
oreilly.comSafari Books Online.Conferences.

advertisement


PHP 4.3 and Mac OS X
Pages: 1, 2

In addition to configuring PHP to support additional extensions, you also need to tell PHP where to install its files. Apple stores files in a different set of directories than PHP's preferred location. However, you can instruct PHP to override its default settings to conform with Apple's.



To do this, pass in these four settings:

--prefix=/usr --sysconfdir=/etc --localstatedir=/var --mandir=/usr/share/man

Once you set up PHP to install files correctly, add your Web server into the mix. If you don't specifically tell PHP your Web server, PHP builds a generic CGI version. But, if you're running Apache, for instance, PHP can create an Apache module. Apache 1.x support is added by passing in --with-apxs.

--with-apxs

If you're running Apple's bundled Apache, PHP automatically locates your server and properly configures itself accordingly. (This will probably work even if you've reinstalled Apache.)

Other Web servers have different commands. The experimental PHP Apache 2.x filer is built with --apxs2. For others, run the help command, as mentioned earlier. It shows a list of Web server options.

One final configuration note. PHP does not install zlib automatically, and without zlib, MySQL and other programs won't run. So, explicitly add this extension to your configuration line:

--with-zlib

Putting all this together gives us these parameters for a basic Apache and PHP installation:

[benlev:~/php-4.3.0] adam% ./configure --prefix=/usr --sysconfdir=/etc 
 --localstatedir=/var --mandir=/usr/share/man --with-apxs --with-zlib

Hit return and configure will run for a while, printing out a series of scrolling lines, before finally ending with this message:

+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+
|                          *** NOTE ***                              |
|            The default for register_globals is now OFF!            |
|                                                                    |
| If your application relies on register_globals being ON, you       |
| should explicitly set it to on in your php.ini file.               |
| Note that you are strongly encouraged to read                      |
| http://www.php.net/manual/en/security.registerglobals.php          |
| about the implications of having register_globals set to on, and   |
| avoid using it if possible.                                        |
+--------------------------------------------------------------------+

Thank you for using PHP.

As you see, PHP now disables the register_globals configuration directive. This change is effective as of PHP 4.2, but if you're upgrading directly from Apple's installed version (4.0.6), this is the first time the change affects you. In brief, you can no longer access a HTML form variable called "name" as $name. Instead, you need to check the value of $_GET['name'] or $_POST['name']. See the online PHP manual for additional information.

If you don't see this message, PHP had a problem during configuration. Look at the error message and fix what's broken. If you cannot solve the problem by yourself, check the Installation PHP mailing list for help.

Now that the laborious configuration process is complete, compile PHP by running make:

[benlev:~/php-4.3.0] adam% make

This will take a while. Don't be afraid if you see warnings. Warnings are okay; errors are not. There's no fancy announcement when this finishes, so unless you see an obvious error message, everything went OK when the printing stops.

Finally, you want to install PHP. This overwrites any pre-existing copies of PHP on your system. So, if you want to keep them (for testing purposes or nostalgia), now is the time to back them up. If you've chosen to use the directories suggested above, you need administrator privileges to install PHP, so run this command through sudo:

[benlev:~/php-4.3.0] adam% sudo make install

The installer places the Web server module in the correct place, installs the PHP command line version, and also places PEAR onto your system. (A few helper files are also installed.)

If you run Apache and PHP, restart your Web server to use your new copy of PHP:

[benlev:~/php-4.3.0] adam% sudo apachectl graceful

You can verify everything worked OK by viewing a page containing the output from phpinfo(). Check out the version number, build date, and configuration options to make sure.

However, if you're trying out PHP and Apache for the first time, see Kevin Hemenway's article on Apache and PHP to learn how to configure Apache to support PHP.

The command line interface to PHP (aka PHP CLI) lets you execute PHP scripts without the overhead of requesting them using a Web browser. Recently released versions of PHP had unofficial support for the CLI, but it has gone final with 4.3.0. If you want to use PHP for system maintenance tasks or with PHP-GTK, the CLI is for you. (Note: If you've chosen to install PHP as a CGI instead of a Web server module, then you need to explicitly install the CLI using make install-cli. This isn't a problem for people installing PHP as an Apache module, as described earlier in this article.)

Congratulations. You now have a working copy of PHP 4.3 on your Macintosh. Enjoy.


O'Reilly & Associates recently released (November 2002) PHP Cookbook .

Adam Trachtenberg is the manager of technical evangelism for eBay and is the author of two O'Reilly books, "Upgrading to PHP 5" and "PHP Cookbook." In February he will be speaking at Web Services Edge 2005 on "Developing E-Commerce Applications with Web Services" and at the O'Reilly booth at LinuxWorld on "Writing eBay Web Services Applications with PHP 5."


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: