Question

Problem with root and virtual host

  • Posted July 4, 2013

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

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi hypertextsol! <br> <br>you try to place namesarver directives in first position. Example: <br> <br><VirtualHost *:80> <br> ServerName www.domain1.com <br> ServerAlias domain1.com <br> ServerAdmin webmaster@domain1.com <br> DocumentRoot /var/www/domain1.com/public_html <br></VirtualHost> <br> <br><VirtualHost *:80> <br> ServerName www.domain2.net <br> ServerAlias domain2.net <br> ServerAdmin webmaster@domain2.net <br> DocumentRoot /var/www/domain2.net/public_html <br></VirtualHost> <br> <br>I had the same problem and this solved it

“<strong>what should be the root directory of the domain1.com …</strong>” <br> <br>It’s a matter of personal preference. It’s okay to have domain1.com’s root directory be <pre>/var/www/</pre>; or, if you want to be consistent across all domains, have the root directory be <pre>/var/www/domain1.com/public_html/</pre> <br> <br>The key is to make sure that whatever root directory you choose is accurately stated in each virtual hosts’ file in the <pre>/sites-enabled</pre> folder

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. <br>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

@hypertextsol, <br> <br>Have you checked out this article?: <a href=“https://www.digitalocean.com/community/articles/how-to-set-up-apache-virtual-hosts-on-centos-6”>How to Set Up Apache Virtual Hosts on CentOS 6</a>

I think I have messed up everything - should try with a new installation nothing is working good. <br>Thanks a lot for your help <br>@kamal

I see only one VirtualHost (creativejuniors.com). Are you sure you saved the file after adding the new one? <br> <br>You also have “ServerName creativejuniors.com” twice in your VirtualHost, delete one of them.

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. <br> <br>then I create a file in /var/www/domain2.com/public_html/test.php… after that both the domain started pointing to this file

but after I created virtual host for domain2.com <br> <br>Where did you create that file?

output of ls /etc/httpd/conf.d = " README php.conf phpMyAdmin.conf phpMyAdmin.conf.rpmsave welcome.conf"

Hmm. What’s the output of “ls /etc/httpd/conf.d”?