Setting Up Apache Virtual Hosts on Fedora
Apache HTTP server is capable of hosting multiple websites on the same server. The feature is popularly known as virtual host.
The term Virtual Host refers to the practice of running more than one web site (such as www.company1.com and www.company2.com) on a single machine. When you configure virtual hosts your web server runs many websites at any given instance. You don't need to edit Apache configuration file and restart Apache every time you switch to a different website.
Follow the instructions below to configure virtual hosts in Apache.
Step 1: Open the Apache configuration file to edit it
Step 2: Add the below directive to the Apache configuration file since we are using name-based virtual hosts. This directive tells the server to use any and all IP addresses on the machine.
Step 3: Add the VirtualHost block to each different website in the Apache configuration file
<VirtualHost *:80> ServerName website1.example.com DocumentRoot /var/www/html/website1 </VirtualHost>
The above block tells the server to run website1.example.com using the document root /var/www/html/website1.
Step 4: Add as many virtual hosts as you want using VirtualHost blocks like below:
<VirtualHost *:80> ServerName website2.example.com DocumentRoot /var/www/html/website2 </VirtualHost>
Save the file and exit.
Step 5: Restart Apache
The virtual host configuration is done. If the hostnames are fictitious like this example,you have to add the hostnames in your network configuration.
Step 6: Open /etc/hosts
Step 7: Add the host names
127.0.0.1 website1.example.com 127.0.0.1 website2.example.com
save the file and exit.
You will now be able to access http://website1.example.com and http://website2.example.com from your browser. At any given instance your local web server runs both website1.example.com and website2.example.com How convenient it is to work on multiple websites with virtual hosts!
I use subdomains of example.com while testing websites on my desktop because they don't exist in the Internet.
Apache allows overriding certain directives using a .htaccess file. You might want to allow .htaccess files to override all possible directives.
In your httpd.conf file, find the section with the following
<Directory /> Options FollowSymLinks AllowOverride none </Directory>
Change AllowOverride from 'none' to 'all'. After changing the settings your file should look like
<Directory /> Options FollowSymLinks AllowOverride All </Directory>