Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I just purchased a domain on Dreamhost, let's say foo.com. I already have hosting, let's say at 123.4.56.789, and have setup a directory foo.com which is accessible at 123.4.56.789/foo.com/. I can set the DNS to point foo.com to that IP, but how do I route it to that folder once it's there? My hosting has a really bad cPanel that gives me almost no help. Can I use .htaccess, or something else? What's the best way to accomplish this?

Edit in response to comment(s): It's VPS hosting, so I have access to http.conf and other system files. Also, yes it's Apache.

share|improve this question
    
Assuming Apache for a second, you would have to create an entry in the httpd.conf or create a site configuration file under sites-available for foo.com which is where the control panel comes in. In a hosting situation on a shared server, you will not have access to these files. Otherwise, you might. What is your hosting situation? It may also help someone answer your question if you can tell us what control panel you have access to. –  closetnoc Mar 24 at 0:11
    
Edited question in response to your comment :) –  MattDiamant Mar 24 at 0:51

2 Answers 2

up vote 1 down vote accepted

It has been a while since I have had to do this so I am a bit rusty. Please excuse any errors.

Here are some Apache documentation links:

http://httpd.apache.org/docs/current/sections.html

http://httpd.apache.org/docs/current/vhosts/

Here are some other reousrces that seem to be good:

http://code.tutsplus.com/articles/apache-2-basic-configuration-on-unix-like-systems--net-26607

https://www.digitalocean.com/community/articles/how-to-configure-the-apache-web-server-on-an-ubuntu-or-debian-vps

It seems like the default installation of Apache needs less configuration since earlier versions. It may be safe to assume that it will answer to requests on the server IP address and port 80.

There are several configuration files to be considered. You can find them in /etc/apache2 or /etc/local/apache2, and the directories sites-available and sites-enabled under the apache2 directory.

The sites-available/default file is the default configuration for your server. If you create no other sites, then this is the only site that will be served. If you only have one site, it is okay to modify this file. Common modifications would be to change the <directory /var/www/> directive to change the directory and to change the AllowOverride from None to All to allow the use of .htaccess files. It would be fine to expect to deploy a website within the /var/www/ directory and it should work.

Otherwise, if you want to host more than one site, then in the /etc/apache2/sites-available directory, create a site configuration file often named using the following scheme domain-name.tld.conf. Here is an example configuration:

<VirtualHost *:80>
SuexecUserGroup "#<user id>" "#<group id>"
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /home/mydomain.com/www
ErrorLog /home/mydomain.com/log/mydomain.com_error_log
CustomLog /home/mydomain.com/log/mydomain.com_access_log combined
AddHandler cgi-script .php
DirectoryIndex index.php index.html
<Directory /home/mydomain.com/www>
Options -Indexes +IncludesNOEXEC +FollowSymLinks
allow from all
AllowOverride All
</Directory>
</VirtualHost>

The <user id> and <group id> need to be replaced with the user id and group id of the user that owns the site. The home, www, and log, directories have to be created in the /home directory and chown, chgrp, and chmod may need to be used to change the ownership and permissions of these directories.

When you are done, create a symbolic link with the same name of the config file you created in the sites-enabled directory pointing to the configuration file you just created.

That should do it. If I missed a step or something needs to be explained better let me know. I will add more or change anything I need to help.

share|improve this answer

Thanks to closetnoc for leading me on the right path by mentioning sites-available.

I used these two articles to solve it:

http://wiki.gandi.net/en/hosting/using-linux/tutorials/ubuntu/virtualhosts

http://twohlix.com/2011/05/setting-up-apache-virtual-hosts-on-centos/

share|improve this answer
    
Glad you got it! I had to run away for a short while and was just answering your question when your answer popped up. You might want to get used to the Apache documentation which can be a bit hard to digest at first. –  closetnoc Mar 24 at 2:02
    
Thanks for your help. If you'd like to answer, your answer will probably be more knowledgeable than me just linking to two answers, and I'll give you the green check. –  MattDiamant Mar 24 at 2:28
1  
Thanks Matt. I am hoping this answer is helpful to someone in the future. If you need more help, let me know. –  closetnoc Mar 24 at 5:21
    
I actually am having some trouble. foo.com is working fine, but www.foo.com is not. In Dreamhost's DNS settings, I have set A records for 123.4.56.789 with name www and blank name. In my vhost file, I have ServerName www.foo.com and ServerAlias *.foo.com. Pinging www.foo.com reveals that it's still going to Dreamhost, and pinging foo.com goes to 123.4.56.789. Pretty sure it's a DNS problem, and I'd like to get www working, along with mail.foo.com, etc. –  MattDiamant Mar 24 at 18:09
    
Typically, you would have an A record for the foo.com and create a CNAME for www pointing to foo.com. Then in the Apache config you would have ServerName and ServerAlias like I have it above. Is this the case in your scenario? –  closetnoc Mar 24 at 18:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.