Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
TetraWiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Linux 101 hacks
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
='''Chapter 10: Apachectl and Httpd'''= '''Examples''' After you have installed Apache2, if you want to use apachectl and httpd to it’s maximum potential, you should go beyond using start, stop and restart. The 9 practical examples provided in this chapter will help you to use apachectl and httpd very effectively. Apachectl acts as SysV init script, taking arguments like start, stop, restart and status. It also acts as front-end to httpd command, by simply passing the command line arguments to httpd. So, all the commands you execute using apachectl, can also be executed directly by calling httpd. If you don’t have Apache, refer to the tutorials: [http://www.thegeekstuff.com/2008/07/install-apache-2-from-source-on-linux/ ][http://www.thegeekstuff.com/2008/07/install-apache-2-from-source-on-linux/ install apache from source][http://www.thegeekstuff.com/2008/07/install-apache-2-from-source-on-linux/ ]or [http://www.thegeekstuff.com/2008/09/how-to-install-or-upgrade-lamp-apache-mysql-and-php-stack-on-linux-using-yum/ ][http://www.thegeekstuff.com/2008/09/how-to-install-or-upgrade-lamp-apache-mysql-and-php-stack-on-linux-using-yum/ install LAMP stack using yum]. =='''Hack 76. Pass different httpd.conf filename to apachectl'''== Typically you’ll modify the original httpd.conf to try out different Apache directives. If something doesn’t work out, you’ll revert back the changes. Instead of playing around with the original httpd.conf, copy it to a new httpd.conf.debug and use this new httpd.conf.debug file with Apache for testing purpose as shown below using option -f. # '''apachectl -f conf/httpd.conf.debug ''' # '''httpd -k start -f conf/httpd.conf.debug ''' <nowiki>[</nowiki>'''Note''': you can use either apachectl or httpd as shown above] {| style="border-spacing:0;" | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| <nowiki># </nowiki>ps | colspan="2" style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| <div align="right">-ef | grep http</div> | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| |- | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| root | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| <div align="right">25080</div> | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| <div align="right">1</div> | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| 0 23:26 00:00:00 /usr/sbin/httpd -f |} conf/httpd.conf.debug apache 25099 25080 0 23:28 00:00:00 /usr/sbin/httpd -f conf/httpd.conf.debug <nowiki>[</nowiki>'''Note''': ps shows the httpd running with httpd.conf.debug file] Once you are satisfied with the changes and Apache runs without any problem with httpd.conf.debug, you can copy the changes to httpd.conf and start the Apache normally as shown below. # cp httpd.conf.debug httpd.conf # apachectl stop # apachectl start # ps -ef | grep httpd {| style="border-spacing:0;" | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| root | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| <div align="right">25114</div> | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| <div align="right">1</div> | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| <div align="right">0</div> | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| 23:28 00:00:00 /usr/sbin/httpd |- | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| -k start | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| |- | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| daemon | colspan="2" style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| <div align="right">25115 25114</div> | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| <div align="right">0</div> | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| 23:28 00:00:00 /usr/sbin/httpd |- | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| -k start | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| |} <nowiki>[</nowiki>'''Note''': ps indicates that the httpd is running using the default config file] =='''Hack 77. Use a temporary DocumentRoot without modifying httpd.conf'''== This is very helpful, when you are trying out different layout for your website and don’t want to modify the original files under the default DocumentRoot. Take a copy of your original DocumentRoot directory (/var/www/html) to a new temporary DocumentRoot directory (/var/www/html_debug). Make all your changes under this temporary DocumentRoot directory (/var/www/html_debug) and start the Apache with this temporary directory as shown below using option -c. <nowiki># </nowiki>'''httpd -k start -c “DocumentRoot /var/www/html_debug/”''' If you want to go back to original configuration using the default DocumentRoot (/var/www/html), simply restart the Apache as shown below. # httpd -k stop # apachectl start =='''Hack 78. Increase the Log Level temporarily'''== While you are debugging an issue, you can change the LogLevel of the Apache temporarily, without modifying the LogLevel directive in the httpd.conf as shown below using option -e. In this example, the LogLevel is set to debug. <nowiki># </nowiki>'''httpd -k start -e debug''' <nowiki>[Sun Aug 17 13:53:06 2008] [debug] mod_so.c(246): loaded module auth_basic_module</nowiki> <nowiki>[Sun Aug 17 13:53:06 2008] [debug] mod_so.c(246): loaded module auth_digest_module</nowiki> Possible values you can pass to option -e are: o debug o info o notice o warn o error o crit o alert o emerg =='''Hack 79. Display the modules inside Apache'''== '''Display the modules compiled inside Apache''' <nowiki># </nowiki>'''httpd -l''' Compiled in modules: core.c prefork.c http_core.c mod_so.c '''Display both static and dynamic module loaded by Apache''' When you pass option -l, to httpd, it will display only the static modules. Passing option -M, will display both static and shared modules as shown below. <nowiki># </nowiki>'''httpd –M''' Loaded Modules: core_module (static) mpm_prefork_module (static) http_module (static) so_module (static) auth_basic_module (shared) auth_digest_module (shared) authn_file_module (shared) authn_alias_module (shared) Syntax OK =='''Hack 80. Show all accepted directives inside httpd.conf'''== This is like an extended help for httpd, which will display all the httpd.conf directives and the places where they are valid. For a specific directive, it tells all the possible values and where it can be used inside the httpd.conf. This can be very helpful, when you want to quickly know about a particular Apache directive. <nowiki># </nowiki>'''httpd –L''' HostnameLookups (core.c) “on” to enable, “off” to disable reverse DNS lookups, or “double” to enable double-reverse DNS lookups Allowed in *.conf anywhere ServerLimit (prefork.c) <nowiki>Maximum value of MaxClients for this run of Apache Allowed in *.conf only outside <Directory>, <Files> or <Location></nowiki> KeepAlive (http_core.c) <nowiki>Whether persistent connections should be On or Off Allowed in *.conf only outside <Directory>, <Files> or <Location></nowiki> LoadModule (mod_so.c) a module name and the name of a shared object file to load it from <nowiki>Allowed in *.conf only outside <Directory>, <Files> or <Location></nowiki> =='''Hack 81. Validate the httpd.conf after making changes'''== Use option -t to validate whether there are any issues with a specific Apache configuration file. In the example shown below, it displays that there is a problem at line 148 in the httpd.conf.debug. mod_auth_basicso is missing a . (period) before the so. <nowiki># </nowiki>'''httpd -t -f conf/httpd.conf.debug''' httpd: Syntax error on line 148 of /etc/httpd/conf/httpd.conf.debug: Cannot load /etc/httpd/modules/mod_auth_basicso into server: /etc/httpd/modules/mod_auth_basicso: cannot open shared object file: No such file or directory Once you fix the issue, it will display Syntax OK. <nowiki># </nowiki>'''httpd -t -f conf/httpd.conf.debug''' Syntax OK =='''Hack 82. Display the httpd build parameters'''== Use option -V (upper-case V), to display Apache version number and all the parameters that are used while building the Apache. <nowiki># </nowiki>'''httpd –V''' Server version: Apache/2.2.9 (Unix) Server built: Jul 14 2008 15:36:56 Server’s Module Magic Number: 20051115:15 Server loaded: APR 1.2.12, APR-Util 1.2.12 Compiled using: APR 1.2.12, APR-Util 1.2.12 Architecture: 32-bit Server MPM: Prefork threaded: no forked: yes (variable process count) Server compiled with…. -D APACHE_MPM_DIR=”server/mpm/prefork” -D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled) -D APR_USE_SYSVSEM_SERIALIZE -D APR_USE_PTHREAD_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D DYNAMIC_MODULE_LIMIT=128 -D HTTPD_ROOT=”/etc/httpd” -D SUEXEC_BIN=”/usr/sbin/suexec” -D DEFAULT_PIDLOG=”logs/httpd.pid” -D DEFAULT_SCOREBOARD=”logs/apache_runtime_status” -D DEFAULT_LOCKFILE=”logs/accept.lock” -D DEFAULT_ERRORLOG=”logs/error_log” -D AP_TYPES_CONFIG_FILE=”conf/mime.types” -D SERVER_CONFIG_FILE=”conf/httpd.conf” If you want display only the Apache version number, use the option -v (lower-case v) as shown below. <nowiki># </nowiki>'''httpd -v''' Server version: Apache/2.2.9 (Unix) Server built: Jul 14 2008 15:36:56 =='''Hack 83. Load a specific module only on demand'''== Sometimes you may not want to load all the modules in the Apache. For e.g. You may want to load ldap related modules to Apache, only when you are testing LDAP. This can be achieved as shown below. Modify the httpd.conf and add IfDefine directive called load-ldap (you can name this anything you want). <nowiki><IfDefine </nowiki>load-ldap> LoadModule ldap_module modules/mod_ldap.so LoadModule authnz_ldap_module <nowiki>modules/mod_authnz_ldap.so </IfDefine></nowiki> When you are testing ldap and would like to Load the ldap related modules, pass the load-ldap to Option -D, as shown below: <nowiki># httpd -k start -e debug -Dload-ldap -f /etc/httpd/conf/httpd.conf.debug</nowiki> <nowiki>[Sun Aug 17 14:14:58 2008] [debug] mod_so.c(246): loaded module ldap_module</nowiki> <nowiki>[Sun Aug 17 14:14:58 2008] [debug] mod_so.c(246): loaded module authnz_ldap_module</nowiki> <nowiki>[Note: Pass -Dload-ldap, to load the ldap modules into Apache]</nowiki> <nowiki># </nowiki>apachectl start <nowiki>[</nowiki>'''Note''': Start the Apache normally, if you don't want to load the ldap modules.104'''Linux 101 Hacks'''www.thegeekstuff.com
Summary:
Please note that all contributions to TetraWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
TetraWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)