简体   繁体   中英

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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM