Top

A Linux User Reference

Search tips
  • search ignores words that are less than 4 characters in length
  • searches are case insensitve
  • if a search does not return anything try it in Boolean mode then Query expansion mode by checking the appropriate radio button e.g. searching for 'cron' in just the Administration category returns nothing - presumably because the 50% threshold is reached. Boolean mode ignores this threshold so a search for 'cron' returns several hits
  • in Boolean mode preceding a word with a '+' means the result must include that word, a '-' means it must not
  • in Boolean mode '+crontab -anacron' means match articles about crontab that DO NOT mention anacron
  • to match a phrase e.g. 'manage system' check the Boolean mode radio button and enclose the phrase in quotes "some phrase ..."
  • in Query expansion mode the search context is expanded beyond the keywords you entered - relevancy of hits may well be degraded

NETWORK APPLICATIONS

Apache Web Server modules

  • Modules
    Apache modules

    Modules are bits of source code that can either be built into the 'httpd' binary or built separately as shared object files.

    Shared object files are referred to as DSOs (Dynamically Shared Objects).

    DSOs are loaded and unloaded from memory on demand.

    Status

    • a module's status (apache docs) indicates how tightly bound into the Apache Web server the module is
    • depending on it's status it may be necessary to recompile the server in order to gain access to a module and its functionality.

    Possible status values:

    MPM

    a Multi-Processing Module. Unlike the other types of modules, Apache must have one and only one MPM in use at any time. This type of module is responsible for basic request handling and dispatching.

    Base

    the module is compiled and loaded into the server by default and is therefore normally available unless you have taken steps to remove the module from your configuration.

    Extension

    the module is not normally compiled and loaded into the server. To enable the module and its functionality, you may need to change the server build configuration files and re-compile Apache.

    Experimental

    the module is available as part of the Apache kit, but you are on your own if you try to use it. The module is being documented for completeness, and is not necessarily supported.

    External

    Modules which are not included with the base Apache distribution ("third-party modules") may use the "External" status. We are not responsible for, nor do we support such modules.

  • Listing compiled in and loaded modules

    List compiled in modules

    # httpd -l               (1.3.x)
    
    # apache2 -l             (2.2.x)
    Compiled in modules:
      core.c
      mod_log_config.c
      mod_logio.c
      worker.c
      http_core.c
      mod_so.c               (Required if using DSOs - loads modules at run-time)
    

    List all loaded modules

    $ sudo apachectl -t -D DUMP_MODULES
    Loaded Modules:
     core_module (static)
     log_config_module (static)
     logio_module (static)
     mpm_prefork_module (static)
     http_module (static)
     so_module (static)
     alias_module (shared)
     auth_basic_module (shared)
     .....
     perl_module (shared)
     php5_module (shared)
     reqtimeout_module (shared)
     setenvif_module (shared)
     ssl_module (shared)
     status_module (shared)
    Syntax OK
    
  • mod_perl

    Mod_perl documentation

    Status: not sure, probably Extension or External. It is likely that you distribution will have this module compiled into the apache binary as a DSO ready for use, if not see the docs via the above link.

    Configure for use - httpd.conf, apache2.conf

    # Allow running of perl scripts.
    
    LoadModule perl_module /usr/lib/apache2/modules/mod_perl.so     # Load
    AddModule mod_perl.c                                            # Activate
    PerlModule Apache::Registry                                     # Transparently run perl CGI scripts, 
                                                                    # effectively replacing CGI with perl
    Alias /perl/ /home/httpd/perl/                                  # Reroutes requests for URIs in the form
                                                                    # http://www.host.com/perl/file.pl to
                                                                    # the directory /home/httpd/perl
    <Location /perl>
         SetHandler perl-script                                     # Requests for a perl file will be 
                                                                    # directed to the perl-script handler
         PerlHandler Apache::Registry                               # which is part of this module.
         Options +ExecCGI                                           # Allow execution of CGI scripts
         PerlSendHeader On
    </Location>
    

    Test configuration file and reload

    # apache2ctl configtest
    # apache2ctl reload
    

    Debian

    Is the perl module available - usually is if not then follow mod_perl 2.0 install doc or mod_perl 1.0 install doc or read your distibutions docs.

    $ ls /etc/apache2/mods-available | grep perl
    perl.load
    

    Enable, load, check and disable

    $ sudo a2enmod perl
    Enabling module perl.
    To activate the new configuration, you need to run:
      service apache2 restart
    
    $ ls /etc/apache2/mods-enabled | grep perl
    perl.load
    
    $ sudo service apache2 reload 
    
    $ sudo apache2ctl -t -D DUMP_MODULES | grep perl
    Syntax OK
     perl_module (shared)
    
    
    $ sudo a2dismod perl
    [sudo] password for mark: 
    Module perl disabled.
    To activate the new configuration, you need to run:
      service apache2 restart
    
  • mod_php

    Allow running of php scripts.

    Status: not sure, probably Extension or External. It is likely that you distribution will have this module compiled into the apache binary as a DSO ready for use, if not then you need to recompile.

    Build apache2 to binary to use php5 as a DSO

    # ./configure --with-apxs            (Enable building of PHP as a DSO)
                  --with-mysql           (Allows PHP to connect to Mysql DBs)
    # make
    # make install
    

    Configure for use - 'httpd.conf' or 'apache2.conf'

    LoadModule php5_module modules/libphp5.so                       # Load
    AddModule mod_php5.c                                            # Activate
    AddType application/x-httpd-php .php .phtml                     # Add to very end of  file (1.3)
    AddType aplication/x-httpd-php-source .phps                     # Enable source code highlight extension - optional
    DirectoryIndex  index.php default.php index.php index.htm       # Change default DirectoryIndex index.php
    

    Test configuration file and reload

    # apache2ctl configtest
    # apache2ctl reload
    

    Debian

    As for mod_perl.

    Is available, enable, load, check and disable

    $ ls /etc/apache2/mods-available | grep php5
    php5.conf
    php5.load
    
    $ sudo a2enmod php5
    Enabling module php5.
    To activate the new configuration, you need to run:
      service apache2 restart
    
    $ ls /etc/apache2/mods-enabled | grep perl
    php5.conf
    php5.load
    
    $ sudo service apache2 reload 
    
    $ sudo apache2ctl -t -D DUMP_MODULES | grep php
    Syntax OK
     php5_module (shared)
    
    $ sudo a2dismod php5
    [sudo] password for mark: 
    Module perl disabled.
    To activate the new configuration, you need to run:
      service apache2 restart
    

    Test the module implementation

    Create a php file and access via web browser - info.php

    <?php
    phpinfo()
    ?>
    
  • mod_alias

    Designed to handle simple URL manipulation tasks. For more complicated tasks such as manipulating the query string, use the tools provided by mod_rewrite.

    Status: Base - so should be available

    Redirect directive

    Maps an old URL into a new one - used in server config, virtual host, directory and .htaccess

    Redirect [status] URL-path URL
    

    Usage example

    Redirect /service http://foo2.bar.com/service
    

    Requests for 'http://myserver/service/foo.txt' redirected to 'http://foo2.bar.com/service/foo.txt'.

    RedirectMatch directive

    Equivalent to 'Redirect', but uses 'regex' for matching - used in server config, virtual host, directory and .htaccess

    RedirectMatch [status] regex URL
    

    Usage example

    RedirectMatch (.*)\.gif$ http://www.anotherserver.com$1.jpg
    

    Requests for GIF files redirected to same name JPEG files).

    ServerAlias directive

    Redirecting incoming HTTP requests.

    Example configuration

    <VirtualHost *:80>
       ServerName  www.example.com
       ServerAlias  example.com www.eg2.com eg2.com          
       DocumentRoot  /var/www/www.example.com
       CustomLog  /etc/httpd/logs/www.example.log combined
    </VirtualHost>
    

    This virtual host will serve content to all the domains listed 'under' ServerAlias.

  • mod_rewrite

    Load and enable module directives.

    Status: Extension - if your distribution does not have this module compiled in then you will need to do so. Good chance it is as is the case with Mint.

    Enable via 'httpd.conf', 'apache2.conf'

    .....  
      LoadModule rewrite_module modules/mod_rewrite.so     # Rewrites a URL. Load module
      AddModule mod_rewrite.c                              # Enable module
    .....
    

    Turn on for use

    <VirtualHost *:80>
        ServerName   www.eg2.com
        ServerAlias   eg2.com
        DocumentRoot  /var/www/www.example.com
        CustomLog   /etc/httpd/logs/www.eg2.log combined
        <IfModule mod_rewrite.c>
           RewriteEngine  On                                 # Turn on
           RewriteOptions Inherit 
           RewriteRule  ^(.+) http://www.example.com  [R]    # Redirect to www.example.com
        </IfModule>
    </VirtualHost>
    

    Configuration settings for the Main server context are not inherited by virtual hosts so the above directives need to be in each virtual host where you wish to use the module.

    Debian

    As per other modules.

    $ sudo a2enmod rewrite
    
    $ sudo a2dismod rewrite
    

    Sample .htaccess for say am MVC framework

    Options +FollowSymLinks
    IndexIgnore */*
    RewriteEngine on 
    
    # if a directory or a file exists, use it directly 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    
    # otherwise forward it to index.php 
    RewriteRule . index.php
    

    If a file does not exists all requests end up being routed via the site's default controller

  • mod_ssl

    Status: Extension - if your distribution does not have this module compiled in then you will need to do so. Good chance it is as is the case with Mint.

    • the module supports SSL encryption of Web traffic
    • when SSL is used, data transmitted between server and client is encrypted with a dynamically negotiated password
    • requires 'openssl'

    Implement SSL via a virtual host

    • can set some global settings and create a virtual host section for SSL connections
    • can also have two running copies of apache, one on port 80, the other on 443.
    <VirtualHost *:443>
        DocumentRoot  "/var/www/www.example.com"
        ScriptAlias  /cgi-bin /var/www/cgi-bin
        ServerName   www.example.com
        ServerAdmin   webmaster@example.com
        Errorlog   /etc/httpd/logs/ssl_error_log
        CustomLog   /etc/httpd/logs/ssl_access_log combined
        Options   FollowSymLinks
        SSLEngine  on
        SSLCipherSuite ALL: !ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
        SSLCertificateFile /etc/httpd/ssl/server.crt
        SSLCertificateKeyFile /etc/httpd/ssl/server.key
    </VirtualHost>
    

    Configure apache-SSL as a DSO

    # ./configure -enable-shared=apache_ssl
    

    Then compile and install.

    Configure for use

    LoadModule apache_ssl_module modules/libssl       # enable module
    

    In 'httpd.conf' or 'apache2.conf'.

    Test, stop and restart

    # apachectl configtest
    # apachectl stop
    # apachectl startssl
    

    Please note

    To use encrypted data you ALSO need to generate the following

    RSA private key file

    A digital file used to decrypt messages received. Has a public component which can be distributed (via a Certificate file) and allows people to encrypt messages to you.

    Certificate Signing Request (CSR)

    A digital file which contains your public key and your name. Sent to to a Certifying Authority (CA) to be converted into a real Certificate.

    Certificate

    Contains your RSA public key, your name, the name of the CA and is digitally signed by your CA. Browsers that know the CA can verify the signature on that Certificate, thereby obtaining your RSA public key.

    See the 'OpenSSL' section in the Security category for more details on this subject.

    Create certificate signing request (CSR)

    Create a self signed certificate

  • Test SSL connection

    A couple of checks to see if apache is responding correctly to requests via HTTP and HTTPS.

    Check using OpenSSl

    $ openssl s_client -connect localhost:443 -state -debug
    GET / HTTP/1.0
    

    Need 'openssl' installed. Before getting the HTTP response, you will receive detailed information about the SSL handshake.

    Check using curl

    $ curl http://localhost/
    $ curl https://localhost/
    

    Need 'curl' installed.

    Simple check via HTTP

    $ telnet localhost 80
    GET / HTTP/1.0
    

    For completeness.