4.5 Validating the Configuration Syntax
Before
you restart a server on a live production
machine after the configuration has been changed,
it's essential to validate that the configuration
file is not broken. If the configuration is broken, the server
won't restart and users will find your server
offline for the time it'll take you to fix the
configuration and start the server again.
You can use apachectl configtest or
httpd -t to validate the configuration file
without starting the server. You can safely validate the
configuration file on a running production server, as long as you run
this test before you restart the server with apachectl
restart. Of course, it is not 100% perfect, but it will
reveal any syntax errors you might have made while editing the file.
The validation procedure doesn't just parse the code
in startup.pl, it executes it too.
<Perl> sections invoke the Perl interpreter
when reading the configuration files, and
PerlRequire and PerlModule do
so as well.
Of course, we assume that the code that gets called during this test
cannot cause any harm to your running production environment. If
you're worried about that, you can prevent the code
in the startup script and in <Perl> sections
from being executed during the syntax check. If the server
configuration is tested with -Dsyntax_check:
panic% httpd -t -Dsyntax_check
you can check in your code whether syntax_check
was set with:
Apache->define('syntax_check')
If, for example, you want to prevent the code in
startup.pl from being executed, add the
following at the top of the code:
return if Apache->define('syntax_check');
Of course, there is nothing magical about using the string
'syntax_check' as a flag—you can use any
other string as well.
|