Adding multiple sites or subdomains to Apache 2 in Ubuntu
Recently I have started my cloud experience by evaluating and testing out cloud computing at CityCloud the Swedish cloud computing provider. So far it has been a good experience. Anyway when you have your own server then you also want to host multiple sites or subdomains. In a shared hosting environment one would normally have support for handling multiple sites in cpanel or similar. However when you don’t have a panel application then one needs to do that manually and here how I have done that.
First one need to add an A record to your DNS which points to your cloud computer IP address. This step is normally done at your registrar or where you have your name servers for your domain. Say that you have a domain called yourcloud.com and you want to add a subdomain called site1.
Next is the Apache setup.
One could start with following step with a copy of the default site definition
sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/site1.yourcloud.com
or just skip that step and just paste my already predefined site file.
sudo vi /etc/apache2/sites-available/site1.yourcloud.com
Paste following and replace everything with site1.yourcloud.com with your own site and domain name.
<VirtualHost *:80>
ServerAdmin webmaster@site1.yourcloud.com
ServerName site1.yourcloud.com
DocumentRoot /var/www/site1.yourcloud.com/
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
DirectoryIndex index.php index.html
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
Save the file.
To activate your new site then execute command
sudo a2ensite site1.yourcloud.com
And finally restart Apache
sudo /etc/init.d/apache2 restart
Hopefully if your DNS change have kicked in you should now be able to browse to site1.yourcloud.com
No comments