Problem with root and virtual host

July 4, 2013 5.8k views
Hi, I have installed lamp stack on centos for my domain1.com. Now I have created virtualhost for domain2.com. At first domain1 was pointing to the starting page of "apache ", but after I created virtual host for domain2.com and created a new file index.php, domain1.com is pointing to the same index.php for domain2.com. Please help how to get the domain1.com "apache page" or how to proceed so that both the domains are pointing to their respective root directory. Thanks in advance
19 Answers
Please post your directory structure and pastebin your apache virtualhost configs.
Sorry to say ...but I am a total newbie.. how to post my directory structure? and how to I copy the contents of virtualhost configs. from vi editor
You can run the following command to paste a file to sprunge.us:

cat /etc/apache2/sites-enabled/filename | curl -F 'sprunge=
(Make sure you replace "filename" with the actual virtualhost file name).
Hi, my link for vhost is here -- http://pastebin.com/8ptA0BWC
Thanks for your help
What's the output of "ls /etc/apache2/sites-enabled"?
ls: cannot access /etc/apache2/sites-enabled: No such file or directory - there is an error message for this command
the above virtualhost file content has been taken from /etc/httpd/conf/httpd.conf
Sorry, "ls /etc/httpd/sites-enabled"
There is no "sites-enabled" directory in httpd.
the structure of httpd are :"conf conf.d logs modules run" only
Hmm. What's the output of "ls /etc/httpd/conf.d"?
output of ls /etc/httpd/conf.d = " README php.conf phpMyAdmin.conf phpMyAdmin.conf.rpmsave welcome.conf"
> but after I created virtual host for domain2.com

Where did you create that file?
I just created the entry for virtualhost in " /etc/httpd/conf/httpd.conf" as mentioned in the article https://www.digitalocean.com/community/articles/how-to-set-up-apache-virtual-hosts-on-centos-6.

then I create a file in /var/www/domain2.com/public_html/test.php... after that both the domain started pointing to this file
I see only one VirtualHost (creativejuniors.com). Are you sure you saved the file after adding the new one?

You also have "ServerName creativejuniors.com" twice in your VirtualHost, delete one of them.
I think I have messed up everything - should try with a new installation nothing is working good.
Thanks a lot for your help
@kamal
@hypertextsol,

Have you checked out this article?: How to Set Up Apache Virtual Hosts on CentOS 6
by Etel Sverdlov
This tutorial shows you how to set up a new directory, how to grant the correct permissions, how to add content to a new page, how to turn on virtual hosting, and how to, if needed, set up local hosts. Virtual Hosts are used to run more than one domain off of a single IP address and allows you to run multiple sites off of a single DigitalOcean droplet. This tutorial describes how to set up virtual hosts with Apache on Centos
what should be the root directory of the domain1.com to which I have assigned the droplet -- i.e. I have assigned domain1.com to the droplet and domain2.com is the addon domain.
As I have created the domain2.com directory structure as "/var/www/domain2.com/public_html/test.php" but I never created the same for domain1.com
"what should be the root directory of the domain1.com ..."

It's a matter of personal preference. It's okay to have domain1.com's root directory be
/var/www/
; or, if you want to be consistent across all domains, have the root directory be
/var/www/domain1.com/public_html/


The key is to make sure that whatever root directory you choose is accurately stated in each virtual hosts' file in the
/sites-enabled
folder
Hi hypertextsol!

you try to place namesarver directives in first position. Example:


ServerName www.domain1.com
ServerAlias domain1.com
ServerAdmin webmaster@domain1.com
DocumentRoot /var/www/domain1.com/public_html



ServerName www.domain2.net
ServerAlias domain2.net
ServerAdmin webmaster@domain2.net
DocumentRoot /var/www/domain2.net/public_html


I had the same problem and this solved it
Have another answer? Share your knowledge.