Simple PHP echo code not working

In my case (which is a very specific case) installing this missing package (Ubuntu 14.04) did the trick:

sudo apt-get install libapache2-mod-php5

for users working with php7 install the package:

sudo apt-get install libapache2-mod-php7.0

After that, just restart apache:

sudo service apache2 restart

And there you go.


Make sure that you are using <?php and not <? shorthand since that may be disabled on your server. This will cause the output of "; ?> as it happened to me a few months ago in a transition to PHP5.

I've only seen the odd output like this when the PHP parser isn't detecting it as PHP. Make sure to check that PHP is functioning as expected and that the <?php tag is being recognized.


Any of these (or more) could be your answer why it is not working

  1. Is there actually PHP running on your computer?
  2. Is the file extension .php?
  3. Are you accesing the file through your browser doing something like http://localhost/myfile.php
  4. If it is on a remote server, is there PHP installed?

I had the same problem when I figured out my mistake:

Instead of correct http://localhost/test.php I just double clicked on the file file:///C:/Users/.../htdocs/test.php.

Tags:

Php

Echo