Home  >  Q&A  >  body text

Set up Apache2 to handle .html files the way php 8.0 does

I have set up php/apache according to this linode guide: https://www.linode.com/docs/guides/install-php-8-for-apache-and-nginx-on-ubuntu/

This seems to work, I have an apache server that serves files and handles .php files.

However, I'm taking the time to figure out how to tell apache to use .php to handle .html files. Anything I do with .htaccess (a-la- https://manage.accuwebhosting.com/knowledgebase/2492/Parse-HTML-As-PHP-Using-HTACCESS-File.html etc.) Modifications will not produce any changes. I also set AllowOverride All to /etc/apache2/apache2.conf in the /var/www/ directory. Additionally, most online information on the subject points to earlier versions of .php, with no specific mention of 8.0.

What can let apache use 8.0 to process .html?

P粉670838735P粉670838735300 days ago446

reply all(1)I'll reply

  • P粉373990857

    P粉3739908572024-01-17 09:55:22

    You need this module, confirm you have this line in httpd.conf, or add it to it:

    LoadModule mime_module modules/mod_mime.so

    Also check if the modules/mod_mime.so file exists on your system.

    Then find or add the module section in httpd.conf:

    
        # following line will change mime type of .html file to php
        # and they will be handled as such
        AddType application/x-httpd-php .html
    

    Directive AllowOverride All will enable .htaccess files, but you also need to enable mime_module.

    Of course, restart the apache server after changing the configuration.

    Module documentation: here

    reply
    0
  • Cancelreply