Setting Up Subdomains
I thought that following the same procedure to create a new virtualhost but using the subdomain as the ServerName would work.
But I couldn't get it to work, am I missing something here?
6 Replies
Do you have a DNS record for your subdomain pointing to your Linode's IP address?
Does the ServerName directive for your subdomain conflict with anything else you've set up? (Is it listed as a ServerAlias in another virtualhost? Is it covered by a wildcard ServerName in another virtualhost? Is it identical to your Apache server's default ServerName?)
This is the main domain that is working. I have another domain using the same codes/layout
# Notes
<virtualhost *:80=""># Admin Details
ServerAdmin webmaster@wpthoughts.com
ServerName wpthoughts.com
ServerAlias www.wpthoughts.com
# Index and Document Root
DirectoryIndex index.php index.html
DocumentRoot /var/www/wpthoughts.com
# Log Files
LogLevel warn
ErrorLog /var/www/wpthoughts.com/logs/error.log
CustomLog /var/www/wpthoughts.com/logs/access.log combined</virtualhost>
And this is the file for the subdomain that isn't working.
# Notes
<virtualhost *:80=""># Admin Details
ServerAdmin webmaster@wpthoughts.com
ServerName themes.wpthoughts.com
# ServerAlias www.wpthoughts.com
# Index and Document Root
DirectoryIndex index.php index.html
DocumentRoot /var/www/themes.wpthoughts.com
# Log Files
LogLevel warn
ErrorLog /var/www/themes.wpthoughts.com/logs/error.log
CustomLog /var/www/themes.wpthoughts.com/logs/access.log combined</virtualhost>
Here is the DNS render file
$TTL 86400
@ IN SOA ns1.linode.com. andrewjbarnett.gmail.com. (
2009012406
7200
7200
1209600
86400
)
@ NS ns1.linode.com.
@ NS ns2.linode.com.
@ NS ns3.linode.com.
@ NS ns4.linode.com.
@ MX 10 ASPMX.L.GOOGLE.COM.
www A 72.14.181.193
@ A 72.14.181.193
themes CNAME wpthoughts.com.
I did 'a2ensite' for the subdomain, and restarted Apache2 as well without success.
# a2dissite default
# /etc/init.d/apache2 reload
Then try your subdomain again.
@dcelasun:
The "default" site might be interfering with your subdomains. Try running
# a2dissite default # /etc/init.d/apache2 reload
Then try your subdomain again.
Depending on your distribution, you might get undesirable behavior if you disable the default site. Just make sure that nothing in the default site interferes with any other virtual host.
One common problem involves the hostname. If you have manually set your hostname in /etc/hostname and/or /etc/apache2/apache2.conf, you must make sure that it is different from all the other domains/subdomains being hosted.
How exactly is it "not working"? What are the symptoms?
I changed the A record to a CNAME record, and OpenDNS has the correct IP address against the domain now.
However PHP isn't being parsed anymore. I navigate to the domain, and the my browser downloads the php file rather then parsing it.
@sphinx:
However PHP isn't being parsed anymore. I navigate to the domain, and the my browser downloads the php file rather then parsing it.
Now that's a bigger problem!
What's your distro? If it's Debian or Ubuntu, apt-get install libapache2-mod-php5 automatically sets everything up (assuming that you're using Apache2 with PHP5)
But please, reenable the default site and try to tinker with only those settings in the default file that you suspect is causing a problem. Depending on your distro and version, the default file might contain important configuration directives (e.g. NameVirtualHost).
And again, it's not helpful to just say "it doesn't work". What's happening? Does your subdomain show another site? Does it throw a 404? Or is it the PHP problem you described above?