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 trialRhys Baker
8,200 PointsMy First PHP File is only showing up as html text. My server is on. What am I doing wrong?
I typed everything the man in the computer told me to but when I put the file on my local host it only printed the html text. Is there something I have to do to connect the file to the server?
11 Answers
Rhys Baker
8,200 PointsSo the problem was that I was trying to open my file from my text editor when I should've been going through localhost. Thanks for the help y'all.
Glen Burnett
Courses Plus Student 27,349 PointsWhen you say its only showing html text is it showing the current copyright year date at all? Also, when you saved your file, did you save it as a php file or a html file? Also yes most definitely, make sure you have your local server running in order for your php code to work.
Glen Burnett
Courses Plus Student 27,349 PointsHrm.
Curious. Ideally the only time as far as I am aware it should behave the way you are describing is if local server is not running or the file has been saved as something other than a php file.
Glen Burnett
Courses Plus Student 27,349 PointsAt the bottom of the forum there is a markdown cheat sheet for showing you how to show your code in a forum comment. Post what you have there and also, quick question, are you running Mac or Windows?
thomascawthorn
22,986 PointsHave you placed php code inside opening and closing php tags?
<?php
echo date(Y);
?>
Glen Burnett
Courses Plus Student 27,349 PointsThat was going to be my next question ;)
Rhys Baker
8,200 PointsNo, it's showing the php code. I saved the file as php, which is what I think the guy in the video did. The server is running. Thanks Glen.
Rhys Baker
8,200 PointsWait, the problem isn't solved yet, the server was running when I started. I should've saved the file in php write?
Glen Burnett
Courses Plus Student 27,349 PointsYeah sorry Rhys, I deleted my "you're welcome" comment after I read your reply a second time. See below reply
Rhys Baker
8,200 PointsYou've still been help, thanks for the attempt. My server must be acting strange and not affecting the file or something.
Rhys Baker
8,200 PointsI'm running mac. The file is test.php. Here's the code. ''' <!DOCTYPE html> <html> <head> <title> Shirts 4 Mike </title> </head> <body> <h1>Shirts 4 Mike</h1> <p>©<?php echo date('Y'); ?> Shirts 4 Mike</p> </body> </html> '''
Rhys Baker
8,200 PointsThat isn't my code.
'''<!DOCTYPE html> '''<html> '''<head> '''<title> Shirts 4 Mike '''</title> '''</head> '''<body> '''<h1>Shirts 4 Mike</h1> '''<p>©<?php echo date('Y'); ?> Shirts 4 Mike</p> '''</body> '''</html>
Rhys Baker
8,200 Points'''html <!DOCTYPE html> <html> <head> <title> Shirts 4 Mike </title> </head> <body> <h1>Shirts 4 Mike</h1> <p>© '''php <?php echo date('Y'); ?> ''' Shirts 4 Mike</p> </body> </html> '''
Glen Burnett
Courses Plus Student 27,349 PointsGlen Burnett
Courses Plus Student 27,349 PointsAh cool I'm glad you got it fixed. Sorry, I passed out due to being dead tired. Its now morning here in Australia. Once you have the server issue sorted you should be right to create any PHP file you like when you move on to learn more on PHP :)