This article describes how to install an apache web server on Ubuntu with no extras. It's intended only for users who are experienced administrators or who just want a basic web server install with no details on including modules like PHP or customizing apache for their site.
A barebones article is intended for users who just want to get a software package up and running with the default options and no frills. It's best used by either experienced Linux administrators or users needing to get a package installed to satisfy a prerequisite without going through extensive customization. Most users are advised to use the more in-depth tutorials found elsewhere in the Slicehost articles repository so they can better learn the software they are implementing.
For a more comprehensive survey of this topic, check the links in the "Further reading" section at the end of the article.
Run the following commands:
sudo aptitude update sudo aptitude install apache2
Adding iptables rules for apache (optional)
The default Ubuntu images for Slicehost do not have iptables configured to restrict any ports, and the Slicehost articles on configuring Ubuntu slices leave ports 80 and 443 open.
If you have added iptables restrictions yourself or have removed the Slicehost default rules for web servers, the iptables rules to add can look like this:
-I INPUT -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT -I OUTPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT -I INPUT -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT -I OUTPUT -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT
Starting and stopping apache
You can start apache with:
sudo /usr/sbin/apache2ctl start
Similarly, you can stop apache with:
sudo /usr/sbin/apache2ctl stop
To restart apache run:
sudo /usr/sbin/apache2ctl restart
Executing apache2ctl by itself will show what other options can be passed to the command.
Starting apache at boot time
Ensure apache will start when the slice reboots by running:
sudo /usr/sbin/update-rc.d apache2 defaults
Where to put documents
Apache will serve documents for the default site from the directory:
This directory is called apache's "document root". You can make documents available via the web by putting them in that directory or in a subdirectory. If you were to have "www.example.com" pointing to your slice you could see the default index file in the document root by going to this URL:
To access files or subdirectories in the document root, think of the base URL for your web server as an alias for the document root, then add a path to the URL telling the web server to look deeper. For example, if "www.example.com" gets you to the document root of "/var/www", to view the file at "/var/www/mysite/mypage.html" you would use the URL:
When no filename is specified in the URL apache will look for a default page like "index.html" or "index.htm" in the target directory before returning an error or a listing of files in the directory (depending on your configuration).
Apache's log files are located in the directory:
By default only the root user has access to that directory, so you will need to use sudo to get a directory listing or view files.
The log file that records errors is:
The log file that records page accesses to the default site is:
Apache's configuration files are located in:
The main configuration file, which cites other configuration files for more specific functions, is:
The configuration for the default site is located in the file:
It is good practice to create any other virtual hosts in the same directory, possibly using the default config file as a reference. Once a site is configured it can be enabled or disabled with the commands "a2ensite" and "a2dissite". For example, to enable the default site, enter the command:
sudo /usr/sbin/a2ensite default
And the default site can be disabled with the command:
sudo /usr/sbin/a2dissite default
Similarly, modules can be enabled and disabled with "a2enmod" and "a2dismod".
There are a number of Slicehost articles on apache, including tutorials and information on configuring virtual hosts and some mods.
- -- Jered