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 Basics PHP on the Web Don't Repeat Yourself

Sam Dale
Sam Dale
6,136 Points

Confused about local PHP setup

Hi there. I'm trying to follow along at home and she said to rename index.html to index.php and insert some php code blocks in the middle of the HTML. When I run it in my browser locally, it's just a plain text file with all the code. Executing in the Terminal does nothing either. But it works in the Treehouse workspace.... What's up with that?

Thanks!

Sam Dale
Sam Dale
6,136 Points

And if I run it as index.html in my browser, there are just blank spaces where the name should be.

Simon Coates
Simon Coates
28,694 Points

I'm assuming you've actually turned on the server, and are trying to access index.php using the http protocol not the file protocol (what it uses when you click on it within windows explorer). Should be able to tell based on the complete URL. It may seem simplistic but it's easy to download wamp (or xampp/mamp) and forget to actually run the server, to click on the file rather than use a localhost url. Some beginners might also mess up the rename if windows doesn't show file extensions. It'd lead to wondering why a file named something like "index.php.html" or "index.php.txt" wasn't working. Anyhow, the starting point is to rule out the obvious.

Treehouse workspaces should provide you with a properly configured PHP server, will tend to be accessed via the browser (hence http:// not file://) and doesn't enable silly stuff like bad extensions.

Sam Dale
Sam Dale
6,136 Points

Simon Coates Hi there. I don't have a server turned on. How exactly do I go about doing that locally? Is it something to do with using apache?

Simon Coates
Simon Coates
28,694 Points

what server stack did you install? xampp? wamp? mamp? (the a in all of those is apache). You just need to install one of them and then run the executable file for that particular server. (probably have the same name as the server stack). Once you got the server running, you confirm by accessing it with http://localhost/ and it should display a default page. Once you confirm the server is running, you can put your .php file in the default folder for php files (for wamp this is wamp\www, while for xampp, the folder is probably xampp\htdocs). You should be able to find fairly recent videos on youtube that cover the install and initial acess for any given server stack.

Sam Dale
Sam Dale
6,136 Points

Simon Coates Oh! I got what you were saying in your first comment. Now everything is working using MAMP. Thanks for the help!

Simon Coates
Simon Coates
28,694 Points

Good. Glad it worked. The stacks should work out of the box, and when they don't, debugging what's gone wrong is hellish. Glad we were spared that.

1 Answer

Daniel Breen
Daniel Breen
14,943 Points

Thought I'd add that php has a built-in web server from version 5.4 and up.

You can just run php -S localhost:8000 from the command line