0

Just today i'm going to learn php and first of all i'm installed apache2 server and mysql then php-7 . then within " var/www/test.php " directory my php code is working fine . But when i try to create a index.html file in my Desktop then my php code is not working . here is my index.html file

   <!DOCTYPE html>
   <html>
   <head>
       <title>learnPhp</title>
   </head>
   <body>
        <h1>my first php code</h1>
       <?php
         echo "Hello World!";
       ?>
   </body>
   </html>

for solve this i'm try to all the method that given this two post:
1 . PHP codes doesn't work inside HTML codes
2. PHP inside HTML doesn't work

when i'm try to Rename the file index.phn and open it then :
enter image description here

Rafsan
  • 131
  • 1
  • 9

1 Answers1

-1

You must use a .php extension.

PHP files works only in .php files and in directory of the server.

Rename file to index.php and copy it to var/www/anything/

After that, go to http://localhost/anything/

EDIT: I was wrong. You can run php in html file, but you must have a file in a directory from a server. For example /www/... and go to http://localhost/...