Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.