Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

xper

macrumors 6502
Original poster
Dec 15, 2005
430
3
Sweden - Halmstad
Hi!

I´ve read the virtual host documention for Apache2 but i still cant get it to work.

Currently i am using MAMP to develop my homepage, current adress is localhost:20000 and i still want to be able to use the localhost:port setup to get to the page localy, and be able to use my domain www.rogatio.com to get to the homepage, how do i solve that with vhosts?

Currently it looks like this:

Listen 20000

NameVirtualHost localhost:20000

<VirtualHost localhost:20000>
ServerName localhost:20000
DocumentRoot "/Applications/MAMP/htdocs_rogatio.com/"
</VirtualHost>
 
Using this example:
Code:
NameVirtualHost *:80

<VirtualHost *:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>

Change you ServerName directive.
 
Look how you defined ServerName. You included a port. You should put just localhost, or your website.domain.tld, in there. In essence, you put in the ServerName directive whatever someone is going to type in their web browser to get to that site.
 
Ok, so now it looks like this:

PHP:
Listen 20000

NameVirtualHost localhost:20000

<VirtualHost localhost:20000>
ServerName localhost:20000
DocumentRoot "/Applications/MAMP/htdocs_rogatio.com/"
</VirtualHost>

NameVirtualHost *:20000

<VirtualHost *:20000>
ServerName www.rogatio.com
ServerAlias rogatio.com *.rogatio.com
DocumentRoot "/Applications/MAMP/htdocs_rogatio.com/"
</VirtualHost>

I can access localhost:2000 but not www.rogatio.com
 
Ok, so now it looks like this:

PHP:
Listen 20000

NameVirtualHost localhost:20000

<VirtualHost localhost:20000>
ServerName localhost:20000
DocumentRoot "/Applications/MAMP/htdocs_rogatio.com/"
</VirtualHost>

NameVirtualHost *:20000

<VirtualHost *:20000>
ServerName www.rogatio.com
ServerAlias rogatio.com *.rogatio.com
DocumentRoot "/Applications/MAMP/htdocs_rogatio.com/"
</VirtualHost>

I can access localhost:2000 but not www.rogatio.com

If you ping www.rogatio.com, does it return the IP of your system or localhost?
 
Make sure you have this in your httpd.conf just before your virtual host declarations. This should make sure permissions are setup properly.
Code:
<Directory "/Applications/MAMP/htdocs_rogatio.com">
 Order Deny,Allow
 Allow from all
</Directory>
You'll also need to edit the /etc/hosts file for the server name you're using. Open Terminal and do a,
Code:
sudo pico /etc/hosts
It'll have something like,
Code:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1	localhost
255.255.255.255	broadcasthost
::1             localhost
At the end add the line
Code:
127.0.0.1 www.rogatio.com
Then save it and restart the web server.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.