Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

MAMP & htdocs - How do I demo multiple sites?

So I am working through the "Buld a simple PHP application" project, and it's great. As I move through it, I would like to create another project that is more relevant to what I want to do. My question is, what is the best way to do this?

Is htdocs the only folder that is recognizable by MAMP? Can I have multiple projects going within the htdocs folder? I would imagine that if I have more than one project in that folder and I run "localhost" in the browser, MAMP will be confused. Anyone have a good way to do this?

Thanks!

3 Answers

I am currently running 5 different web projects under my htdocs folder.

I have it structured like Spen mentioned. I have subfolders inside my htdocs folder that are named after the project. In my browser I type localhost/project3 for instance to view and working on the third project in there.

The big trick is keeping your links, images, CSS, etc from breaking since that projects root is not the servers root.

To keep that from happening, I used Randy's lesson on setting up a config file for each project, defining the BASE_URL and ROOT_PATH variables to that particular name for that project.

Then I can use keep my links happy and working. Plus if I ever want to change the name of my project, I can in one location and all of my links and includes should still work.

How to do that is in Randy's PHP lessons.

Thanks Kevin, do you know the exact name of the lesson where Randy covers this? Thanks!

It mostly starts in this lesson http://teamtreehouse.com/library/programming/enhancing-a-simple-php-application/cleaning-urls-with-subfolders. But you may need to back up further to understand it. He uses this as a way of having clean urls with multiple subfolders, but essentially that is what you are doing anyway having more than one site in your htdocs.

Thanks!

Hi Chance,

It's as simple as keeping your multiple sites in sub directories within htdocs.

For example :

htdocs/exampleone - would be one site,

htdocs/exampletwo - would be another

htdocs/.... etc.

And to access them in your browser, either just go to localhost and choose the site that you want to see, or go to:

localhost/exampleone or localhost/exampletwo

:)

Thanks Spen and Kevin!

Thanks this was helpful!