Typically if one wants to setup separate virtual host configurations, you would place them in this directory:
/etc/apache2/sites-available/
So if you have a virtual host named www.example.com
the config filename can be named www.example.com.conf
like this:
/etc/apache2/sites-available/www.example.com.conf
You would then open that file in a text editor like this; I’m using nano
as an example but feel free to use whatever text editor you prefer:
sudo nano /etc/apache2/sites-available/www.example.com.conf
And then place content similar to this into www.example.com.conf
:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Close and save that file and then use a2ensite
like this to have the system set a symbolic link from sites-available
to sites-enabled
like this:
sudo a2ensite www.example.com.conf
Or—if you wanted to—you could manually use ln -s
to set a symbolic link like this:
ln -s /etc/apache2/sites-available/www.example.com.conf /etc/apache2/sites-enabled/www.example.com.conf
When that’s done just reload Apache like this:
sudo service apache2 reload
And if for some reason reload
doesn’t work, just force a restart like this:
sudo service apache2 restart
The benefit of using reload
before restart
is that if there is a typo in a config file, Apache will report an error but not load the config files. Meaning your Apache web server will still be up and running based on the last stable configuration file it loaded.
The risk is that if you force a restart
and there is a typo in a configuration file, Apache will be dead because restart
forces a complete service stop
followed by a start
. And if that start
chokes, the server is dead until the config typo/issue is cleared up.
httpd.conf
file, it should contain a line like Includeconf/*.conf
. Check whether it is a wildcard or a fixed file (like000-default.conf
). Also, check that your new conf files match the wildcard patern and are stored on the same folder as the000-default.conf
. Finally, there are apache distributions where they have aavailable
and aactive
conf files, so in some cases a soft link is needed in order for it to work.