pavement

Apache, Controlling

From FreeBSDwiki
Revision as of 17:30, 25 August 2012 by Jimbo (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Want to see if it works? If you just got done installing Apache, first of all, issue a rehash command to reindex your system's PATH. Then let's get started:

ph34r# apachectl start
/usr/local/sbin/apachectl start: httpd started

Don't take its word for it, though - sometimes apachectl lies through its teeth. Let's make sure we really do have some httpd processes running:

ph34r# ps ax | grep http
18564  ??  SsJ    0:00.74 /usr/local/sbin/httpd
18566  ??  IJ     0:02.71 /usr/local/sbin/httpd
18567  ??  IJ     0:01.12 /usr/local/sbin/httpd
18568  ??  IJ     0:00.64 /usr/local/sbin/httpd
18569  ??  IJ     0:02.10 /usr/local/sbin/httpd
18570  ??  IJ     0:06.16 /usr/local/sbin/httpd
18612  ??  IJ     0:03.00 /usr/local/sbin/httpd
18621  ??  IJ     0:03.94 /usr/local/sbin/httpd
18639  ??  IJ     0:05.96 /usr/local/sbin/httpd
18644  ??  IJ     0:01.60 /usr/local/sbin/httpd
18645  ??  IJ     0:02.05 /usr/local/sbin/httpd

Okay, good, looks kosher. You're probably going to want Apache to run automatically whenever the server boots, though, right? Well, there are two ways to go about doing that. One way is to edit /etc/rc.conf and set some variables that will then cause the default apache.sh / apache2.sh startup script that the port placed in /usr/local/etc/rc.d to actually do something when the machine starts... but we're not going to talk about that way, because I personally despise forcing the administrator to maintain two files where one would do. So instead, we're just going to write our own script for /usr/local/etc/rc.d that will start Apache all on its lonesome, regardless of what is or isn't in /etc/rc.conf. So make yourself a new script and name it /usr/local/etc/rc.d/apache.sh, and make it look like this:

#!/bin/sh

case "$1" in
start)
        /usr/local/sbin/apachectl start > /dev/null && echo -n ' apache'
        ;;
stop)
        /usr/local/sbin/apachectl stop > /dev/null && echo -n ' apache'
        ;;
*)
        echo "Usage: `basename $0` {start|stop}" >&2
        ;;
esac

exit 0

Now you'll want to make sure that your new script 1. can get executed when the system starts, and 2. won't get clobbered the next time you upgrade Apache from the ports tree, so make it executable but NOT writeable:

ph34r# chmod 555 /usr/local/etc/rc.d/apache.sh

There you go - now that you've got a handle on starting and stopping Apache, move on to the basics of Configuring Apache.

Personal tools