Install Apache


Installing Apache correctly is a very important part in your quest to Host your website at home. Luckily, on Ubuntu this is an easy task. I hope you went through the Install Linux how-to and you had the time to play around a little. But enough playing and let’s get to work!

First, let me tell you that with Ubuntu you can perform most of the tasks by pointing and clicking, but it is much faster to work in terminal and do everything in text mode. This might be a little hard in the beginning, but soon you will prefer this to any mouse activity.

Probably, after you installed Ubuntu you were able to find the terminal app. If not, on your Ubuntu desktop click the 9 dots on the left part of the screen. Then, in the search field type terminal. As you type, you will see that Ubuntu shows you a different set of applications that match the text you already typed. On the bottom part of the screen you see applications that exist and are similar to the applications showed on the top part of the screen, but those applications are not yet installed. Now click the Terminal icon.

Click on the Show Applications icon
Search for Terminal and click the icon

Terminal has started and now you are about to start playing with the big boys (big boys always use text mode). In terminal you see a prompt which should be “your_username@server_name”. You can type some basic commands. Just to give an example type “ls” and press enter. “ls” stands for list. When executed, you will be presented with the list of files sitting in the current folder. But a command can take options and it will give you different information. For example, if you type “ls -a” you will be presented a slightly different list of files. This is because “-a” means “show me all the files including hidden files”. Now, if you type “ls -l” you will be presented with the first list of files but in long format, giving you information about the owner of the file, creation date and rights on the file. Finally, you can combine command options. Typing “ls -al” will give you the list of all files, including the hidden ones, in long format.

ls command output with different options

Here is the list of commands that will install apache for you. But before that one important step. Installations on Ubuntu are usually done by the user “root” and you are logged in with your own user. You cannot login as user root with the default configuration of Ubuntu, and that, for security reasons. But you can become root. So, this will be the first step before doing anything else. In your terminal type “sudo su” You will be prompted to enter your password. If you entered the password correctly you will see that your prompt has changed. First of all, there is no color (that is because root is serious and only worries about important things not how they show ;P) and now the prompt is root@server_name.

With no further discussion, here is the list of commands that will install Apache Webserver on your Linux Ubuntu box. In the same time, we will also upgrade all software installed on your server (It is good practice to keep all packages up to date):

 apt-get -y update
 apt-get -y upgrade
 apt-get -y install apache2 

Let the installation process do its job. If you wonder what all the output on your screen means here is a very good explanation:


Testing the Installation

The easy part is completed. Now, we need to test the installation. First, we will do it locally, meaning we will make sure that the Linux box is able to access the web server that is installed on it. For this we will start Firefox on our server (to start Firefox click the it’s icon on the top left part of your screen)

Start Firefox

In the URL bar enter This should bring you to the test page of the Apache installation we just performed. If you see something like in the following image, it means the installation has succeeded, and we are ready to test remote access to the web server.

Apache Test Page

If you see something different, the installation did not work out. Possible you mistyped a command, so retype the 3 commands that will upgrade the packages and install Apache. But this time, take note of the output after each command. Usually a short output indicates an error. You can live a comment to this post, pasting the error, and I will be more than glad to give you a solution. Below are also some examples of errors, which in fact are the result of misspelling in the commands.

Installation Errors

Another good reason for a failed installation would be that your server is not connected to the internet. In this case you will get connections errors when you run the upgrade and install commands. Did you use an ethernet cable to connect your server to your router, as explained in If you did not, it is not too late. Get an ethernet cable, connect your Ubuntu server to your router and restart your computer. To restart an Ubuntu server there are several ways. You can either use the power button on the top right of your screen, or just type “sudo reboot” in a terminal.

Network card and ethernet cable

Once you have restarted your server and you logged in, look at the top right corner and check that you have a network icon. If you do, retry the Apache installation. If you do not, you can retry installing Linux, but this time with the computer plugged into the router using the ethernet cable.

Network is connected

If everything is good when testing the Apache web server locally, we can test the remote connection. Basically, we want to use another computer to access the Apache webserver we have installed on our Linux box. For this we need to know how to access our server from a remote computer using the IP address of our server.

When we did the local test, we used the IP This is a very special IP, in the sense that every computer has it. It is meant to allow software that uses the network to function when the computer is not connected to the internet. But you cannot use it to connect from a remote location. Basically, when you connect to you are doing a loop connection to yourself. It would be just like talking on the phone to yourself. So what is the public IP of your Ubuntu web server?

To find the IP address of our server several methods are available, but here I will give you the one I prefer, and I have been using for over a decade now. In your terminal just type the following commands. Note that we will install the net-tools package, and since we install something let’s also upgrade everything in the same time (upgrades done often take very little time and keep your server up to date).

 sudo apt-get -y update
 sudo apt-get -y upgrade
 sudo apt-get -y install net-tools

Once you execute the last command, your IP will be the second line of the output of the first block. If you see more than two blocks of information, it means that your server has more than one network card, but probably only one is connected. On the second line of each block, there should be an IP address in the form (xxx are 3 numbers). Chances are that the IP will be 192.168.x.x or 10.x.x.x, depending how your router is configured. In the image below you see that in my case the IP of my server is

External IP – in this case

As you can see in the above image, one of the blocks contains the address that we used to test apache locally

Now go to your windows computer, open a browser and in the URL field type: http://x.x.x.x (where x.x.x.x is the IP address that we found) . In my case I will type  You should get the same test page for your Apache server as when we tested locally.

Accessing the apache Webserver from a windows computer

If you do not see the test page, several reasons can be the cause. It is either because a firewall blocks you, or the Apache server is not listening for requests on the external IP, or …. maybe your windows computer is not connected to the network. But we will go through any debugging in another how-to. For now, I would like to complete this document by showing you how to create your first page.

The html pages will sit in the folder /var/www/html. Every file you will put in this folder will be accessible through the browser. I do hope that you have done some reading on some basic linux commands, but if you did not please just type the commands below.

sudo su

It is important before anything else that you become root. Only as root user you will be able to add files in the folder /var/www/html. When you execute the above command, you will be prompted for your password. Enter it and you should be root once you have done that.

cd /var/www/html
ls -ltr

The above commands will place you in the folder that contains the html files, and will show the content of the folder. You probably have only one file (which is the Apache test file). It is called index.html. The output should be like this:

File in /var/www/html

We will rename the index.html file and create a new one. In order to edit files, we will use “nano”, which is a very simple text editor like notepad in windows. There are other text editors available on Ubuntu, but for now we will just take this one since it is installed by default. Another text editor installed by default on all Unix distributions is “vi”, but it can be quite cryptic for a beginner. I just mention it here because in my opinion, it is a great tool for many tasks, and when you master it, you would not want to use anything else. So, type the follow commands:

 mv index.html index_bkup.html
 nano index.html 

The first command will rename the existing index.html to index_bkup.html, and the second will start the editor that will create the new index.html file. Your screen is divided now in two parts. The text editing part at the top and the function commands available to you at the bottom. In order to get help you would press the <CTRL> – G keys, meaning press the <CTRL> (it is on the bottom left corner of the keyboard) and while you hold the key down also press G. You can scroll up and down with the arrows. Do not use the mouse, it will not work. To exit from the help press <CTRL>-X as indicated in the bottom part of the screen. (by now you understood that ^ is the short way of saying <CTRL>). Let’s edit our first page. Type the following:

This is my first web page. As I do not know HTML yet, it is just plain text.

Then you must save the file (or Write Out). So, you will press <CTRL>-O. There are several options for saving the file but simply pressing enter is enough when you are presented those options. Now you can exit nano. To exit press <CTRL>-X.

Go back to your browser (either on window or locally on the server and refresh the test page) It should now display the text we have entered when we edited the file. “Pretty boring!” you will say “I want to have color and animations and build this website that will make me the next Zuckerberg!!!!”. Baby steps, I will answer! For now you have an Ubuntu server that runs Apache Web Server and you have built your first “boring” page.

Walking means “make one step, followed by all the others”!

Further reading

HTML & CSS for Complete Beginners: A Step by Step Guide to Learning HTML5 and CSS3
A Smarter Way to Learn HTML & CSS: Learn it faster. Remember it longer.
HTML5 and CSS3 All-in-One For Dummies


Posted in Apache, How to.

Leave a Reply

Your email address will not be published. Required fields are marked *