Apache for Ubuntu Quickstart Guide

Apache is the world’s most popular web server, and is developed and maintain by an open community of developers under the Apache Software Foundation.

Installing Apache for Ubuntu

From the Ubuntu desktop:

  1. Go to System > Administration > Synapatic Package Manager
  2. Search for “apache2″ and “Mark for installation”
  3. Click on the “Apply” to install

From the command line:

$ sudo apt-get install apache2

Apache Directories for Ubuntu

  • /etc/apache2 This directory contains the Apache configuration files.
  • /etc/init.d The startup script apache2 can be found in this directory. This script is used to start and stop the server. It also, automatically starts and stops the server when it’s halted, started, or rebooted.
  • /var/www The default location for the web content.
  • /usr/sbin The executable programs are placed in this directory. For example: apache2 the server executeable itself.
  • /usr/bin Some of the utilities from Apache package are placed here. For example: htpasswd, used for generating authentication password files.

Configuration Files

The configuration files for Apache is under the directory /etc/apache2.

  • apache2.conf This is the file which contains all the default configurations of the web server. Inside the configuration file it also loads configurations from: mods-enabled/*.load, mods-enabled/*.conf, httpd.conf, ports.conf, conf.d/, and sites-enabled/
  • mods-available This directory contains all the configurations for all the available modules in Apache
  • mods-enabled This directory contains all the configurations for the modules enable in Apache
  • httpd.conf This file is original and should contain custom configuration specifically for your web server. e.g. ServerName
  • ports.conf This file contains a list of all the ports the web server should be listening to.
  • sites-available This directory should contain all the configurations for your websites being hosted on the webserver
  • sites-enabled This directory should contains the configurations for your websites that you have enabled on the web server.

Starting and Stopping Apache

The /etc/init.d/apache2 script and the following options is use to control the web server:

  • start Start the web server.
  • stop Stops the web server.
  • reload Reload the configuration files after modification.
  • restart Convenient way to stop and then immediately start the web server.

Virtual Hosting

Virtual hosts enable you to run more than one host on the same IP address. To enable virtual host you can modified the httpd.conf file:

NameVirtualHost 192.168.100.1

<VirtualHost 192.168.100.1>
ServerName www.vincentkong.com
ServerAlias vincentkong.com

CustomLog /path/to/logfile/access.log combined
ErrorLog /path/to/logfile/error.log

DocumentRoot /path/to/website/
<Directory /path/to/website/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
allow from all
</Directory>
</VirtualHost>

Options Directives

Options directives determines what options are available for the directory configured in Apache.

Switch Description
None None of the available options are enabled for this directory.
All All the options, except for MultiViews, are enabled for this directory.
Indexes If the index.html or other DirectoryIndex file is missing, then list the files in the directory as an HTML page.
Includes Server-side includes (SSI) are permitted in this directory. Can also be IncludesNoExec if you want to allow includes but don’t allow exec option.
FollowSymLinks Allows access to directories that are symbolically linked to a document directory.
ExecCGI CGI programs are permitted in this directory.
MultiViews Part of mod_negotiation module. When a client requests document that can’t be found, the server tries to figure out which document best suits the client’s requirements.

Enabling/Disabling Multiple Sites

There are two commands which allows you to easily enable/disable multiple websites. For each website create a file in the /etc/apache2/sites-available directory (it’s perferable that the file name is the name of your site) e.g. vincentkong.com, and add in your virtual host settings.

To enable the website use the command:

$ a2ensite <site filename>

This command will create a symbolic link inside the /etc/apache2/sites-enabled directory to your file.

To disable the website use the command:

$ a2dissite <site filename>

Enabling/Disabling Modules

All the configuration files for the modules installed with Apache can be found in /etc/apache2/mods-available, the .load file are the settings to load the module, and the .conf are the default settings for the module.

To enable a module for Apache use the following command:

$ a2enmod or

$ a2enmod <module name> (if you already know the name of the module)

This command basically creates a symbolic link in the mods-enabled directory to the module configuration you specified.

To disable a module use the command:

$ a2dismod

Related posts:

  1. Integrating Tomcat and Apache with mod_jk Connector
  2. Configuring Apache for SSL Support
  3. Tomcat 5.5 for Ubuntu Quickstart Guide
  4. Apache mod_proxy and Reverse Proxy
  5. Samba on Ubuntu Quickstart Guide
This entry was posted in Apache, Ubuntu and tagged , . Bookmark the permalink.

Comments are closed.