Install Apache Web Server on Ubuntu

Table of Contents

Install Apache Web Server on Ubuntu

This step-by-step howto shows a basic setup for Apache 2 web server. Apache is installed on Ubuntu 6.06 LTS Dapper, but instructions will probably work on any Ubuntu. This document is a work in progress, initially only required commands are listed without troughout explanations.

© 2006 Tero Karvinen. GNU General Public License, version 2.

Install Apache

$ sudo apt-get install apache2

Test it

Surf to your own server on your own local computer:

$ firefox "http://localhost"

Find out how your server is found on the net. Anyone can use your IP address or DNS name to connect to your server:

$ ip addr

Use your own IP address (eth0, first IP number, does not end .255)

$ firefox ""

If DNS is working on your network, you can see your fully qualified domain name with:

$ host

User homepages

With user homepages, anything you put in public_html in your home directory is published on the web.

Enabling Userdir on Server

You must give users the permisson to create homepages. This is done by enabling the userdir module.

$ sudo a2enmod userdir

The a2enmod command just modified configuration files under /etc/apache2/. To take these changes to use, you must restart Apache daemon.

$ sudo systemctl restart apache2

This section has been updated 2016, 2021 and 2022 to enable userdir module and to use modern systemd. Old method in 2016 was: On modern Linuxes such as Ubuntu 16.04, you can restart the server with 'sudo service apache2 restart'. On very old (10+ years old) Linuxes, the command was 'sudo /etc/init.d/apache2 restart', and before that, Ubuntu shipped Apache with userdir enabled by default. This really shows it pays of to learn command line Linux: two commands out of the whole article needed updates in 14 years.

Test homepages

Go to your home directory

$ cd

Create a folder for public html files, note the underscore ‘_’

$ mkdir public_html

Check your name

$ whoami

Surf to ~yourname:

$ firefox "http://localhost/~tkarvine/"

You should see a directory listing of an empty directory. You can also try it using your IP address and a different machine.

If you see your homepage, well done. You have successfully installed a server with user homepages. You can create some web pages with OpenOffice and save them to your public_html directory.

Posted in Old Site | Tagged , , , | 32 Comments

32 Responses to Install Apache Web Server on Ubuntu

  1. Irina Shapovalova says:

    the “$ mkdir public_html” command does not mention that it should be created under root… it took some time for me as a beginner to figure it out.

  2. ‘mkdir public_html’ should be run in user’s home directory. The previous command in the article is ‘cd’, which takes you to your home dir.
    For example, your home page could be under /home/irina/public_html/.
    You should never create public_html directly under root directory ‘/’.

  3. In most modern distros, daemons are restarted with
    $ sudo systemctl restart apache2.service