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 Build a Simple PHP Application Getting Started with PHP Your First PHP File

Rhys Baker
Rhys Baker
8,200 Points

My 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
Rhys Baker
8,200 Points

So 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.

Ah 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 :)

When 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.

Hrm.

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.

At 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?

Have you placed php code inside opening and closing php tags?

<?php
echo date(Y);
?>

That was going to be my next question ;)

Rhys Baker
Rhys Baker
8,200 Points

No, 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
Rhys Baker
8,200 Points

Wait, the problem isn't solved yet, the server was running when I started. I should've saved the file in php write?

Yeah sorry Rhys, I deleted my "you're welcome" comment after I read your reply a second time. See below reply

Rhys Baker
Rhys Baker
8,200 Points

You've still been help, thanks for the attempt. My server must be acting strange and not affecting the file or something.

Rhys Baker
Rhys Baker
8,200 Points

I'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
Rhys Baker
8,200 Points

That 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
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> '''