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 trialM Glasser
10,868 PointsGuessing this won't work on a basic local server?
Using atom and the atom-live-server package to preview and edit the downloaded project files for this course. Followed the instructions and added php code block then changed the name of index.html to index.php. Now my localhost in the browser shows the directory rather than interpreting the index.php file as the index. Can anyone explain what's happening? My guess is the local server I have set up is not capable of processing PHP.
2 Answers
andren
28,558 PointsIn order to use PHP with web content you do indeed need a server that is compatible with PHP, as well as to have PHP installed on the machine the server runs on. From what I can see the server that atom-live-server is based on is only designed to handle plain HTML, CSS and JavaScript content.
There are plenty of local servers compatible with PHP though. Including one that is built into PHP itself, which can be used within Atom through the php-server package.
So if you download PHP on to your machine and use the package above or some other PHP compatible server then you should have no issues testing PHP on your local machine.
Jonathan Kuhl
26,133 PointsYou can also try the built-in php server that comes with the PHP installation:
Run the following from your project's directory:
php -S localhost:3000
3000
can be replaced by any other valid port number of your choosing. More information is in man php
Run localhost:3000 in your browser and your project should be there. It will auto detect and load index.html or index.php (but it's not a good idea to name the php file "index")
Seth Johnson
15,200 PointsThank you Jonathan! I was very, very puzzled about this for awhile. It worked exactly the way I needed it to.
M Glasser
10,868 PointsM Glasser
10,868 PointsOk cool! Thanks! Actually got this working in MAMP, but would rather use something like atom for these basic exercises.