Ka of Isis is not optimized for this version of Internet Explorer
HomeE-mail

The Laboratory - Apache

PHP for Apache

10 September, 2008 | Filed under “Apache on the Macintosh

Note: This is a guide on how to enable PHP 5.2.6 on a client version of Mac OS X 10.5 (Leopard). It was last tested with version 10.5.4 of the operating system and, when used, requires that Apache is up and running on your local machine. For a tutorial on that, see Apache on the Macintosh. The former tutorial also elaborates on opening and editing hidden files.

Back in ‘94 it was Personal Home Page. Today PHP is ...

“… a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.” To echo the PHP team.

PHP is a module for the Apache web server and as such only runs when Apache runs. Even though PHP comes with the default installation of Leopard, several components of PHP go missing. This may or may not be a problem, depending on how extensive your implementation of PHP will be. If you are concerned about this, do consult Steve Stringer’s discussion and Marc Liyanage's forum and maybe opt for the separate installation of Apache, PHP – and MySQL – offered by Living-e.

Recommendation: As you are going to modify one of the Apache configuration files, it is a good idea to stop the Apache server from running while you are at it. You will eventually have to stop it and restart it, anyway, for the changes to take effect. So, in Finder, choose Apple > System Preferences… > Sharing and turn Web Sharing off. Then quit System Preferences.

Doin’ it

1. With TextWrangler, open the hidden, main configuration file for Apache (below, X represents the name of your System hard disk/partition):

X > private > etc > apache2 > httpd.conf

If you have a file from which no early line of code has previously been added or deleted, line 114 should read:

#LoadModule php5_module        libexec/apache2/libphp5.so

2. Uncomment the line by removing the hash (#) character. The line should now read:

LoadModule php5_module        libexec/apache2/libphp5.so

3. Save the file and close it.

Note: If you are curious and open the libphp5.so file (actually, I do not recommend that you do so; the file is a hefty 31 MB and may take a looooooong time to load), you will find references to a file called php.ini. There is, however, no such file to be found among the Apache/PHP default offerings. You will have to make your own based on a file called php.ini.default. David Powers shares more information on this.

4. Open the hidden, default php.ini file here:

X > private > etc > php.ini.default

5. Scroll down to line 305 and change it from:

error_reporting  =  E_ALL & ~E_NOTICE

to:

error_reporting  =  E_ALL

This will eventually show all errors including notices and coding standards warnings. Good for debugging! More details are available at php.net.

6. Save the modified file as php.ini. As you will discover, you are not allowed to save this document directly to the etc directory. You will have to temporarily save to another location. Do it!

7. In Finder, invoke Go > Go to Folder… and type/enter:

/private/etc/

Manually, drag a copy of php.ini from its temporary resting place into the etc folder. Authenticate, and trash the temporary document. Time for testing.

8. Turn Web sharing (aka Apache) on.

9. Create a plain text document with the following:

<?php phpinfo(); ?>

Important: As this guide builds on a preceding Apache tutorial, you will make use of a virtual host already created, when you test the PHP configuration.

10. Save the document with a php suffix, e.g., info.php, to, e.g., the Cochise folder.

11. Enter the following address into your browser:

cochise/info.php

If you are presented with a page detailing the PHP version number and several configuration settings, everything is hunky-dory. If not, you will have to backtrack.

Conclusion

To sum it all up, only two steps are involved in adding PHP functionality to your local web server:

  1. Modify httpd.conf
  2. Create php.ini

  Leave a comment