Introduction
Apache is one of the most popular web servers used to host millions of websites across the web. It is most commonly used to host both static and dynamic content due to its ease of use and powerful features. The Apache web server is a free and open-source cross-platform web server that provides multiple modules like mod_rewrite
that allows you to rewrite URLs easily and mod_headers
that allows you to modify request and response headers. Virtual Hosting is a method of hosting multiple websites on one server.
In this tutorial, we are going to be setting up a website for the domain name uptello.com
using Apache Virtual Hosts. The server we will be using will be running Linux Ubuntu 14.04 LTS that we configured and is hosted from DigitalOcean. DigitalOcean is my preferred method for running basic Linux virtual machines with prices as low as $5/month for a server with 1GB of memory and 25GB of SSD storage. I would definitely recommend you check them out as it could save you a lot of time and money.
Installation\nSince we are running a Linux virtual machine we will first run a couple of commands to get the Apache web server installed. The first command will update the package list repository to ensure that we get the latest version of all packages.
sudo apt-get update
sudo apt-get install apache2
Configuration
We will then need to create a directory under the `/var/www/` folder that will hold our code for the website, we will call it `uptello.com/public_html`. Afterward, we will need to assign the correct permissions to the directory to allow read access.\n\n```\nsudo mkdir -p /var/www/uptello.com/public_html\nsudo chmod -R 755 /var/www\n```\nFollowing that, we will now be able to create a basic HTML page with the code below and name it `index.html`. We will put that file under the `public_html` folder. \n\n```html\n\n \n Uptello.com\n \n \n It works!\n \n\n``` \n# Enable Virtual Host\nTo enable our virtual host, we will need to create a virtual host file within the `/etc/apache2/sites-available` folder. We can clone the existing example that apache includes within the `sites-available` folder called 000-default.conf. We can do this by doing the following commands.\n```bash\ncd /etc/apache2/sites-available\ncp 000-default.conf uptello.com.conf\n```\nNow that we have our `uptello.com.conf` file that is a clone of the `000-default.conf` file, we can modify a few values in there to work for our case. Most importantly `DocumentRoot` should point to our websites project directory `/var/www/uptello.com/public_html`. We will also add a couple of lines as well.\n```html\nServerName uptello.com\nServerAlias www.uptello.com\n```\nThe final step would be to run the `a2ensite` command and pass the virtual host file as an argument. Then we will restart apache to apply our changes. \n```bash\nsudo a2ensite uptello.com.conf\nsudo service apache2 restart\n```\n# Conclusion\nIf you followed the steps above, you should now have a working virtual host! Navigating to `uptello.com` or the domain you were using, you should see "It works!" displayed. In this example, I've also enabled SSL encryption to allow use with the HTTPS protocol. You can learn more about how to set up a website with SSL encryption for FREE by reading How To Obtain And Install A Free SSL Certificate. \n\n\n