I have a personal VPS hosted in * and an ubuntu installation. The ubuntu runs apache,php,mysql and is currently being used for 5 websites mapped by virtualhosts. I am writing the whole procedure in case someone needs it.
When I want to add a new domain, I create an
127.0.0.1 test.com *.test.com row in
/etc/hosts, add a new file in
run a2ensite test.com - then restart apache. Each website has its own folder in
/var/www and the virtualhost entry looks like this :
# Admin email, Server Name (domain name) and any aliases
ServerAdmin [email protected]
ServerAlias test.com *.test.com
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
allow from all
I am planning to add some aliases like
ccc.test.com etc. which will point/forward to different folders. The
aaa.test.com one will point to
/var/www/aaa/index.php and the
/var/www/bbb/index.php. To summarize, different aliases - same domain - different folders all in apache. How do I achieve that ?
As aaa.test.com and bbb.test.com should point to different directories, You are required to create separate Virtualhost entries manually. Before that you have to remove the _*.test.com_ from the ServerAlias of test.com Virtualhost entry. Then create a file at /etc/apache2/sites-available , say aaa.test.com and add the following and then save
<Virtualhost *:80> ServerName aaa.test.com DirectoryIndex index.html index.php DocumentRoot "/var/www/aaa/" </Virtualhost>
make sure to restart/reload the apache service.
Do the same for bbb.test.com.. That is all you required to do... All d best :)
There can only exist one
VirtualHost container. Since you have specified different
DocumentRoot for each
bbb.test.com etc, you need to setup a separate
VirtualHost for each:
<VirtualHost *:80> ServerName aaa.test.com DocumentRoot /var/www/aaa DirectoryIndex index.php index.html ... </VirtualHost>
and so on.