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
|Category||Requirements, Conventions or Software Version Used|
|Software||Apache web server|
|Other||Privileged access to your Linux system as root or via the |
|Conventions|| $ sudo - requires given linux commands to be executed with root privileges either directly as a root user or by use of |
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.
- Start by creating a new directory which will contain the website's files. Typically this is somewhere inside the
$ sudo mkdir /var/www/example.net
- Next, place your site files into the directory. Just as an example, we'll create a simple
index.htmlfile for testing. After that, we need to give the directory proper permissions.
$ sudo echo Hello Web > /var/www/example.net/index.html $ sudo chmod -R 755 /var/www/example.net $ sudo chown -R apache.apache /var/www/example.net
- Now we will need to edit the
/etc/httpd/conf/httpd.conffile 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
- 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> ServerName www.example.net ServerAlias example.net DocumentRoot /var/www/example.net $ sudo Other Apache config directives, logs etc. </VirtualHost>
- After you've made your edits to the
httpd.conffile, save your changes and exit it. Then, use the following command to check for any syntax errors in your configuration.
$ sudo httpd -S
- As long as you didn't get any syntax errors, restart Apache for the changes to take effect.
$ sudo systemctl restart httpd
- 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/hostsfile. For example if this is done just locally, add the following line:
$ sudo -i # echo 127.0.0.1 www.example.net example.net >> /etc/hosts
You should now be able to pull up your website in browser.
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.