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
Peter G.
Courses Plus Student 5,806 PointsTrouble with PHP files
Hello everybody. I'm having trouble viewing my php files in localhost. I launch the xampp, and then when I try to view a php file in google chrome, it doesn't work, it just shows the code I've written in the text editor. I really need help. Thank you everybody.
5 Answers
Freek Wevers
Courses Plus Student 14,599 PointsIs the php file you're trying to view in the right directory?
By default xampp is looking in the htdocs directory inside your xampp installation folder. If your project files are in the htdocs directory then you can access those files (and have xampp parse them) by typing "localhost/filename.php" in your address bar, where "filename.php" is the name of the file you're trying to view.
You can also put your project files in a separate folder, but that folder also needs to be inside the htdocs directory. Let's say you created a project folder called "project" inside your htdocs folder and stored your project files there, then you can access those files by typing "localhost/project/filename.php". Bottom line is that your php files need to be in the htdocs folder for xampp being able to handle them.
If you try to open the php file by locating the file in windows explorer and then right click - open with chrome, then chrome is opening the php file without having your local webserver (the webserver that comes with xampp) interpret your code. Keeping in mind that php is a server side programming language it should be clear that your browser cannot do this by itself. It needs the webserver to do the interpreting of the php file and serve information that a web browser can handle (html).
I hope this answer helps you out.
Andres Altuve
16,274 PointsPeter if you double click on the file it won´t open, you must open any web browser and type (IN MY CASE)
localhost/treehouse/php/index.php
Hope it helps..
Kevin Kenger
32,834 PointsHey Peter,
Are your files named correctly? I had a similar experience due to having my index.php file named index.html.
Michalis Efstathiou
11,180 Pointsalso remember that after you launch xampp, you need to open the control panel and start the apache server by clicking the start button next to it
Peter G.
Courses Plus Student 5,806 PointsThank you for the help. I learnt something today that wasn't covered in the php beginner course. :) Freek's answer really explained and helped me a lot with what I was doing wrong. -Andreas it looks we were having the same problem. -Kevin, it's something to keep in mind.