Executing a PHP script within an HTML file: What’s the process?

How to run PHP programs ?
How to run PHP programs ?


What is the procedure for executing a basic
PHP code
within an .html file?

Solution 1:

For ‘apache version 2.4.23’, to
execute ‘php
code within ‘html’ or ‘htm’.

Navigate to the directory ‘/etc/apache2/mods-enabled’ and make modifications to the file ‘@mime.conf’.

Navigate to the conclusion of the document and append the subsequent line.

 "AddType application/x-httpd-php .html .htm"

The tag ‘< /ifModules >’ has been confirmed and tested to work with ‘apache 2.4.23’ and ‘php 5.6.17-1’ on the ‘debian’ operating system.

Solution 2:

It is not possible to execute


on an HTML page that concludes with


. However, if the page is PHP and the extension has been modified from




, it is feasible.

What you mean is:


 //This is impossible
index.php //The file extension can be changed using htaccess, ex: its type stays php but will be visible to visitors as index.html

Solution 3:

I appreciate the suggestions, but none of them are effective in this situation. Therefore, I took the following action…
I am currently using the latest version of xampp, which was released in 2014.
Navigate to the following directory:

we will find this bit of code:

        SetHandler application/x-httpd-php
        SetHandler application/x-httpd-php-source
    PHPINIDir "C:/xampp/php"

The emphasis should be on the second line, therefore we need to make a modification.

        SetHandler application/x-httpd-php
        SetHandler application/x-httpd-php-source
    PHPINIDir "C:/xampp/php"

And that is it. Works good!

Solution 4:

It’s not possible to do it, but there are a few potential choices available to you.

1. Execute the PHP page as an external page.

Incorporate your HTML code directly within the PHP page.

To incorporate the PHP code into the HTML page, employ an iframe.

In order to provide more details, if you don’t want to modify your htaccess file, you can consider the following alternative.

Please refer to the following link for information on HTML and PHP: http://php.about.com/od/advancedphp/p/html_php.htm.

Frequently Asked Questions

Posted in Php