Configure Apache VirtualHost on Fedora

Apache web servers utilize the virtual host feature in order to host more than one website. If you have Apache installed on Fedora Linux and want to run multiple websites, this is the route you will have to take. But don’t worry, Apache makes it rather easy to setup and configure virtual hosts.

In this guide, we’ll go through the step by step instructions to configure Apache virtual hosts on Fedora.

In this tutorial you will learn:

  • How to configure Apache virtual hosts on Fedora Linux

Configuring Apache virtual hosts on Fedora

Configuring Apache virtual hosts on Fedora

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Fedora Linux
Software Apache web server
Other Privileged access to your Linux system as root or via the sudo command.
Conventions $ sudo – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Configuring Apache virtual hosts

We assume that you already have Apache installed on Fedora and have one website running. Now, it’s time to configure Apache to host another one.

  1. Start by creating a new directory which will contain the website’s files. Typically this is somewhere inside the /var/www directory.
    $ sudo mkdir /var/www/
  2. Next, place your site files into the directory. Just as an example, we’ll create a simple index.html file for testing. After that, we need to give the directory proper permissions.
    $ sudo echo Hello Web > /var/www/
    $ sudo chmod -R 755 /var/www/
    $ sudo chown -R apache.apache /var/www/
  3. Now we will need to edit the /etc/httpd/conf/httpd.conf file to configure a virtual host for our new website. You can use nano or your favorite text editor and open this file with root permissions.
    $ sudo nano /etc/httpd/conf/httpd.conf

  4. Add the following lines to the bottom of the file, of course replacing the example domain with that of your own. There are a lot more options you can put inside the virtual host directive, but these are the essential lines you’ll need.
    <VirtualHost *:80>
        DocumentRoot /var/www/
    	$ sudo Other Apache config directives, logs etc.
  5. After you’ve made your edits to the httpd.conf file, save your changes and exit it. Then, use the following command to check for any syntax errors in your configuration.
    $ sudo httpd -S
  6. As long as you didn’t get any syntax errors, restart Apache for the changes to take effect.
    $ sudo systemctl restart httpd
  7. As long as your fully qualified domain name is already pointing to your server, everything should be good to go. Otherwise, for testing it is also handy to modify the /etc/hosts file. For example if this is done just locally, add the following line:
    $ sudo -i
    # echo >> /etc/hosts

You should now be able to pull up your website in browser.

Accessing our test website configured through Apache virtual hosts

Accessing our test website configured through Apache virtual hosts

Closing Thoughts

In this guide, we saw how to configure virtual hosts in an Apache web server on Fedora Linux. This allows us to host multiple websites on Fedora, while still only using one network port and letting Apache do all the management for us. As you can see in this guide, the configuration for hosting more than one website is rather easy. For further reading, check out our guide on managing dynamic virtual hosts with Apache and the mod_vhost_alias module.