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 Setup Your Local Development Environment

Ulrike Pechmann
Ulrike Pechmann
18,211 Points

With this Video i setup mamp. But how am i going to get to the console on my local mamp-Server?

I simply dont know how i make myself able to run .php files from the console like in workspaces. Where to find the console in a local dev environment like mamp?

Michael Walker
Michael Walker
45,428 Points

Hello Ulrike. I see that neither one answered your question. The answer is you CAN'T run php commands from the console like you can with say Python or Java. You have to use the browser by typing in localhost\'name of php file' assuming you have the file in the correct director that MAMP is pointing to.

3 Answers

Once you are running mamp you go into your browser and type

localhost

into the address bar. sometimes this is followed by the port like:

localhost:8080

then you would follow it by the directory of your website in your htdocs.

localhost/website or localhost:8080/website

As long as you have started your php server in mamp youre ready to go. Take the steps that Anton said. Locate the file directory ex in Mac: Application->mamp->htdocs, As long as you have a php file in there you can run it directly from your browser as Anton mentioned.

Hi! This might come a tad late for Ulrike, but maybe someone else has stumbled into this issue.

Since MAMP comes with PHP bundled, it is possible to use this PHP version from the Windows Command Prompt. All you need to do is to tell Windows were PHP is located:

  • Download MAMP and install it.
  • Locate the subdirectory with the PHP package. For the default installation path, this is C:\MAMP\bin\php. There are multiple PHP packages in there. I recommend choosing the newest one. At the time of this writing, this is php7.1.7
  • Copy the full path in which the php.exe is located. For the above example: C:\MAMP\bin\php\php7.1.7
  • Now, this path needs to be added to the PATH environment variable. The Command Prompt uses the PATH to look for php.exe when you type php in the prompt. This article does a good job at describing how to accomplish that for your version of Windows.
  • Once you've done that, open a Command Prompt (Windows Key + R, then type cmd). Note: You need to open a new prompt. Don't use a prompt that's already open. It cannot detect that you changed the PATH.
  • Now, type php --version. If you did everything correctly, you should now see the php version printed. Something like PHP 7.1.7 (cli) (built: Jul 25 2017 09:24:45) ( ZTS MSVC14 (Visual C++ 2015) x86 ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
  • PHP files can be run just like in the Workspace: php filename.php, where filename.php is the file you want to run. You just have to navigate to a folder were you have php files, or create one in the location were the Command Prompt is open at (The location is displayed at the start of the command line, e.g. C:\Users\YourUserName>

If working with the command line is new to you, this article might be a good starting point.

Good luck, and happy programming!