Apache Web-Serving with Mac OS X: Part 3
by Kevin Hemenway01/04/2002
Editor's note: In the first part of this series, Kevin showed you how to easily start serving Web pages from your Mac OS X computer. In the second article, he explored the world of CGI access. Today, he moves forward with a look at PHP.
Turning on PHP4
We're on the last legs of our trip down Feature Lane, Impressiville. This will be the easiest section of our journey, mainly because we'll be going through the paces based on what we already know. Much like CGI, PHP is very popular and well supported, and very often installed on Web hosts by default. Much like SSI, the code is included and interpreted into the actual HTML of your Web pages.
Just like our other sections on CGI and SSI, turning on PHP involves searching for the feature name ("php") within our Apache configuration file. The first entries we come up against are:
# LoadModule php4_module libexec/httpd/libphp4.so
# AddModule mod_php4.c
These lines are just like those we encountered when we were messing around with CGIs -- they enable or disable the loading of PHP on a restart of our Apache Web server. Since they're commented with that little "#" character, we've got to remove the "#" to enable them. Do that now.
Moving on to our next search result, we see:
# For example, the PHP 3.x module will typically use:
#
# AddType application/x-httpd-php3 .php3
# AddType application/x-httpd-php3-source .phps
#
# And for PHP 4.x, use:
#
# AddType application/x-httpd-php .php
# AddType application/x-httpd-php-source .phps
|
|
We saw these same sorts of lines when we were enabling
SSI. In essence, they're saying that any file with the .php extension should
be processed by the PHP module we just enabled. As we'll see soon enough, Mac OS X (versions 10.1 and above) comes pre-installed with PHP 4, so go ahead and uncomment the two "for
PHP 4.x" lines. Save the Apache configuration file, and stop and start the
Web server using the "Sharing" preference panel.
We're going to return to our Apache error log for a second to illustrate a simple, yet helpful bit of information. Each time you start Apache, it will spit out a single line telling you that everything has started successfully. Often times, it will look like so:
[notice] Apache/1.3.20 (Darwin) configured
-- resuming normal operations
When you add a third party module or feature
(like PHP, mod_perl, mod_ssl, etc.), Apache will graciously make mention of it in its startup line.
If you just restarted the Apache Web server now, take a look at the error
log by typing:
tail /var/log/httpd/error_log
You should see Apache wax poetic with:
[notice] Apache/1.3.20 (Darwin) PHP/4.0.6
configured -- resuming normal operations
Apache tells us
that PHP is enabled, but how do we really know for sure? Rather easily,
actually. Take that index.shtml file that we were testing SSIs with, and
rename it to index.php. Now, replace the contents with the
following:
<html><body>
<h1>Gleefully Served By Mac OS X</h1>
<? phpinfo()?>
</body></html>
Finally, go to
http://127.0.0.1/index.php and you should see a long page full of PHP
diagnostic information. If so, rub your hands with a gleam in your eye,
because PHP has now been added to your arsenal. Want to add a simple Web-based email program for your traveling coworkers? Check out PHPost. Note: Most PHP
applications require a sophisticated database backend, like MySQL or
Postgres -- PHPost is one of the few that doesn't. While installing and
configuring these database systems is relatively easy on Mac OS X, it would be
outside the scope of this primer. Want to see an article on this? Let us know by commenting below.
Choosing Who Sees What
|
| |
It's five in the morning. You've gone through three six packs of soda, two tins of Penguin Reds, and an untold number of delicious snacky treats. You've got a CGI poll script ready to quiz the employees on the menu for the next company picnic, an SSI image gallery that happily sends the marketing department into a drool-dripping feature panic, and a PHP app with which your developers can track and monitor their sloppy code.
Now what?
After all you've done, something rather minor. We've just got to throw a little access control on our spunky new intranet -- we wouldn't want the outside world seeing the insanely great job we've done (we'd rather wait and show them the really cool stuff we're gonna do on our personal time, right? Wink, wink, nudge, nudge).
While Apache can certainly handle authenticated access control, we're only going to touch on the location-based side of it. To do so, we're going to return to a snippet of configuration file that we've messed around with before, back when we were enabling SSIs:
<Directory "/Library/WebServer/Documents">
Options Includes Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
I mentioned we'd eventually touch on the remaining lines, and now is said
time (although, we're still going to rudely skip AllowOverride). Quite
simply, the "Order allow, deny" and "Allow from all" lines are the magic
that will stop outside visitors from perusing our intranet. Right now, as
these lines stand, our intranet is wide open to the public.
This is what we're going to end up with:
<Directory "/Library/WebServer/Documents">
Options Includes Indexes FollowSymLinks MultiViews
AllowOverride None
Order deny,allow
Deny from all
Allow from gatesmcfaddenco.org
</Directory>
See what we've done here? The first thing we did is flip our "Order" directive. This tells Apache to process all "Deny" rules first, and then all the remaining "Allow" rules. Likewise, our first "Deny" is "from all," meaning no one can come knocking. If we denied everyone, of course, no one would be able to see our Macstrosity (rather phenomic, eh?), so we add an "Allow" rule for our GatesMcFaddenCo domain. We can also allow and deny by IP, like "Allow from 209.204.146". This will allow access to anyone from within the GatesMcFaddenCo network, but no one from without.
Conclusion
Before you know it, it's seven in the morning and time to show off your efforts. You're confident, feigning a yawn of boredom, not sleepiness. As the morning sun glints off the silver of your glorious G4 tower, you smile privately -- as has been typical since time began, doing something amazing on the Mac has been incredibly simple. Your boss is impressed, your coworkers are disbelieving, and you're signing a purchase order for the newest mystery item from MacWorld. Oh, life is good.
Don't think we've exhausted everything Apache and Mac OS X has to offer, though. You still
haven't touched mod_ssl, which allows secure server capabilities, nor have
you fiddled with mod_perl, which can speed up your CGI scripts immensely.
You haven't touched the authentication capabilities of Apache's access
control, or even tweaked Apache's configuration with .htaccess files. And
sadly, if someone types in a bad URL for your intranet, you still get an
ugly and generic 404 page.
Only 7:30? Plenty of time to bust those out before lunch. Good luck!
Kevin Hemenway is the coauthor of Mac OS X Hacks, author of Spidering Hacks, and the alter ego of the pervasively strange Morbus Iff, creator of disobey.com, which bills itself as "content for the discontented."
-
php 5 instructions
2009-12-28 13:55:48 stumpygreg [View]
-
index.php
2005-06-27 15:00:03 TWizard [View]
-
index.php
2005-06-27 15:00:55 TWizard [View]
-
so easy - but . . .
2005-02-22 12:55:54 videomike [View]
-
so easy - but . . .
2008-01-11 09:01:26 ludwig_von_rocht [View]
-
mac,php and variables
2004-09-01 04:52:53 flashsmurf [View]
-
PHP HTML parsing problem
2003-06-19 16:57:31 enderws [View]
-
PHP HTML parsing problem
2003-08-16 16:36:04 anonymous2 [View]
-
My vote for an article!
2003-05-30 16:29:37 anonymous2 [View]
-
php AND ssi?
2003-03-26 06:01:55 anonymous2 [View]
-
php AND ssi?
2003-03-26 06:19:31 Kevin Hemenway |
[View]
-
php AND ssi?
2003-04-02 03:37:25 anonymous2 [View]
-
PHP Nodice. Failed Opening?
2003-01-30 20:16:46 bucky4d4s [View]
-
PHP Nodice. Failed Opening?
2003-12-30 07:03:17 anonymous2 [View]
-
PHP Nodice. Failed Opening?
2003-04-16 06:10:40 anonymous2 [View]
-
Apache-PHP
2002-11-23 07:03:35 anonymous2 [View]
-
Apache-PHP
2002-12-31 06:05:34 khasmir [View]
-
Pbs with PHP on OS X.2
2002-11-23 06:08:51 anonymous2 [View]
-
Pbs with PHP on OS X.2
2002-12-31 06:07:03 khasmir [View]
-
phpInfo() showing my password
2002-11-14 20:15:13 anonymous2 [View]
-
phpInfo() showing my password
2003-06-05 01:25:19 anonymous2 [View]
-
MySQL or Postgres Please
2002-11-04 11:51:25 anonymous2 [View]
-
PHPost...
2002-11-03 08:40:43 anonymous2 [View]
-
Automatic PHP tasks
2002-10-28 13:44:25 anonymous2 [View]
-
Automatic PHP tasks
2002-10-28 16:50:45 anonymous2 [View]
-
Automatic PHP tasks
2002-10-28 17:00:00 anonymous2 [View]
-
i'm missing some lines in my httpd.conf
2002-10-27 21:45:27 anonymous2 [View]
-
SOLUTION for OSX 10.2.x users (the missing lines)
2002-12-10 16:07:08 tronje [View]
-
php paths
2002-10-23 07:46:38 anonymous2 [View]
-
php paths
2003-08-02 21:20:09 anonymous2 [View]
-
*To anyone running Jaguar*
2002-10-09 13:03:42 anonymous2 [View]
-
*To anyone running Jaguar*
2002-10-10 16:06:49 sckz [View]
-
*To anyone running Jaguar*
2003-01-30 00:05:51 anonymous2 [View]
-
PHP doesn't work but IS installed
2002-09-30 05:27:17 sckz [View]
-
PHP is running, but scrambles HTML and shows up in Source-Code???
2002-09-26 09:56:37 anonymous2 [View]
-
PHP is running, but scrambles HTML and shows up in Source-Code???
2002-10-01 17:53:39 philocon [View]
-
Re: PHP and Apache on Jacuar (OSX 10.2)
2002-09-22 13:25:16 anonymous2 [View]
-
Tomcat + Apache
2002-09-22 10:13:13 anonymous2 [View]
-
Apache + php + jaguar = no go?
2002-09-18 06:24:34 anonymous2 [View]
-
Apache + php + jaguar = no go?
2002-09-26 05:51:14 philocon [View]
-
Apache + php + jaguar = no go?
2002-09-26 05:56:30 philocon [View]
-
PHPost Permissions fix
2002-09-13 12:28:50 rymes60 [View]
-
PHP and Apache on Jacuar (OSX 10.2)
2002-09-12 07:55:48 anonymous2 [View]
-
PHP and Apache on Jacuar (OSX 10.2)
2002-12-31 06:08:04 khasmir [View]
-
HELP!!! Installed PHP now can't start Apache!
2002-09-11 09:09:08 sat150 [View]
-
RE: Where is my error???
2002-09-02 15:42:28 insomnis [View]
-
Where is my error???
2002-08-12 14:23:00 arellano [View]
-
Where is my error???
2002-08-12 14:18:35 arellano [View]
-
Paste in LoadModule/AddModuleLines
2002-08-04 16:43:56 bobmoore [View]
-
Paste in LoadModule/AddModuleLines
2002-09-15 15:29:15 timbrooke [View]
-
edit PHP default settings
2002-07-19 20:57:23 cyndical [View]
-
Permission problems
2002-07-05 06:19:35 morteniv [View]
-
Permission problems
2002-12-06 16:25:17 anonymous2 [View]
-
I don't have an index.php file
2002-05-11 13:17:50 mknauf [View]
-
I don't have an index.php file
2002-08-12 14:25:30 arellano [View]
-
problem with Volumes
2002-05-07 01:38:35 wilseven [View]
-
Missing LoadModule/AddModule Lines
2002-04-09 15:52:10 d_simmons [View]
-
Missing LoadModule/AddModule Lines
2002-04-16 17:14:10 Kevin Hemenway |
[View]
-
Help!!! Error in the httpd file
2002-04-07 23:37:29 plastic1 [View]
-
Help!!! Error in the httpd file
2002-04-16 17:09:01 Kevin Hemenway |
[View]
-
PostgreSQL
2002-03-30 10:57:47 Michael Brewer | [View]
-
PostgreSQL
2002-06-11 11:01:06 wbug [View]
-
Should this work on osX 10.1.3 ?
2002-03-27 03:19:55 sba [View]
-
Should this work on osX 10.1.3 ?
2002-03-26 16:56:33 sba [View]
-
Allow from....
2002-03-22 03:38:26 redleader [View]
-
Allow from....
2002-03-22 09:02:04 Kevin Hemenway |
[View]
-
tutorial on MySQL please
2002-03-20 20:57:38 clappazon [View]
-
tutorial on MySQL please
2002-03-22 08:58:29 Kevin Hemenway |
[View]
-
index.php empty
2002-03-19 19:16:08 driftkop [View]
-
index.php empty
2002-03-19 10:52:37 driftkop [View]
-
index.php empty
2002-03-19 14:15:23 Kevin Hemenway |
[View]
-
no access through 127.0.0.1
2002-03-15 08:06:42 axel_vogelsang [View]
-
no access through 127.0.0.1
2002-03-15 12:22:10 Kevin Hemenway |
[View]
-
phpost pop connection fails
2002-03-01 19:42:31 dicklacara [View]
-
PHP.INI
2002-02-27 12:35:21 kuacweb [View]
-
PHP.INI
2003-06-29 08:00:18 anole [View]
-
PHP.INI
2002-03-02 06:14:16 kkohler [View]
-
rebol meets apache on MacOS X
2002-02-26 12:38:26 usaps [View]
-
Appreciation
2002-02-24 17:58:43 mgoins11 [View]
-
Installing the imap extension for php
2002-02-23 04:11:18 kkohler [View]
-
Installing the imap extension for php
2002-02-25 08:26:54 Kevin Hemenway |
[View]
-
Outside users can't connect
2002-02-03 00:22:04 audiophyle [View]
-
Outside users can't connect - me too
2002-02-03 03:26:06 pattyb777 [View]
-
Web Server won't start - please help
2002-02-02 14:32:51 pattyb777 [View]
-
Web Server won't start - please help
2002-02-02 21:23:01 rudar [View]
-
checked back up file - d'oh!
2002-02-03 03:23:04 pattyb777 [View]
-
Why two httpd.conf files?
2002-02-01 12:14:56 galt606 [View]
-
Why two httpd.conf files?
2002-02-01 14:37:21 Kevin Hemenway |
[View]
-
PHPost works - but does not display correctly
2002-01-30 14:29:07 cpaulu [View]
-
PHPost works - but does not display correctly
2002-01-31 14:43:49 Kevin Hemenway |
[View]
-
Missing LoadModule php4
2002-01-30 09:17:51 stepgo [View]
-
OK we can add these....
2002-01-30 09:23:27 stepgo [View]
-
OK we can add these....
2002-01-30 13:56:31 Kevin Hemenway |
[View]
-
Apache to Classic
2002-01-28 10:51:59 fallenaristocrat [View]
-
Apache to Classic
2002-01-28 11:16:00 Kevin Hemenway |
[View]
-
Apache to Classic
2002-01-29 08:44:05 fallenaristocrat [View]
-
please do an article on mysql on osx
2002-01-26 13:43:25 dan@visual-contact.com [View]
-
i have a question
2003-07-14 18:10:11 anonymous2 [View]
-
please do an article on mysql on osx
2002-02-03 13:09:58 brucefor [View]
-
Apache Web-Serving-Mac OS X: Part: ALL
2002-01-26 13:12:35 hylas [View]
-
Another vote to continue
2002-01-23 15:12:26 djwudi [View]
-
Linux and X Windows programs
2002-01-22 17:46:38 skinnywhitegeek [View]
-
Linux and X Windows programs
2003-07-26 00:21:35 anonymous2 [View]
-
Excellent series by the way
2002-01-22 17:48:05 skinnywhitegeek [View]
-
PHPost
2002-01-18 14:42:43 radionerd [View]
-
PHPost
2002-01-20 13:15:25 Kevin Hemenway |
[View]
-
PHPost
2002-01-21 13:00:09 radionerd [View]
-
Let's get to MySQL!!
2002-01-18 13:42:46 radionerd [View]
-
Let's get to MySQL!!
2002-03-04 18:40:01 ronmtec [View]
-
Try FrontBase (imports direct from FM)...
2002-01-30 14:57:42 mmalc [View]
-
You can do PostgreSQL right now
2002-01-26 05:04:58 fitz22 [View]
-
My config file is different
2002-01-18 13:40:29 radionerd [View]
-
My config file is different
2002-01-30 09:21:15 stepgo [View]
-
NEVERMIND
2002-01-18 13:44:46 radionerd [View]
-
GatesMcFaddenCo must Live!
2002-01-17 07:42:51 haligan [View]
-
GatesMcFaddenCo must Live!
2002-01-17 10:05:54 Kevin Hemenway |
[View]
-
Yes, please do a MySQL w/ Apache article
2002-01-16 17:43:18 donncha [View]
-
Yes, please do a MySQL w/ Apache article
2002-02-02 14:21:07 pattyb777 [View]
-
Can't activate PHP4
2002-01-14 07:16:42 hammer09 [View]
-
Can't activate PHP4
2002-01-14 12:57:11 Kevin Hemenway |
[View]
-
RE:Can't activate PHP4
2002-01-15 09:55:26 hammer09 [View]
-
RE:Can't activate PHP4
2002-01-15 12:24:52 Kevin Hemenway |
[View]
-
RE:Can't activate PHP4
2002-04-06 10:08:38 scottfeldstein [View]
-
RE:Can't activate PHP4
2002-01-15 09:58:31 hammer09 [View]
-
Please continue this series!
2002-01-11 19:23:45 rkd [View]
-
Please continue this series!
2002-01-16 08:00:27 rmo966 [View]
-
Please continue this series!
2002-01-19 21:51:08 samvenning [View]
-
OS X, Apache and Zope
2002-01-10 05:47:46 martinb9999 [View]
-
OS X, Apache and Zope
2002-01-16 14:30:55 dondi [View]
-
Please continue - best articles on the web!
2002-01-10 03:54:59 bob30 [View]
-
YES YES YES
2002-01-09 19:15:57 josecord [View]
-
YES YES YES
2003-08-19 18:54:37 anonymous2 [View]
-
Please Continue
2002-01-09 12:23:05 eyelet [View]
-
Please continue
2002-01-09 12:20:29 eyelet [View]
-
missing something...
2002-01-08 17:54:21 ryentzer [View]
-
Continue!!!
2002-01-05 23:42:59 Joe [View]
-
more please
2002-01-05 20:58:22 erika1 [View]
-
adding my support
2002-02-11 22:34:32 theg [View]
-
Please continue series!
2002-01-05 11:25:56 cms7912 [View]
-
Please continue series!
2002-01-19 21:54:47 samvenning [View]
-
Continue series!!!
2002-01-05 03:28:05 eatons [View]
-
Apache with OSX
2002-01-05 00:23:15 smithac9 [View]
-
Apache with OSX
2002-01-16 10:20:25 ryentzer [View]


