Creating subdomain / virtualhost in apache on CentOS 6.2

SAFC picture SAFC · Mar 11, 2012 · Viewed 34.7k times · Source

I've been trying to make a subdomain to host my forum to make it look better than www.mydomain.co.uk/forum/index.php i want it to be forum.mydomain.co.uk

I've tried all the tutorials, guides and everything i've found on google, but nothing works. I've tried using webmin but that just made things more complicated and i had to reinstall everything from scratch because it wrecked it up. Here's what i have below, could anyone tell me if there's anything other than this that i must do for the subdomain to work?

The contents of my httpd.conf are:

NameVirtualHost *:80

<VirtualHost *:80>
     ServerAdmin [email protected]
     ServerName forum.mydomain.co.uk
     DocumentRoot /var/www/html/forum
     ErrorLog logs/forum-error_log
     CustomLog logs/forum-access_log common
</VirtualHost>

The domain itself works. It points to my apache page which is what I need for now because I haven't uploaded anything. When I go to mydomain.co.uk/forum it, shows the index of forum contents. forum.mydomain.co.uk shows page cannot be displayed / unable to resolve host.

Are there any other files i must configure for this to work?

Answer

t q picture t q · Mar 11, 2012
  • go to your registrar and point the sub-domains A-Record to your static ip
  • inside httpd.conf make sure this line exists: NameVirtualHost *:80

the name of my folder where all the html and php files reside: mydirectory
full path from root: /var/www/mydirectory
this is my httpd.conf on ec2 linux

<VirtualHost *:80>
    ServerName www.beta.myDomain.com
    ServerAlias beta.myDomain.com
    ServerAdmin [email protected]
    DocumentRoot "/var/www/mydirectory"
    <Directory /var/www/beta.myDomain.com/>
            AllowOverride All
            Allow from all
    </Directory>
</VirtualHost>
  • then after all that is done reload your webserver: sudo service httpd reload
  • remember that it can take up to 24 hours for the registrar to propagate