Apache


Compile-time options
Syntax
  • ./configure [option]*
  • --prefix=<path>  (where to install Apache)
  • --enable-<module>[=shared]  (add [DSO] module)
  • --disable-<module>
  • --with-port=<port>  (the port number to listen to) (used for generating the httpd.conf file)
Examples
  • --enable-module-name  (add "mod_module_name")
  • --disable-module-name  (disable "mod_module_name")
  • --enable-module-name=shared  (add "mod_module_name" as a DSO module that can be loaded or unloaded at runtime)
Modules
  • mod_cgi: CGI scripts (default: enabled)
  • mod_include: Server side includes
  • mod_so: DSO modules
  • mod_speling: Correcting common URL mispellings
  • mod_ssl: SSL/TSL (Secure Sockets Layer / Transport Layer Security) via OpenSSL
  • mod_unique_id: Provides an environment variable--UNIQUE_ID--with a unique identifier for each request
  • mod_usertrack: User tracking (formerly mod_cookies)
Identifying modules
  • <?php phpinfo(); ?>   (list currently loaded modules)
  • <apache>/bin/apachectl -l   (list static compiled modules)

Running apache (requires root access)

  • <path>/bin/apachectl [start, stop, restart]
Configuration files
  • /etc/httpd/conf/httpd.conf
  • ServerAdmin admin@your-domain.com
  • DefaultType [text/plain, application/octet-stream]
  • DefaultLanguage en
  • AddDefaultCharset ISO-8859-1
  • DocumentRoot "/var/www/html"
  • <Directory /> ... </Directory>    # Default directory options
  • <Directory "/var/www/html"> ... </Directory>    # html directory options
  • <Directory "/var/www/cgi-bin"> ... </Directory>    # cgi-bin directory options
  • <Directory "/var/www/icons"> ... </Directory>    # icons directory options
  • <Directory "/var/www/manual"> ... </Directory>    # manual directory options
  • <Directory "/var/www/error"> ... </Directory>    # error directory options
  • ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
  • Alias /icons/ "/var/www/icons/"
  • Alias /manual "/var/www/manual"
  • Alias /error/ "/var/www/error/"
  • If a different location is used for one of the above directories, the location needs to be changed in the following places:
  • The <Directory ...> tag
  • The DocumentRoot, ScriptAlias, or Alias value
Running CGI scripts
  • Set the permission for the script files to allow execution.
Supporting server side includes (SSI)
  • AddType text/html .shtml
  • AddOutputFilter INCLUDES .shtml
  • For the relevant html directories add "Includes" to the "Options" directive
Examples
<Directory "/var/www/html">
    Options Indexes FollowSymLinks Includes
</Directory>
Enabling mod_speling
  • CheckSpelling [on, off]  (default: off)
Enabling PHP
  • LoadModule php5_module        modules/libphp5.so    # Avoid redundant copies of this line.
  • DirectoryIndex index.html index.php    # Add index.php  to the DirectoryIndex.
  • AddType application/x-httpd-php .php
  • AddType application/x-httpd-php-source phps    # Syntax highlighting for PHP source-code.
Running Apache behind a firewall
  • Often ISPs will block port 80, the default port for http;  as a work-around for this, Apache can be set to listen to a different port number for http (in this example, port 8080)
  • Listen 8080
  • Firewalls often won't allow access to another local computer via an external IP address; due to NAT (Network Address translation), IP masquerading.
  • With virtual hosting, a web site hosted on the local network can be accessed either by the internal IP address or by the external IP address.
Examples
NameVirtualHost 192.168.1.100   # Internal IP address
NameVirtualHost 11.22.33.44       # External IP address

<VirtualHost 192.168.1.100 11.22.33.44>
    DocumentRoot /var/www/html
    ServerName www.my-domain.com
    ServerAlias my-server
</VirtualHost>

Parent URL: 
category/network
Resources URL: 
notes/apache/resources
Sources URL: 
notes/apache/sources
Topic type: 
Topic

See Also