Posted 11 November, 2013 by Alix Dunn

Getting off Google: Step Three, Configuring Apache

This post is part of our series on Getting off Google. The first two posts detailed how to set up a Virtual Private Server (VPS) and how to install things on your VPS  so you can host your own data (websites, documents, and other information). This post will walk you through how to setup Apache (the software that turns your VPS into a web host). There’s no point in keeping your website files on a VPS if no one can access them from the internet.

So without further ado, let’s get Apache configured so you can share data over the internet. With Apache installed (see the last post if you haven’t gotten that step completed), it’s time to get familiar with two new concepts: exploring files on your VPS, and editing files in command line. Both are pretty straightforward but take some time getting used to. Rest assured, with just a little bit of time trying to set up your Apache server, you will be changing directories, finding files, and editing them quickly and easily.

Getting around files in command line

When you first log into your server in terminal, all you will see is an intimidating black screen. Don’t worry. All of the files for your operating system and all of the newly installed PHP and Apache software are there too. There are two commands that you can use to start moving around your directories and see what is hiding in that black hole.

Try this: ls

That will show you all of the folders and files that are in the directory. There is a lot more you can do with this command, but for now at least you can use it to see that there are indeed files in your VPS. Another important command is: cd

“cd” stands for Change Directory and by typing “cd /any/folder/name”, you will jump into that folder. cd .. will back you up to the folder above the one you are in. Play around with “ls” and “cd” commands to get more comfortable with navigating your folders and files. Using the command “man” in front of any command, you can see a description of how a command can be used (sometimes it takes a while to decipher what “man entries” mean, but using search engines to search forums is really useful). Try out “man ls” to see what the command “ls” can do. And if you want to learn more about what you can do with command line, there are some basic introductions at TutsPlus and some great tutorials at LifeHacker.

Keeping our eye on the prize of getting Apache up and working, let’s navigate to the configuration file for Apache. Go to /etc/apache2/ and type “ls” to get a readout of the files in your Apache2 directory.

Configuring Apache to Reach Your Website

Now we are going to do four things:

  1. Name our server;
  2. Learn how to edit text documents in command line;
  3. Tell the server what data to give to someone who visits our IP address;
  4. Restart your apache server.

Naming the server and setting up virtual hosts

Naming a server makes it easier to set up configuration. And it’s not difficult. Here are  easy-to-use step-by-step instructions on how to do it.

 Telling Apache to listen to requests coming from the internet is a little bit more difficult. But still pretty straightforward. You are already in the /etc/apache2/ folder and now you need to open the file “ports.conf.” Wouldn’t it be great if you could just double click on that file in your favorite text editor to edit it? This won’t be your last longing for a point-and-click interface but embrace your inner-nerd and open the file using the command: “nano ports.conf”. The “nano” command is saying ask the nano application to open this file.

What’s Nano? Nano is an in-terminal editor that uses the keyboard for commands. At the bottom of the opened document in terminal there are keyboard shortcut controls – test them out a little bit, and always know that when you exit (ctrl + x) you will have the option to write over the old file or ditch the changes. (It’s like the difference between “save and save as” in point-and-click text editors.)

In the ports.conf file you should edit so that you “Listen” at your IP address port 80 or “:80”:

Listen ‘your-IP-address’:80

NameVirtualHost *:80

<VirtualHost *:80>

       ServerName ‘yourservernamehere’

       ServerAdmin webmaster@localhost

        DocumentRoot /var/www/

       <Directory /var/www/>

               Order allow,deny

               Allow from all



There is a lot to unpack here, and I’m not going to go into it all here (to stay on task and because I’m also still learning how to manage virtual hosts). Naming a virtual host makes it possible to serve up different websites from the same IP address. In your /var/www folder you can have folders that hold all the files for each website. This virtual host looks in the “document root” folder “/var/www/” for an index file to serve up as a home page. Changing this document root to something like “/var/www/otherwebsitefolder” would serve up the index file in that subfolder. This makes it possible to have multiple websites in subfolders all on the same server.

So save that file by exiting out and saving over ports.conf.

Restarting your Apache server

Now that you have changed fundamental configurations on your server, you’ll need to restart Apache so that the changes are registered. It’s not the same as restarting your VPS (which you can do from your VPS dashboard if you need to). It’s the difference between restarting your computer (that’s what restarting your VPS means) and restarting a software application.

To restart the server you use a command that will become familiar to you quickly:

/etc/init.d/apache2 restart

For more information about how the “/etc/init.d/” command works and what to use it for, look here.  The way I understand it, in basic terms, is that the directory is where you can start and stop applications that are running on your VPS. It sort of provides the same function as when you double-click on an application icon (or /etc/init.d/name-of-service start) or exit a program (/etc/init.d/name-of-service stop).

Once you have restarted your Apache server you can open up a browser, type in your IP address in the url bar, and, voila! Your server sends the internet the content of the file /var/www/index.html!

Don’t believe me? Try using Nano to edit the /var/www/index.html file to whatever you want it to say and then refresh your browser!

Ever wonder how the internet knows to send visitors to your domain name to the right IP address? In the next post we will talk about how to manage your domain name so you have control over where the internet routes visitors when they go to your website.

Related articles