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 E. 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
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 36 of 36.
-
302 Messages
2003-11-26 18:01:34 cshannon [Reply | View]
-
302 Messages
2003-11-30 09:19:37 Theory [Reply | View]
-
302 Messages
2003-12-02 11:38:00 cshannon [Reply | View]
Yeah, I saw that already. Believe me, I've been all over Google for days before posting here. My CGI.pm is up to date, according to CPAN. I'm not near my system, but will have to check version of CGI when I can. I'll take another look at that message to see if there's something I've missed, but so far, the only thing that worked was using LWP to get the page , then print its content back to the screen. I've tried printing headers, not printing, turning off PerlSendHeader, turning it on - nothing gives me the desired result. Thanks for the response.
-
MP_APXS MP_AP_PREFIX
2003-11-24 09:44:08 anonymous2 [Reply | View]
When I try to run the Makefile.PL for mod_perl-1.99_11 (perl is 5.8.0) and use ../apache_1.3.29/src for APACHE_SRC, I get the following error:
!!! Unable to determine server version, aborting.
!!! Please specify MP_APXS or MP_AP_PREFIX.
Am I working with incompatible versions since they are different from the article's, or do I need to set additional parameters in the Makefile command? Thanks for any info.
-
can't run scripts with Apache::Registry
2003-10-10 18:11:53 dstone27 [Reply | View]
Ok, I've followed this tutorial and seem to have it all working. I can run the perl-status script. It brings up several links. I click on 'Loaded Modules' and then it brings up a list Apache::Connection, Apache::Constants and quite a few others. If I click on any of those it says: Please install Devel::Symdump which I loaded via -MCPAN -e install 'Devel::Symdump' and it still returns the same: Please install etc.
Then I try using Apache::Registry following another tutorial (http://www.osxfaq.com/man/3/Apache--Registry.wsc) by placing the following in my httpd.conf:
#----------------------------------------
Alias /perl/ /usr/local/apache/perl/
<Location /perl>
SetHandler perl-script
PerlHandler Apache::Registry
PerlSendHeader On
Options +ExecCGI
</Location>
#--------------------------------------
and making the appropriate directory and loading a test "hello world" test script. I restart the server and hit http://localhost/perl/test1.pl (the name of the script) and it won't work. I get 'page can't be found' error from my browser. I've set permissions on the file to 755 and 777 for the /perl directory and restarted the server but no luck. I know there are security issues with my perm settings but will twek those later. I'd also like some info on how to change the user running apache, currently it is running as root which I've heard is also a security issue. Any guidance would be great as I'd love to start developing my site. Thanks
-
can't run scripts with Apache::Registry
2003-10-24 16:17:26 Theory [Reply | View]
Try loading Devel::Symdump in your httpc.conf:
PerlModule Devel::Symdump
Not sure what's up with your Apache::Registry script; it sounds right to me. But I can tell you that Apache is supposed to start up as root. But it then forks off its children and assigns them to the user "nobody", which should reduce security issues.
HTH,
David
-
Problem after installing perl 5.8
2003-07-30 18:51:40 bradpuett [Reply | View]
I've tried to install mod_perl (and libapreq) several times, but I'm still having problems ...
So, I started from the beginning and installed Perl 5.8.0; however, when I tried to install "Apache::Test" via CPAN, I received this error message:
cpan> install Apache::Test
Running install for module Apache::Test
Running make for S/ST/STAS/Apache-Test-1.03.tar.gz
Checksum for ~<myid>/.cpan/sources/authors/id/S/ST/STAS/Apache-Test-1.03.tar.gz ok
.
.
.
CPAN.pm: Going to build S/ST/STAS/Apache-Test-1.03.tar.gz
generating script t/TEST
Checking if your kit is complete...
Looks good
!!! Makefile.PL has found old copies of Apache/test.pm which will be removed during 'make install' to prevent collisions with Apache::Test:
.
.
.
/usr/sbin/httpd -X -d ~<myid>/.cpan/build/Apache-Test-1.03/t -f ~<myid>/.cpan/build/Apache-Test-1.03/t/conf/httpd.conf -DAPACHE1
using Apache/1.3.27
waiting for server to start: .............................................................
waiting for server to start: giving up after 61 secs
!!! server failed to start! (please examine t/logs/error_log)
make: *** [run_tests] Error 1
/usr/bin/make test -- NOT OK
Running make install
make test had returned bad status, won't install without force
cpan> quit
Looking at "t/logs/error_log":
[Wed Jul 30 20:48:00 2003] [info] (2)No such file or directory: mod_rendezvous: First Init, ignoring...
[Wed Jul 30 20:48:00 2003] [debug] mod_rendezvous_apple.c(1012): mod_rendezvous_apple: Module init count=1 pid=2524.
dyld: /usr/sbin/httpd Undefined symbols:
_perl_init_i18nl10n
Normally, that should mean I have the infamous "head vs HEAD" problem. However, when I check for the locations of each "head":
% which head
/usr/bin/head
%which HEAD
/usr/local/bin/HEAD
HOWEVER, a find shows this:
% sudo find / -name "[Hh][Ee][Aa][Dd]" -print
/usr/bin/head
/usr/local/bin/HEAD
~<myid>/.cpan/build/libwww-perl-5.69/bin/HEAD
~<myid>/.cpan/build/libwww-perl-5.69/blib/script/HEAD
Is this enough information to determine how to fix this? If so, could I get specific instructions on how to fix this?
Thanks!!
-
TestMM.pm
2003-06-13 19:58:01 goldenmean [Reply | View]
When I attempt to install libapreq, I get an error message that perl cannot locate TestMM.pm in the @INC list of paths. I have installed the LWP and URI modules, but where can I get this TestMM script and where should I install it? -
TestMM.pm
2003-07-01 13:50:25 anonymous2 [Reply | View]
After receiving an e-mail from David Wheeler, he suggested the following:
You need to install Apache::Test from CPAN:
perl -MCPAN -e 'install Apache::Test'
Then all should go well. Apache::Test replaces Apache::test, but CPAN should to the right thing vis-à-vis case insensitivity.
Hope that helps
-Mark Oehlberg
-
apreq patch not needed for 10.2
2003-06-10 00:34:08 anonymous2 [Reply | View]
According to the INSTALL.MacOSX file in the latest libapreq distribution, 10.2 systems do NOT need to apply the patch referred to in the article. Only 10.1 systems need apply. -
apreq patch not needed for 10.2
2003-06-10 08:04:00 anonymous2 [Reply | View]
Right, that's why the editor's note at the beginning of this article points to Installing libapreq on Jaguar: An Update. Check it out. :-)
--David
-
which Perl directory structure to choose? Apple or standard?
2003-04-19 21:59:32 anonymous2 [Reply | View]
while installing Perl 5.8 there is an option to configure it to use the Apple directory structure or the standard Perl directory structure.
What are the pros and cons of each choice?
Thanks
eric rehnke
eric at rehnke dot net -
which Perl directory structure to choose? Apple or standard?
2003-04-21 08:00:26 Theory [Reply | View]
I think that, by default, it will use the Apple Perl directory structure. This will effectively replace Perl 5.6.0 on your system. Most experienced Perl users on Mac OS X don't recommend this, however, as there are system scripts that rely on Perl 5.6.0, and if you don't remove all of the existing C-based Perl 5.6.0 modules, you're much more likely to run into dyld errors. I personally install it in
/usr/localand completely ignore the old Perl. If you decide to install Perl in/usr/local, however, I strongly recommend that you compile and install another library, such as exapt, in that directory tree, first. That way, Perl will see that the appropriatelibandincludedirectories exist when you try to compile Perl modules that rely on those directories, such as XML::Parser.
HTH,
David
-
I completally doubt I will get any help but...
2003-04-09 05:40:41 anonymous2 [Reply | View]
This article is pretty old. But on the off chance... I think I skrewed up my install. There is no usr/local/modperl! I don't know what to do. I think I should uninstall it but I can't find any documentation on how to do it. I botched the
% cd ../mod_perl-1.27
% perl Makefile.PL \
APACHE_SRC=../apache_1.3.26/src \
NO_HTTPD=1 \
USE_APACI=1 \
PREP_HTTPD=1 \
EVERYTHING=1
I tried entering it all in one line at a time, which mad it go off and running with the first line. Then I tired keeping all of the lines together but having a space between each command.
Help.
Ugh. -
Re: I completally doubt I will get any help but...
2003-04-09 16:34:16 Theory [Reply | View]
make uninstallshould work. But FWIW, mod_perl doesn't get installed as/usr/local/mod_perl. It's a Perl module, and gets installed where other Perl modules get installed. Typeperldoc mod_perl, and if you get a man page, it's installed.
HTH,
David
-
Use ApacheBuilder
2003-02-14 08:13:05 anonymous2 [Reply | View]
The sourceforge project 'ApacheBuilder' at apachebuilder.sourceforge.net is a project that does all this for you. You edit the top of the script to set installation directory and other config info, and then execute the script. A fully functioning, configured Apache with Mod_Perl and Mod_SSL is set up for you.
It's beta software, so there are probably some config options that aren't intuitive yet, but it's CVS'd so you can make the changes or suggest them to the project manager.
I've used it and had to change a line of code here and there but it worked pretty good and I could see what functions it was performing.
-
Controlling the Firewall
2002-12-08 05:09:34 anonymous2 [Reply | View]
How do you control the firewall access when you've compiled your own version of Apache? I had previously successfully built Apache and then added a startup item using this article. Then to allow access to the web server through the firewall, I would turn personal web sharing on in system prefences and, consequently, the linked firewall access to only allow access to the http ports. The system hangs up trying to start the default apache, as it should, but then seems to stop trying to start apache and shuts down the firewall access after a given period of time. I'm using 10.2.2. What else can I do to allow firewall access to only http ports? -
Re: Controlling the Firewall
2002-12-11 16:10:22 Theory [Reply | View]
I personally don't allow access to port 80 on my Mac, because I only use it for personal development. However, looking at the Firewall settings, it looks as though they're specifically geared for Apple's build of Apache. While there may well be a way to change some configuration file to get Apple's firewall to allow access to your custom build of Apache on port 80, if you're really serious about needing firewalling, you're better off using an external device to act as the firewall, rather than rely on Apple's software filewall.
Such is what I've done for my production server. I have a LinkSys router that allows me to set which computer inside the firewall responds to external requests on port 80. With such a device you'd be able to set it to forward port 80 requests to your Mac with its ccustom build of Apache, while not worrying about the Apple firewall software's special cases.
HTH,
David
-
Connection refused(newbie needs help)
2002-11-29 22:26:35 dfoley1 [Reply | View]
I followed all the steps(including the bit about apreq in the earlier post), and everything seemed to build fine. Apache starts ok and if I run top I can see it's running.
But when I point my browser at localhost or 127.0.0.1, I get a "Connection refused..." message. Any hints as to where to look for problems? -
Connection refused(newbie needs help)
2002-12-06 16:17:39 mr_chuckle [Reply | View]
For some reason the default http.conf is set to listen on port 8080 so try http://127.0.0.1:8080.
If you change the config to use port 80 you'll have to start apache as root. But be careful as this will conflict with the default Mac OS X apache install.
Good luck.
-
A final step with with apreq.
2002-11-18 20:30:38 bspage [Reply | View]
I found the following step to be necessary after completing the Apache+mod_perl installation
(from http://www.apache.org/~joes/ ):
% tar xzvf apreq.tar.gz
% cd httpd-apreq
% perl Makefile.PL
% make && make install
The article included downloading apreq.tar.gz, but not the installation.
-
A final step with with apreq.
2002-11-24 13:51:58 Theory [Reply | View]
You're so right! I'm not sure how I forgot to include these instructions, but you're right that they're essential. Fortunately, there are no gotchas with compiling and installing apreq, and the directions you provide should work beautifully. Thanks!
David
-
Perl 5.8.0 - a few extra tips
2002-11-11 13:27:13 germuska [Reply | View]
I started with that Apple page referenced in the article. I came upon some undefined symbol problems, and these two pages bailed me out -- posting in case anyone else needs 'em:
First, if you have Fink installed, you may have extra libraries compiled against Perl 5.6 that you "forgot" are on your perl path -- see this:
http://archive.develooper.com/perl5-porters@perl.org/msg83916.html
but after I did that, I was still stuck, until I found this:
http://search.cpan.org/author/JHI/perl-5.8.0/pod/perldelta.pod#Mac_OS_X_dyld_undefined_symbols
It suggests two steps, first, remove an old file (/Library/Perl/darwin/CORE/libperl.dylib) which I didn't even have, and then, remove old .bundle files, which was what finally got me back in action.
-
Why replace the Personal Web Sharing tests?
2002-11-10 10:23:11 anonymous2 [Reply | View]
Just modify the built-in StartupItem to call your version of apachectl instead of the default location, and that way you can use the checkbox in System Preferences to control your version of Apache instead.
This also offers a solution for people who like to programmatically modify the /etc/hostconfig file to turn services on/off at startup.
Oh, and the guy bitching about the Control key on the PowerBooks needs to lay down the crack pipe and get some fresh air. -
Re: Why replace the Personal Web Sharing tests?
2004-01-12 10:28:01 Theory [Reply | View]
Yes, the setup will run into problems, unless you set the Listen directive in either configuration's httpd.conf to listen on a different port.
HTH,
David -
Why replace the Personal Web Sharing tests?
2003-04-21 10:00:52 anonymous2 [Reply | View]
another method is to just edit the shell script that calls apache in /sbin. once making a backup of apachectl in /sbin just edit the one line that points to apple's original version of httpd so it points to your new version (/usr/local/apache/bin/httpd or whatever you are using).
-
Why replace the Personal Web Sharing tests?
2002-11-11 13:23:19 Theory [Reply | View]
<blockquote> Just modify the built-in StartupItem to call your version of apachectl instead of the default location, and that way you can use the checkbox in System Preferences to control your version of Apache instead.</blockquote>
While this will work, there are a number of issues with it that you should be aware of:
- The Apache you've compiled according to my instructions does not use the same configuration as Apple's. So, for example, unless you change the configuration to use Apple's, Personal Web Sharing won't actually work.
- Should Apple update the Mac OS X version of Apache, there's a good chance that your changes to the Apple Apache startup script will be wiped out.
- Everything in the
/Systemdirectory hierarchy is technically for the OS only, so YMMV.
A better solution, offered by another attentive reader, is to leave the variable tests in, but rename them, e.g.,
if [ "${APACHE:=-NO-}" = "-YES-" ]; then
Then just add the new
APACHEvariable to the/etc/hostconfigfile and you're in business.
Regards,
David
-
Why replace the Personal Web Sharing tests?
2004-01-10 16:32:43 anonymous2 [Reply | View]
Since we have a startup script for Apple's own Apache in /System/Library/StartupItems AND one for the new version of Apache in /Library/StartupItems won't this setup run into problems if we have both WEBSERVER and APACHE set to YES in hostconfig (or personal web serving set under system preferences), ie: at startup we are loading both Apple's Apache and the new one? -
Why replace the Personal Web Sharing tests?
2004-01-12 10:29:08 Theory [Reply | View]
(Sorry I responded to the wrong message above. Here goes again...)
Yes, the setup will run into problems, unless you set the Listen directive in either configuration's httpd.conf to listen on a different port.
HTH,
David
-
or...
2002-11-05 15:31:21 anonymous2 [Reply | View]
port install apache +mod_perl_expt
with darwinports will build a static mod_perl, with the patched httpd to give a working libapreq. in fact, it will also compile Perl 5.8.0 for you as a dependancy.
HTH the lazy of you out there
Michael -
or...
2003-04-12 17:12:04 anonymous2 [Reply | View]
Here is an email conversation with the above author.
The +<name> syntax is the darwinports syntax for executing a variant of
a port, so 'port install vim +x11' might install vim with the XFree86
stuff compiled in. In the case of apache there is a variant called
mod_perl (mod_perl_expt has gone away, it is no longer experimental as
the patches to make it work properly are in the main apache source tree
now).
At the moment mod_perl is only available as a variant of the apache port
in darwinports and only as a static module. I'll probably get around to
making a dynamic module (and some others) that will be separate ports.
The layout used in darwinports is essentially the FreeBSD layout, where
there is a /opt/local/www dir which contains the CGI and document roots.
the Apache configuration files are in /opt/local/etc/apache and the
binaries are in /opt/local/bin and /opt/local/sbin.
I haven't tested this port with the perl install as described on
apple.com, it should work afaik, but I don't know for sure.
ONe thing to bear in mind, I just broke the perl5.8 port trying to make
it cleaner, it should be fixed soon, but likely not in the next day or
two. (If you do decide to put a perl in /opt/local.
HTH
Michael
Useful heh? This was posted 4/12/03 -
or...
2002-11-11 13:07:06 Theory [Reply | View]
Yeah, that's good too. I wouldn't mind seeing articles on the Darwin ports project, or on Fink. What you posted is great for folks who already have Darwin Ports stuff installed, but others might be intersted to know what Darwin Ports is about, and what's involved in installing it and using it. Same goes for Fink, of coruse.
Regards,
David






I cannot figure how to skip this server message, and since I never get this screen from my other dev platforms, and I've tested to show it is not the browser, but the server, how can I make the browser redirect.
Just to add some detail, CGI::Application uses screen modes, so when a form is submitted, I input the form data into a database, then redirect the browser to a different screen mode, so that I don't have to redundantly construct the mode's HTML in my code.
The only way I got around it so far (and this is not a final solution, I hope) was to do an LWP get on the redirect url, then print the contents back to the browser. This seems ridiculous to me, but perhaps I am ridiculous for using CGI's apparently heavy redirect function.
Any ideas would be much obliged. Thanks for the great Apache/mod_perl info on the site!