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

PHP not working on MAMP

Hey guys! I'm trying to reach out and try my hand at PHP, but I'm having some issues with testinf my scripts in the browser. I'm on a Mac with OSX, and I've successfully installed MAMP. At least, that's what I'm led to believe by the "Welcome to MAMP" page.

I added a simple test.php file to the htdocs directory, and I can list the directory in the browser. When I click on the test.php file, though, I get an error message. When I add the port number to the localhost, it downloads what appears to be an error file.

I don't know if this error helps, but here's what I'm getting from Chrome: HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

Any ideas?

6 Answers

Mike Costa
PLUS
Mike Costa
Courses Plus Student 26,362 Points

Hi Grey,

In MAMP's preferences, go to the apache tab and see what the apache port is set to (I think by default its 8888). If you file you're trying to test is in your htdocs folder, go to your browser and try:

http://localhost:8888/FileToTest.php

*Edit* I wrote this while you posted your solution.

Also, the MySQL and Apache servers both have the green light.

I FOUND THE ISSUE! Troubleshooting like a boss! I was using the python exponent operator (**) that broke the php file. Habit.

But that raises another question. How can I configure a specific error to throw that will let me know that the problem was in the execution of the script?

Mike Costa
PLUS
Mike Costa
Courses Plus Student 26,362 Points

With php, you can edit the local php.ini file to display errors, or you can add this:

ini_set('display_errors',1);

to the top of your scripts to display errors.

Hmm. Any reason why it works fine without me using the port number?

Mike Costa
PLUS
Mike Costa
Courses Plus Student 26,362 Points

I think it all depends on the way you initially set up your local server. I have MAMP configured where my folders are not located inside the MAMP htdocs directory, so I do use that port number. However, I have a debugger set up through eclipse for projects where it uses port 80 when testing scripts.