Apache Configuration Info

Links

NEWER INFO

See setup and config file in ahapache.

Apache config Quickstart

NOTE: OLD, OUT OF DATE INFO

This works as of Dec 29, 2011 with Apache 2.2 as installed via Ubuntu 11.10 server.

Do this to setup apache2 after installing apache2 on Ubuntu or Debian.

  1. Create a directory in your home dir for the document root. For example:
        mkdir -p /home/acorn/bcorn.com/www
    
  2. Add in that directory a file named index.html with something like the following contents.
        <html><body><h1>My server works!</h1></body></html>
    
  3. Also create a ~/public_html and (optionally) a ~/public_html/cgi-bin for webpages under http://bcorn.com/~acorn
        mkdir -p ~/public_html/cgi-bin
        chmod 755 ~/public_html ~/public_html/cgi-bin
    
  4. Add ~/public_html/index.html with something like the following contents.
        <html><body><h1>Acorn's personal page.!</h1></body></html>
    
  5. Edit /etc/apache2/sites-available/default as follows.
    NOTE: Replace bcorn.com with the domain name of your server.
  6. install suexec to allow cgi programs in /home/*/public_html/cgi-bin to run as the user who owns them
        sudo apt-get install apache2-suexec
  7. Enable the mod_userdir and suexec module
        sudo a2enmod suexec
        sudo a2enmod userdir
  8. Test the config for syntax errors
        apachectl configtest
  9. Restart the server to use the new config
        sudo service apache2 restart

Apache configuration details

Applying changes to config files

Anytime you change config files first check the change with

    apachectl configtest
This checks the file syntax. If it reports "Syntax OK" then restart the server with
    sudo service apache2 restart

Config files

Apache default config file location is /etc/apache2/httpd.conf but Debian (and Ubuntu) do not use this. In Debian/Ubuntu the main config file is /etc/apache2/apache2.conf and this file includes all the other config files. To see all config files that get included:

    grep -r -a -i '^ *include' /etc/apache2

The file you should edit is

    suvw /etc/apache2/sites-available/default
which configures the default virtual host.

Modules

You can enable modules with

    sudo a2enmod <module-name>
This creates symlinks in /etc/apache2/mods-enabled dir.

Apache Authentication

Important notes

Adding a user to password file

Creating a password file (only if it does not exist)

Securing a directory in the website

(Note: see next section too)

Alternate Method: Securing a directory in the website

In place of the .htaccess file as described above the described-above contents of the .htaccess file may be placed directly into the main config file (/etc/httpd/conf/httpd.conf). The entire contents of the .htaccess file, as described above, should be placed in the main config file inside the markers <Directory "/path/to/my/dir"> and </Directory>, where /path/to/my/dir is the directory of the files in question (the full path of the directory where the .htaccess file would have been located). For example:

When using this method the .htaccess file should be removed, and the "AllowOverride" directive is not needed - it can be set to "None" like this: This method is faster than using the .htaccess file when "AllowOverride" is "None" because apache does not need to read the .htaccess file each time.

Notes

CGI Quickstart

Look in /etc/apache2/sites-available/default for ScriptAlias line. Shows where to put the file.

Here is an example scriptalias that allows running scripts named /usr/lib/cgi-bin/myscript as http://localhost/cgi-bin/myscript

Sample CGI script

Sample cgi script. Put in /usr/lib/cgi-bin/mydate.

Be sure to
chmod a+x /usr/lib/cgi-bin/mydate
chmod go-w /usr/lib/cgi-bin/mydate
the script.

Sample CGI form

Sample cgi form. Put in /usr/lib/cgi-bin/myform.

Be sure to chmod a+x /usr/lib/cgi-bin/myform the script.