Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

massel's avatar
Level 1

PHP cannot execute .php file but .html file

I am using php 8.2.27 after installing when I execute index.html it works but index.php displays the text in the file , please who can help.

0 likes
10 replies
pc579's avatar

Your Php file begins with

<?php

?

Tray2's avatar

There can be several reasons for this, depending on your setup.

If you are using MacOs or Windows, I recommend Laravel Herd.

If you are using a LAMP or LEMP stacks you should look to make sure you have set it up properly.

massel's avatar
Level 1

@Sinnbeck It display the contents of the file like instead of just Hello world on the browser.

Tray2's avatar

@massel Then you most likely haven't configured it for PHP.

Have you tried running php -S localhost:8000 and then access that url in your browser?

tykus's avatar

@massel did you configure Apache to hand-off requests for PHP files to an appropriate interpreter, e.g. mod_php or PHP-FPM? Apache doesn't itself know how to interpret PHP.

Please or to participate in this conversation.