IDIOTS GUIDE TO VHOST SETUP IN MAMP PRO

Any wishes or suggestions for MAMP?
Post here what functions you are still missing for MAMP.

Moderator: severin

Post Reply
Chris Edeling
Posts: 1
Joined: Fri 16. Mar 2012, 07:38

IDIOTS GUIDE TO VHOST SETUP IN MAMP PRO

Post by Chris Edeling » Fri 16. Mar 2012, 08:09

After struggling to set up virtual hosts in MAMP PRO I eventually figured it out. The input fields did not make sense to me and I found the documentation confusing. Here are the notes I made to remind me how to do it next time. NOTE that this is just for idiots like me who do not know what they are doing. I hope this will help some folks to get started.


IDIOT'S GUIDE TO SET UP VHOSTS IN MAMP PRO

Purpose

Assume that we want to give `example_site` an easy url to domain.com.

Instead of using url http://www.domain.com/example_site we want to give them sub1.domain.com


Step 1 MAKE A DNS POINTER

The internet must know what to do with url sub1.domain.com which does not yet exist. Your DNS server must make sure that sub1.domain.com points to your server.

I got my domains from godaddy.com, so I go to godaddy client area and manage domains with DNS manager. This is what works at godaddy DNS.

Select the domain we want to use for sub1, in this case domain.com.

Add an entry under CNAMES

On left side enter `sub1` (without the quotes) and on the right enter `@`

Save the change and wait about an hour for the dns to spread the world

From now on every call to sub1.domain.com will go to the same IP that domain.com goes to

Our server must now be set up to handle calls to sub1.domain.com and direct them to the correct place

Step 2 MAKE A TARGET DIRECTORY

This step is not necessary, but may make file management on the server easier to follow.

On the server, make a new directory which will serve as the target for url calls to sub1.domain.com.

This new directory will be used in the next step to set Disk location (document root) for sub1.

For example, under /Applications/MAMP/htdocs make a subdir called `www.sub1.domain.com`.

The only reason for this is so we can easily see what vhosts we have and organise them together.

In the next step, using MAMP PRO, we will send sub1.domain.com to our server directory

/Applications/MAMP/htdocs/www.sub1.domain.com

instead of directly to

/Applications/MAMP/htdocs/example_site




Step 3 MAKE A VHOST ON OUR SERVER

OPEN MAMP PRO

Left part - use upper tab for Hosts

Lower left click + to add an entry

Right upper tab General (don’t use the other tabs)

For Server Name enter `sub1.domain.com` - cos this is what the DNS server told the world to use when they want this

checkboxes for Local name resolution and SSL remain UNCHECKED

IP / Port - leave the default suggested ie `*`

Dynamic DNS - leave - unchanged

Disk location: enter /Applications/MAMP/htdocs/www.sub1.domain.com
(if you made this the new target directory. Otherwise enter /Applications/MAMP/htdocs/example_site

Permissions must be unchanged, click it and ensure that Owner = administrator and others = admin

Apply at lower right and restart servers.

Step 4 PUT an index.php IN THE NEW TARGET DIR

make a suitable index.php and save it to

/Applications/MAMP/htdocs/www.sub1.domain.com


WARNING ABOUT CHANGE TO $_SERVER[`DOCUMENT_ROOT`]

Be aware that the vhost made with MAMP PRO gives this vhost
the $_SERVER[`DOCUMENT_ROOT`] which you entered for Disk location
which in this case is /Applications/MAMP/htdocs/www.sub1.domain.com

If you still have your files in /Applications/MAMP/htdocs/example_site
and if any of those files have a call to $_SERVER[`DOCUMENT_ROOT`]
it will try to call
/Applications/MAMP/htdocs/www.sub1.domain.com/example_site
which may not exist

Suggestion:

EITHER move all the files in htdocs/example_site to htdocs/www.sub1.domain.com

or, if you must still use your calls to $_SERVER[`DOCUMENT_ROOT`] to refer to htdocs/example_site, then ensure that the index.php which you put in htdocs/www.sub1.domain.com has a redirect to
htdocs/example_site/index.php
or else make sure that files are called using

$_SERVER['SERVER_ADDR'].`:`.$_SERVER['SERVER_PORT']

Of course there are various ways to solve this problem,
as long as you realise that $_SERVER[`DOCUMENT_ROOT`] now
points to /htdocs/www.sub1.domain.com and no longer to /htdocs

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests