05.01.2013 Views

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

392<br />

CHAPTER 22 LEOPARD AS A WEB SERVER<br />

PHP<br />

NOTE While disabling the explicit permissions on a user directory will do the job in a roundabout<br />

way, the proper way to enable or disable users is with the UserDir directive. See the<br />

Apache documents for more information.<br />

Whenever you change Apache’s configuration file, you will need to restart Apache. The<br />

easiest way to do this is with Terminal, using the special Apache control program, apachectl.<br />

sudo apachectl -k graceful<br />

This will restart Apache gracefully, which is to say, it will let it finish what it’s doing, shut<br />

down, and then restart.<br />

If you try to restart Apache, but it’s not already running for some reason, it will just start. If<br />

you’ve messed up the configuration file it will usually let you know on restart. Otherwise, you<br />

should be ready to test your changes.<br />

There have been a number of schemes to create dynamic web pages since the Web first came into<br />

being in 1993. Some of these rely on the client to execute. Most notable in this regard are<br />

Dynamic HTML (DHTML) and its modern equivalent, Ajax. While it’s beginning to recover,<br />

client-side scripting has traditionally been hampered by compatibility issues in the aftermath of<br />

the browser wars.<br />

Server-side scripting schemes include CGI and Server Side Includes (SSI). However, both of<br />

these have been largely rendered obsolete by PHP. Unlike CGI and SSI, PHP is a hypertext preprocessor.<br />

That is to say, it’s a page that runs a script, but ultimately serves plain HTML.<br />

Since it is open source, PHP is the preprocessor of choice on UNIX systems running Apache.<br />

Indeed, PHP has been implemented as an Apache module, and comes installed, but not activated,<br />

by default on <strong>Mac</strong> <strong>OS</strong> X.<br />

To properly ensure PHP is installed, we need to have a PHP page. The best test page is a simple<br />

PHP Info page. It relies on PHP to be working, so it’s a good test, and it gives us a lot of<br />

information about our PHP installation, so it’s actually useful.<br />

Create a PHP Info page in your favorite text editor, and save it to your document root as<br />

index.php. All you need to include is a single call to PHP’s built-in phpinfo function:<br />

<br />

Then, load the page in your browser of choice by pointing to http://127.0.0.1/index.php.<br />

You have to point to the page explicitly, because otherwise you’ll get the default index page,<br />

index.html.<br />

NOTE You can, of course, also save the PHP info page to your home Sites directory.<br />

Loading the page in your browser, you’re greeted with the entirety of its source, as written.<br />

That’s because Apache doesn’t know what a .php file is, so it’s serving it as its default MIME<br />

type, text/plain.<br />

To enable PHP, we simply need to uncomment a single line of text from the Apache configuration<br />

file.<br />

#LoadModule php5_module libexec/apache2/libphp5.so<br />

Since it starts with #, it’s a comment and is ignored. Delete the # and save. Back in the day,<br />

we’d also have to tell Apache how to handle the file type and look for index.php by default, but

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!