0

I haven't worked in a very long time with php so this question may be a very noob one.

I've installed apache server 2.0.65, and although when i call the localhost, my page in htdocs gets executed, only the html code appears in the view. The php code appears in the source view as html would, thus leading me to believe that it doesn't get interpreted.

My code is the from w3school:

<!DOCTYPE html>
 <html>
 <body>

<?php
 echo "My first PHP script!";
 ?>

 </body>
 </html> 

what am i not doing ok?

3
  • 1
    Make sure the file extension is php. Other than that the second question would be have you installed PHP? Commented Dec 23, 2013 at 9:42
  • What's the filename of the file which this code contains? Commented Dec 23, 2013 at 9:43
  • Use PHP The Right Way, not w3schools. Commented Dec 23, 2013 at 9:46

3 Answers 3

3
  • You did not install PHP
  • You did not configure PHP to run your file (by default it will process files with a .php extensions)
  • You aren't actually visiting http://localhost/foo.php in your browser
Sign up to request clarification or add additional context in comments.

Comments

2

Apache would just run HTML, CSS. In order to make PHP work, you must install PHP, and set environment variable on your local machine, so that all files with .php extension would be run by PHP.

Comments

1

Filename must have a .php file extension.

PHP must be installed and running - if you can open a terminal and type php -v or use top to see if php is running.

If you are running on your local computer try installing WAMP or something similar.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.