Apache
From Wiki99
↑ Computers ↑
← prev: Fetchmail
next: SquirrelMail →
Contents |
Introduction
The basic setup of Apache has mostly been done for you by Apple. We are interested in having Apache act as a server for the entire machine, not on behalf of individual users, so we are interested in storing documents in /Library/WebServer/Documents.
Configuring Apache can become complicated if you are interested in various high performance options, or in running multiple web sites on one computer. We, however, are not interested in either of these, so our task is very simple.
Configuring Apache
The file that controls the Apache options we care about is /etc/httpd/httpd.conf. We want to make two types of changes to it.
Activate PHP
The first is to activate PHP. PHP is used by squirrelmail, by mediawiki, and by wordpress. Start by opening /etc/httpd/httpd.conf for editing
Scroll down the file until you get to the line
and remove the initial # which is commenting out the line.
Add comments (but carefully)
You should probably add a comment above this line, something like #MJH (use whatever your initials are) so that you can subsequently find changes you made to this file.
Note that Apache only treats # as a comment marker when it is the first character in a line, so that if you change the line to something like
Apache will consider the file to be invalid, will not parse it, and will not launch. The only way to learn why Apache won't launch in this case is to run Console.app and look through the logs for an error reported by Apache, which will give you the line number of the first line in the config file that it could not parse. What you want is a change like
#MJH activated the line below
(An alternative is to make all your changes to this file at the very end of the file as we have done with with some other config files.)
Now find the line, a few lines down,
and once again remove the initial #, and, if you want, add an #MJH to the line above.
Tell Apache the name of this server
The second set of changes is to let Apache know the name of this server. Keep scrolling down looking for the line
and under this add the line
Keep scrolling down a few more lines to find the line
and under it add the line
Wrapup
Type ctrl-O to save, ctrl-X to exit. Type
to have Apache reread its preferences.
At this point we are done! The essential setup of Apache has been done. We can now wrap up our mail setup by setting up SquirrelMail.
Types of Web Pages
You are probably most used to static web pages, which are text files written in html and with a .html suffix. You can write these and throw them in /Library/WebServer/Documents if you want. The Documents folder comes prepopulated with a number of such files to handle different languages. For those of us who will serve only English web pages, you can throw them all away and create your own top level file called index.html or, if you prefer, index.html.en which will be the front page of your web site, the page that is displayed when someone types the URL http://name99.org in their web browser.
An alternative to static pages is PHP apps. PHP apps come as directory of files.
Each of these apps is slightly different, but they usually work in the same
way:
You drop the entire directory, say squirrelmail, into
/Library/WebServer/Documents, and a user then references the app with
the URL http://bluecloud.com/squirrelmail.
SquirrelMail is unusual (because it speaks to an IMAP server, and these are not 100% standardized), in that you have to configure it a little before you install it. The usual pattern for these apps (including SquirrelMail after the basic initial IMAP setup) is that you launch your web browser with the URL of the app, and a web page will come up that allows you to configure the app.
These apps will usually store preferences in some file within their directory. Per user preferences may be stored in similar files, or in a database. Upgrading these apps can be done by just throwing away the old directory and installing the new directory, but this will lose your preferences, so you may want to write those down or save the prefs file across such upgrades. If you have a good application for finding and displaying differences in files across directories, you may want to diff the new version of the app against the old version to make sure you are saving all the preference state before you do the upgrade. I personally use Metrowerks CodeWarrior for these sort of directory-wide diffs, but this is neither free nor cheap. I'm afraid I don't know of a good freeware or shareware app for doing this.
Improving the performance of Apache
I'm no authority on how to get Apache to run faster. There seem to be a wide variety of issues in this area, and for the purposes of our little home network the default performance is pretty much good enough.
There is, however, one small thing we can do to improve performance slightly that is so simple there's no reason not to do it, which is to give Apache a higher priority. (Recall that we discussed priorities earlier here.)
Giving Apache a higher priority
Apache is (as of Tiger) launched not using launchd but using the older StartupFiles mechanism. (This will probably change with Leopard, but we'll deal with that when it happens.)
The relevant file that describes how Apache is to be launched is
As always, first make a backup of this file
Then open this file so that you can edit it
and look for the line
about 16 lines down the file. Change this to
You can use any niceness value you want; I chose -5 rather than -10 because I figured that if Apple are using niceness values of -10 for software like faxing, I probably don't want Apache interfering with that.
About 5 lines lower, look for the line
and change it to
(You probably don't need to do this since your system probably doesn't have a copy of /usr/sbin/webperfcachectl on it, but we might as well be thorough.)
Scroll down a few lines to the section
and modify the two lines
apachectl restart
/usr/sbin/webperfcachectl restart
in the same way.
Reboot your system and Apache should now be running at this new priority. You can see this by typing
and seeing that all the httpd programs now have niceness -5.
For all this reasons I've given, this won't have dramatic improvements on your Apache performance, but it can't hurt.

