Apache2 configuration for embedded PHP in HTML files
If you want to use PHP scripts on your web server it is a simple thing to add a script inside a page and save it as a .php file extension.
Listing of phpinside.php
<?php
Listing of phpinside.php
<?php
echo "Hello PHP World!"
?>
When this file is browsed if looks like this:
Hello PHP World!
With the default installation of Apache2 and PHP, however, Apache2 does not know to render an html file as a PHP script. If you name the above file phpinside.html, you will instead see elements of the PHP code when you view the file in a browser.
There are thousands of (old) posts for Apache configuration of PHP by editing the httpd.conf file to include HTML as an application/x-http-php type. However, few make note that Apache2 has a new config file structure for Debian (Ubuntu). Refer to the page that I found for a better explanation: Control Escape - Configuring Apache2 on Debian, Ubuntu
Now the "AddType application/x-http-php" directive is in the php5.conf file in the "etc/apache2/mods-enabled" directory.
Edit the file:
sudo gedit /etc/apache2/mods-enabled/php5.conf
Edit the line to include html and htm:
When this file is browsed if looks like this:
Hello PHP World!
With the default installation of Apache2 and PHP, however, Apache2 does not know to render an html file as a PHP script. If you name the above file phpinside.html, you will instead see elements of the PHP code when you view the file in a browser.
There are thousands of (old) posts for Apache configuration of PHP by editing the httpd.conf file to include HTML as an application/x-http-php type. However, few make note that Apache2 has a new config file structure for Debian (Ubuntu). Refer to the page that I found for a better explanation: Control Escape - Configuring Apache2 on Debian, Ubuntu
Now the "AddType application/x-http-php" directive is in the php5.conf file in the "etc/apache2/mods-enabled" directory.
Edit the file:
sudo gedit /etc/apache2/mods-enabled/php5.conf
Edit the line to include html and htm:
AddType application/x-httpd-php .php .phtml .php3 .html .htm
AddType application/x-httpd-php-source .phps
After you have saved the file you then have to restart Apache2.
sudo /etc/apache2/apache restart
AddType application/x-httpd-php-source .phps
After you have saved the file you then have to restart Apache2.
sudo /etc/apache2/apache restart
Comments