
Multiple domains in apache2 Ubuntu16
The idea of this tutorial is to setup a configuration with multiple domains active in a single server.
This guide is “stolen” from various sources through internet. For the example, we’ll setup the site example.com to run on a server with IP 1.2.3.4 .
We assume that you have already installed apache2 all the required modules, php etc and the web server is running. First step is to create the desired directory structure:
sudo mkdir -p /var/www/html/example.com
Next we need to provide ownership to the apache2 account:
chwon -R $user:$user /var/www/html/example.com
You need to substitute $user with the web user, which can be seen in apache configuration. Set proper permissions:
chmod -R 755 /var/www/html/example.com
Next create some basic index file.
vi /var/www/html/example.com/index.php
Fill some bulk info – I usually create one containing phpinfo, as it provides useful information:
<?php
echo '<h1>Work in progress</h1>';
phpinfo();
?>
Next we need to create the proper configuration for the new site:
cd /etc/apache2/sites-available
sudo cp 000-default.conf example.com.conf
Then add the correct configuration:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/example.com
<Directory /var/www/html/example.com>
Options Indexes FollowSymlinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Next we need to enable the newly created config file
sudo a2ensite example.com
Add some neccessary configuration to the hosts file:
sudo vi /etc/hosts/
1.2.3.4 example.com
And finally – restart apache, so settings can take effect.
sudo service apache2 restart
The above steps were done just before enabling this site on my staging server, (Ubuntu 16) so I assume this should work. Good luck!
Similar blog posts

Elasticsearch cheat sheet
Search Count AND query OR query Query with date range Multiple Queries Or a query inside a query Sort by a date containing field Query with regex Point In Time...
Odroid Sensors
Not long ago I bought an Odroid ARM based mini PC, and among many issues, turned out that the system uses some rather strange scheme for controlling the fan speed....
“Kubernetes network isn’t reliable”
Recently, while trying to figure out an extrelemly annoying problem I was having with Kubernetes – I stumbled upon this marvel of a github issue. So if you ever need...