Build Your Own Apache Server with mod_perl
Pages: 1, 2
Testing Your New Apache Build
And now Apache is completely compiled and installed with mod_perl. A quick test confirms that the installation was successful:
% sudo /usr/local/apache/bin/apachectl configtest
Syntax OK
This quick test confirms that Apache compiled properly and loads its default configuration file without error. But it's more interesting to actually get it to serve some Web pages. First, make sure that Apple's version of Apache isn't running by disabling Personal Web Sharing in the Sharing global system preference. Then start up your newly compiled version of Apache:
% sudo /usr/local/apache/bin/apachectl start
/usr/local/apache/bin/apachectl start: httpd started
Now fire up your favorite browser, and type in your Mac's domain name. Localhost will probably work fine. If you see a page that starts with, "Hey, it worked!", then you're in business.
Testing mod_perl
As the final part of this process, we confirm to ourselves for the sake of
our own sanity, that mod_perl is functioning properly, too. Fortunately this
is rather simple to do as mod_perl includes a module we can easily use for
this purpose. The Apache::Status module is designed to display information
about the status of your Apache Web server, as well as mod_perl itself. To use
it, simply edit the default Apache configuration
file, /usr/local/apache/conf/httpd.conf, and add these lines to
it:
PerlModule Apache::Status
<Location /perl-status>
SetHandler perl-script
PerlHandler Apache::Status
</Location>
Restart Apache so that it loads the new module:
% sudo /usr/local/apache/bin/apachectl restart
/usr/local/apache/bin/apachectl restart: httpd restarted
Now hit your Web server again, this time entering the "perl-status" directory name, e.g, http://localhost/perl-status/. You should see a page appear with something like this at the top:
Embedded Perl version v5.8.0 for Apache/1.3.26 (Darwin) mod_perl/1.27 process 12365,
running since Thu Sep 19 01:05:43 2002
Apache Startup Bundle
Having a working Apache is all well and good but not worth much unless it's running. If you'd like your Mac OS X box to function as a Web server all the time, you might want to create a startup bundle for it. Apple has documented a specification for startup bundles in its Creating SystemStarter Startup Item Bundles HOWTO, but it's a simple matter to adapt Mac OS X's existing Apache startup bundle for our purposes.
Apple has created the /System/Library directory structure for
use by the Mac OS X operating system, and the /Library directory
structure for use by third party applications such as our new Apache server.
All system startup bundles, including for Apple's build of Apache, go into
the /System/Library/StartupItems directory. The startup bundles
for third-party applications go into the
/Library/StartupItems directory. So to adapt Apple's Apache
startup bundle, we'll first copy it to a temporary location. Later, we'll move
the copy to its new home:
% cp -rf /System/Library/StartupItems/Apache \
~/Desktop/
This command will copy the entire Apache startup bundle directory structure
to the desktop where we can easily edit it. Next, using your favorite editor
(TextEdit will work fine), open up the
~/Desktop/Apache/Apache file. The parts we're interested in look
like this:
StartService ()
{
if [ "${WEBSERVER:=-NO-}" = "-YES-" ]; then
ConsoleMessage "Starting Apache web server"
apachectl start
fi
}
StopService ()
{
ConsoleMessage "Stopping Apache web server"
apachectl stop
}
RestartService ()
{
if [ "${WEBSERVER:=-NO-}" = "-YES-" ]; then
ConsoleMessage "Restarting Apache web server"
apachectl restart
else
StopService
fi
}
This file is a Unix Bourne shell script and is executed whenever your Mac
starts up and shuts down. There are essentially two changes we need to make to
convert this script for starting our newly compiled Apache server. The first
is to remove all of the if statements. These statements
programmatically test for a variable that gets set by the Personal Web
Sharing check box in the Sharing system preference. Since our
server won't handle Personal Web Sharing, we won't be needing these tests. The
second change we need to make is to change the location of
the apachectl startup script. Just calling apachectl
will cause Apple's Apache server to start up. To get our new one to start, we
need to change the location to /usr/local/apache/bin/apachectl.
The result of our changes to the startup script looks like this:
StartService ()
{
ConsoleMessage "Starting Apache web server"
/usr/local/apache/bin/apachectl start
}
StopService ()
{
ConsoleMessage "Stopping Apache web server"
/usr/local/apache/bin/apachectl stop
}
RestartService ()
{
ConsoleMessage "Restarting Apache web server"
/usr/local/apache/bin/apachectl restart
}
Now all that's left is to move the entire startup bundle to its new
home in /Library/StartupItems and test it:
% sudo mv ~/Desktop/Apache /Library/StartupItems
% sudo /Library/StartupItems/Apache/Apache start
Starting Apache web server
/usr/local/apache/bin/apachectl start: httpd started
Point your browser to your local computer again and make sure a page loads. If it does, you're in business, and the Apache server will be started whenever you boot into Mac OS X.
Next Up: mod_ssl
I hope that this article has served as a gentle introduction to compiling your own Apache server on Mac OS X. However, as I've suggested, there's a great deal more you can do when building Apache.
In part two of this article, I'll go back over this process, assisting you to compile support for the mod_ssl Apache module. This module allows Apache to encrypt communications with browsers using SSL, the secure sockets layer. Any time you securely connect to a Web site, for example, to complete a credit card transaction at Amazon.com, your browser communicates with the server via SSL. If you find you need to develop Web applications that use SSL, tune in to part two of this article to learn how to add SSL support to your custom build of Apache.
David Wheeler is a developer at Portland, Oregon-based Values of n, where he writes the code that makes Stikkit's little yellow notes think.
Return to Mac DevCenter
-
302 Messages
2003-11-26 18:01:34 cshannon [View]
-
302 Messages
2003-11-30 09:19:37 David Wheeler |
[View]
-
302 Messages
2003-12-02 11:38:00 cshannon [View]
-
MP_APXS MP_AP_PREFIX
2003-11-24 09:44:08 anonymous2 [View]
-
MP_APXS MP_AP_PREFIX
2003-11-24 09:57:21 anonymous2 [View]
-
MP_APXS MP_AP_PREFIX
2003-11-24 09:59:30 David Wheeler |
[View]
-
can't run scripts with Apache::Registry
2003-10-10 18:11:53 dstone27 [View]
-
can't run scripts with Apache::Registry
2003-10-24 16:17:26 David Wheeler |
[View]
-
Problem after installing perl 5.8
2003-07-30 18:51:40 bradpuett [View]
-
Problem after installing perl 5.8
2003-07-30 19:09:21 David Wheeler |
[View]
-
TestMM.pm
2003-06-13 19:58:01 goldenmean [View]
-
TestMM.pm
2003-07-01 13:50:25 anonymous2 [View]
-
apreq patch not needed for 10.2
2003-06-10 00:34:08 anonymous2 [View]
-
apreq patch not needed for 10.2
2003-06-10 08:04:00 anonymous2 [View]
-
which Perl directory structure to choose? Apple or standard?
2003-04-19 21:59:32 anonymous2 [View]
-
which Perl directory structure to choose? Apple or standard?
2003-04-21 08:00:26 David Wheeler |
[View]
-
I completally doubt I will get any help but...
2003-04-09 05:40:41 anonymous2 [View]
-
Re: I completally doubt I will get any help but...
2003-04-09 16:34:16 David Wheeler |
[View]
-
Use ApacheBuilder
2003-02-14 08:13:05 anonymous2 [View]
-
Controlling the Firewall
2002-12-08 05:09:34 anonymous2 [View]
-
Re: Controlling the Firewall
2002-12-11 16:10:22 David Wheeler |
[View]
-
Connection refused(newbie needs help)
2002-11-29 22:26:35 dfoley1 [View]
-
Connection refused(newbie needs help)
2002-12-06 16:17:39 mr_chuckle [View]
-
Thanks !
2002-12-07 00:50:04 dfoley1 [View]
-
A final step with with apreq.
2002-11-18 20:30:38 bspage [View]
-
A final step with with apreq.
2002-11-24 13:51:58 David Wheeler |
[View]
-
Perl 5.8.0 - a few extra tips
2002-11-11 13:27:13 germuska [View]
-
Why replace the Personal Web Sharing tests?
2002-11-10 10:23:11 anonymous2 [View]
-
Re: Why replace the Personal Web Sharing tests?
2004-01-12 10:28:01 David Wheeler |
[View]
-
Why replace the Personal Web Sharing tests?
2003-04-21 10:00:52 anonymous2 [View]
-
Why replace the Personal Web Sharing tests?
2002-11-11 13:23:19 David Wheeler |
[View]
-
Why replace the Personal Web Sharing tests?
2004-01-10 16:32:43 anonymous2 [View]
-
Why replace the Personal Web Sharing tests?
2004-01-12 10:29:08 David Wheeler |
[View]
-
or...
2002-11-05 15:31:21 anonymous2 [View]
-
or...
2003-04-12 17:12:04 anonymous2 [View]
-
or...
2002-11-11 13:07:06 David Wheeler |
[View]

