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

Development Tools

Developing multiple websites locally with MAMP

I'm trying to set up a workflow wherein I can develop multiple web projects on my local machine. My MAMP document root is set to the default, so I'm simply wanting to have directories for each project (e.g. MAMP/htdocs/project-1 or MAMP/htdocs/project-2) that serve as the homepage of each website. So localhost:8888/project-1 is the homepage for Project 1 and so forth.

When I go to localhost:8888/project-1 in the browser, it's just a blank page, but when I go to localhost:8888/project-1/page.php, it shows the page correctly. Is my .htaccess wrong or am I missing some fundamental concept about developing locally?

Any clues at all are most welcome. Thanks, y'all!

1 Answer

Kevin Korte
Kevin Korte
28,149 Points

When you go to localhost:8888/project-1 it's going to look for a file named index (in the case of php, it would be index.php) in that folder. Do you have an index file there? That's the file almost all servers will look for first.

When you go to localhost:8888/project-1/page.php it would show a file called page.php

Hey Kevin. Thanks for the quick response, man! I do have an index.php file in the directory, and that's what is so confusing. I set the top of my htaccess, which is in the project's directory, to this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^!localhost:8888$ [NC]
RewriteRule ^(.*)$ http://localhost:8888/$1 [R=301,L]
RewriteBase /

I'm still a novice at htaccess, so there could be a clue there.

Kevin Korte
Kevin Korte
28,149 Points

Curious, have you tried it without your .htaccess file? I'm a novice too with them, but it looks like you're not wanting to require www in the url (which is fine).

I haven't tried that. I hesitate to simply because it's a large php site I'm setting up a local development environment for, and there are dozens of interlinked pages already on the site. I'd like to keep it a fully functioning replica of the site in production if possible.

Kevin Korte
Kevin Korte
28,149 Points

mmm....I tried you .htaccess file on a test site I have, and it didn't cause any unwanted behavior. So it's in production now? And you're duplicating a dev site to work on it?

Yep. I copied the files via ftp of the live site over to my local machine where I am running MAMP.

Kevin Korte
Kevin Korte
28,149 Points

To test the htaccess file idea, what about just removing it from the directory and putting it somewhere like the desktop, restarting the server, and see if it behaves as you want. If there is no change, just move it back, restart the server and all should be as it was.

I also wonder, depending on the size of this thing, if there isn't some other logic that is playing with routing. When I first read this I assumed this was a brand new site, with two files, index.php and page.php.

Does this site use some sort of framework, MVC logic?

Same thing happening. Blank page on what should be the index. It's a custom template our church hired a development company to build for us, now I and a designer develop and manage the site. It is indeed structured with MVC patterns.

Kevin Korte
Kevin Korte
28,149 Points

Is it an MVC library like Cake, CodeIgnighter, Laravel, Slim....or is it a custom MVC?

I believe it's all custom.

Kevin Korte
Kevin Korte
28,149 Points

Fun...lol. A quick test I'd try is set up another simple, empty project with a index.php, and page.php, and see if your localhost does route to index.php by default.