PHP 7.4.6 won't execute on HTML pages

I am new to Virtualmin and yesterday installed Virtualmin on a fresh CentOS Linux release 8.1.1911 (Core) server. I migrated my cPanel website as a virtual server and the process was effortless and I had no problems.

I am now having an issue not being able to execute PHP code on webpages with a .html extension. Here is my PHP configuration. This can also be accessed without going through Cloudflare, just prefix “wh01.” to the domain.

Here is an example HTML page with PHP code.

I’m also having an issue accessing PHP pages with no extension. You will see if you omit the extension from the PHP configuration page above, a 404 Not Found error is generated, but HTML pages work fine.

Here is the .htaccess code that worked for this from my cPanel website, bearing in mind I understand this will work going through Cloudflare only:

# To internally forward /dir/foo to /dir/foo.html
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [L]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]

Please let me know what other information you may need to help solve these issues. I hope you can help me get things working properly.

Thank you.

Mark Wasley.

@MarkWasley hi, well if you want to run that php code on page you need to run page as .php file… not as .html

to make things simple and clear for you, php is basically logic code which can include html code inside…this means if you have any web page.html and you just rename that page to page.php it will load and run in browser just fine. Now in page.php insert your php code in bits of html code you need to run and thats it. If you want or need run php via html then you need to call that php code in your html code…which means something like this would not work in html file…


$webRoot = "/home/mwasley/public_html";

$pageTitle = "Hitting the Highway";
$insertHeaderPlugins = "hittingthehighway.php"; // links to the Resources directory within pageTheme.

include "$webRoot/res/system.php";

$titleFormat = "$pageTitle | $siteName";

include $siteHeader;

<div id="mainContent">
		<h1><? insertIcon('tranzcar',0); ?> Hitting the Highway</h1>
			<p><b>The best tracks to sing-along to on a long drive or journey. Wind down the windows, let the wind blow through and crank up the volume.</b></p>

try to rename that hml page (code is from your non working page btw) into something.php and it should work…

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.