We can point httpd
at our site with the -d
flag (notice
the full pathname to the site.toddle directory,
which will probably be different on your machine):
% httpd -d /usr/www/APACHE3/site.toddle
Since you will be typing this a lot, it’s sensible to copy it into a script called go . This can go in /usr/local/bin or in each local site. We have done the latter since it is convenient to change it slightly from time to time. Create it by typing:
% cat > /usr/local/bin/go test -d logs || mkdir logs httpd -f 'pwd'/conf/httpd$1.conf -d 'pwd' ^d
^d
is shorthand for Ctrl-D, which ends the input
and gets your prompt back. This go will work on
every site. It creates a logs directory if one
does not exist, and it explicitly specifies paths for the ServerRoot
directory (-d
) and the Config file
(-f
). The command
'
pwd
'
finds the current directory with the Unix command
pwd
.
The back-ticks are
essential: they substitute pwd
’s
value into the script — in other words, we will run Apache with
whatever configuration is in our current directory. To accomodate
sites where we have more than one Config file, we have used
...httpd$1...
where you might expect to see
...httpd...
The symbol $1
copies the first argument (if any) given to the command
go
.
Thus ./go
2
will run the Config file called httpd2.conf,
and ./go
by itself will run
httpd.conf.
Remember that you have to be in the site directory. If you try to run
this script from somewhere else, pwd
’s return will
be nonsense, and Apache will complain that it 'could not
open document config file ...'
.
Make go runnable, and run it by typing the following (note that you have to be in the directory .../site.toddle when you run go):
% chmod +x go % go
If you get the error message:
go: command not found
you need to type:
% ./go
This launches Apache in the background. Check that
it’s running by typing something like this
(arguments to ps
vary from Unix to Unix):
% ps -aux
This Unix utility lists all the processes running, among which you should find several httpds.[1]
Sooner or later, you have finished
testing and want to stop Apache. To do this, you have to get the
process identity (PID) of the program httpd using
ps
-aux
:
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND root 701 0.0 0.8 396 240 v0 R+ 2:49PM 0:00.00 ps -aux root 1 0.0 0.9 420 260 ?? Is 8:13AM 0:00.02 /sbin/init -- root 2 0.0 0.0 0 0 ?? DL 8:13AM 0:00.04 (pagedaemon) root 3 0.0 0.0 0 0 ?? DL 8:13AM 0:00.00 (vmdaemon) root 4 0.0 0.0 0 0 ?? DL 8:13AM 0:02.24 (syncer) root 35 0.0 0.3 204 84 ?? Is 8:13AM 0:00.00 adjkerntz -i root 98 0.0 1.8 820 524 ?? Is 7:13AM 0:00.43 syslogd daemon 107 0.0 1.3 820 384 ?? Is 7:13AM 0:00.00 /usr/sbin/portma root 139 0.0 2.1 888 604 ?? Is 7:13AM 0:00.07 inetd root 142 0.0 2.0 980 592 ?? Ss 7:13AM 0:00.27 cron root 146 0.0 3.2 1304 936 ?? Is 7:13AM 0:00.25 sendmail: accept root 209 0.0 1.0 500 296 con- I 7:13AM 0:00.02 /bin/sh /usr/loc root 238 0.0 5.8 10996 1676 con- I 7:13AM 0:00.09 /usr/local/libex root 239 0.0 1.1 460 316 v0 Is 7:13AM 0:00.09 -csh (csh) root 240 0.0 1.2 460 336 v1 Is 7:13AM 0:00.07 -csh (csh) root 241 0.0 1.2 460 336 v2 Is 7:13AM 0:00.07 -csh (csh) root 251 0.0 1.7 1052 484 v0 S 7:14AM 0:00.32 bash root 576 0.0 1.8 1048 508 v1 I 2:18PM 0:00.07 bash root 618 0.0 1.7 1040 500 v2 I 2:22PM 0:00.04 bash root 627 0.0 2.2 992 632 v2 I+ 2:22PM 0:00.02 mince demo_test root 630 0.0 2.2 992 636 v1 I+ 2:23PM 0:00.06 mince home root 694 0.0 6.7 2548 1968 ?? Ss 2:47PM 0:00.03 httpd -d /u webuser 695 0.0 7.0 2548 2044 ?? I 2:47PM 0:00.00 httpd -d /u webuser 696 0.0 7.0 2548 2044 ?? I 2:47PM 0:00.00 httpd -d /u webuser 697 0.0 7.0 2548 2044 ?? I 2:47PM 0:00.00 httpd -d /u webuser 698 0.0 7.0 2548 2044 ?? I 2:47PM 0:00.00 httpd -d /u webuser 699 0.0 7.0 2548 2044 ?? I 2:47PM 0:00.00 httpd -d /u
To kill Apache, you need to find the PID of the main copy of httpd
and then do kill
<PID>
— the child processes will die
with it. In the previous example the process to kill is 694 — the
copy of httpd that belongs to root. The command is this:
% kill 694
If ps -aux
produces more printout than will fit on
a screen, you can tame it with ps -aux |
more
— hit Return to see another line or Space to see
another screen. It is important to make sure that the Apache process
is properly killed because you can quite easily kill a child process
by mistake and then start a new copy of the server with
its children — and a different Config file
or Perl scripts — and so get yourself into a royal muddle.
To get just the lines from ps
that you want, you
can use:
ps awlx | grep httpd
On Linux:
killall httpd
Alternatively and better, since it is less prone to finger trouble,
Apache writes its PID in the file ...
/logs/httpd.pid (by default — see the
PidFile
directive), and you can write yourself a
little script, as follows:
kill 'cat /usr/www/APACHE3/site.toddle/logs/httpd.pid'
You may prefer to put more generalized versions of these scripts somewhere on your path. stop looks like this:
pwd | read path kill 'cat $path/logs/httpd.pid'
Or, if you don’t plan to mess with many different
configurations, use
.../src/support/apachect1
to start and stop Apache in the default
directory. You might want to copy it into
/usr/local/bin to get it onto the path, or add
$apacheinstalldir/bin
to your path. It
uses the following flags:
usage: ./apachectl (start|stop|restart|fullstatus|status|graceful|configtest|help)
start
Start httpd.
stop
Stop httpd.
restart
Restart httpd if running by sending a SIGHUP or start if not running.
fullstatus
Dump a full status screen; requires lynx and mod_status enabled.
status
Dump a short status screen; requires lynx and mod_status enabled.
graceful
Do a graceful restart by sending a SIGUSR1 or start if not running.
configtest
Do a configuration syntax test.
help
This screen.
When we typed ./go
, nothing appeared to happen,
but when we looked in the logs subdirectory, we
found a file called error_log with the
entry:
[<date>]:'mod_unique_id: unable to get hostbyname ("myname.my.domain")
In our case, this problem was due to the odd way we were running Apache, and it will only affect you if you are running on a host with no DNS or on an operating system that has difficulty determining the local hostname. The solution was to edit the file /etc/hosts and add the line:
10.0.0.2 myname.my.domain myname
where 10.0.0.2 is the IP number we were using for testing.
However, our troubles were not yet over. When we reran httpd, we received the following error message:
[<date>]--couldn't determine user name from uid
This means more
than might at first appear. We had logged in as
root. Because of the security worries of letting
outsiders log in with superuser powers, Apache, having been started
with root permissions so that it can bind to port 80, has attempted
to change its user ID to -1
. On many Unix systems,
this ID corresponds to the user nobody : a
supposedly harmless user. However, it seems that FreeBSD does not
understand this notion, hence the error message.[2] In any
case, it really isn’t a great idea to allow Apache
to run as nobody (or any other shared user),
because you run the risk that an attacker exploiting the fact that
various different services are sharing the same user, that is, if you
are running several different services (ftp, mail, etc) on the same
machine.