I want to set up php on my machine but I can't make it work. This is what I did:

  1. I downloaded php with sudo apt-get php
  2. Installed Apache sudo apt install apache2
  3. Resterted server sudo service apache2 restart
  4. Both http://localhost/ and php -v work as the should

But when I try to run a basic php file it doesn't work. For example in /var/www/html I have following test.html file:

<meta charset="UTF-8">
<body bgcolor="white">

echo '<p> HEY </p>';


But when I type in my browser http://localhost/test.html I get some garbage:

'; ?>

What am I doing wrong?


By default, apache will not run files with the extension html through PHP. Try renaming your file to test.php and call http://localhost/test.php

  • To run html files through PHP, adapt the mime settings
  • To make index.php the default directory index adapt the index settings
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.