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 trialSam Dale
6,136 PointsConfused 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!
Simon Coates
28,694 PointsI'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
6,136 PointsSimon 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
28,694 Pointswhat 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
6,136 PointsSimon Coates Oh! I got what you were saying in your first comment. Now everything is working using MAMP. Thanks for the help!
Simon Coates
28,694 PointsGood. 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
14,943 PointsThought 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
Sam Dale
6,136 PointsSam Dale
6,136 PointsAnd if I run it as index.html in my browser, there are just blank spaces where the name should be.