Alok Bichhwe
Alok Bichhwe

Reputation: 172

How to use PHP7 code in HTML file with the help of .htaccess setting

I am using linux server and in my server I have install PHP 7.* version. I want to use PHP code in HTML file. Right now it render PHP code in in web page. I am using the following code in my .htaccess file but it not working.

AddHandler x-httpd-php .html .htm

and

AddHandler php7-script .php .html .htm

and

<FilesMatch "\.html?$">
SetHandler application/x-httpd-php7
</FilesMatch>

But all are these not working.

Upvotes: 6

Views: 3240

Answers (1)

user4038080
user4038080

Reputation:

After you installed php7.0-cgi

sudo apt install php7.0-cgi

you can add to your .htaccess

AddHandler php70-cgi .php 

tells Apache to run PHP on any file with the extension ".php" using the Module called php70-cgi that is afaik modules/php70-cgi.so

A reason why its not working could be the webserver settings in

/etc/apache2/sites-available/default

if there is AllowOverride „None“ set it to „All“ else you can only make setting in <Directory> and not in .htaccess

<Directory /var/www/>
    ...
    AllowOverride All
    ...
</Directory>

Upvotes: 1

Related Questions