0

I tried 3 things :

  • a simple html file : ok
  • a simple php file : ok
  • a html file with some php code inside : not ok

My configuration is

  • Ubuntu :
ubuntu@ubuntu:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 21.10
Release:    21.10
Codename:   impish
  • NGINX :
ubuntu@ubuntu:~$ nginx -v
nginx version: nginx/1.18.0 (Ubuntu)
  • PHP :
ubuntu@ubuntu:~$ php -v
PHP 8.0.8 (cli) (built: Oct 26 2021 11:42:42) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.8, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.8, Copyright (c), by Zend Technologies

Here is the html with the php code :

<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>

<body>

<?php
echo "My first PHP script!";
?> 
    
Hello world
    
</body>
</html>

i loaded the file on firefox browser from local ip (192.168.x.y) and also from public ip and i got the same results. i really dont know where to start, i dont find any clue on the net.

  • out of curiosity, what is the extension of your mixed HTML/PHP file? – meewog Feb 20 '22 at 18:12
  • The duplicate covers a lot of cases, the rest should be covered by: https://askubuntu.com/questions/134666/what-is-the-easiest-way-to-enable-php-on-nginx – Quentin Feb 20 '22 at 18:13
  • What exactly is your nginx configuration? – Jaquarh Feb 20 '22 at 18:16
  • If it's called "something.html", then no PHP code will be processed. Call it "something.php" and it will. – droopsnoot Feb 20 '22 at 18:19
  • the html file containing php code has the `.html` extension. i rename to `.php` and load it. it works. but i dont understand why. does NGINX have anything to do with it ? – Fanny Mae Feb 20 '22 at 18:22
  • PHP is normally not executed on .html pages. Use .htaccess to get php working while the page appears as .html in the browser address line. – Sputnik Feb 20 '22 at 18:29
  • i'm not using `Apache webserver` so `.htaccess` is not available. `NGINX` is the webserver. renaming `.html` to `.php` worked but it is weird for me. – Fanny Mae Feb 20 '22 at 18:37

0 Answers0