0

So I tried to create a PHP code inside an HTML because I've never used it before, but it never showed up. I have a Mac, so I downloaded MAMP and tried to run it from there, but still...nothing.

Where did I go wrong? The WHAT!!! is the only thing that shows up and not the text in the PHP echo.

<html>
<body>

<?php echo "My first PHP script!";?>
WHAT!!!
</body>
</html>    
kakbar231
  • 21
  • 7
  • Do you get your code or is it all blank? – Neobugu Feb 25 '16 at 00:31
  • 1
    When you open the [source view](http://ccm.net/faq/33026-safari-view-the-source-code-of-a-webpage) of your browser, do you see the php code in there? – VolkerK Feb 25 '16 at 00:31
  • 1
    how are you accessing this as? `http://localhost/file.php` or `c:///file.php`? If the latter, then you need to use the former. – Funk Forty Niner Feb 25 '16 at 00:31
  • Hm, sometimes I wish I hadn't been granted single vote closes for the php tag. But the accepted answer over there should cover it ....or else another answer should be added to _that_ question ;-) – VolkerK Feb 25 '16 at 00:37

1 Answers1

0

The most likely cause is that your web server is serving the file as static content, rather than parsing and processing the php. If you view source in your web browser, you'll probably see the <?php ?> tag. Here are some possible causes:

  1. Your filename doesn't end in an extension that the web server is configured to associate with php. eg. using .html instead of .php.

  2. Your apache config isn't loading the php module. In your httpd.conf file, look for a line beginning with LoadModule php5_module (or similar, depending on php version). Is it commented out?

  3. You're loading the file in your browser directly from the hard drive. ie. with the file:// scheme.

Asaph
  • 159,146
  • 25
  • 197
  • 199