Run .html files as PHP in Apache

On Ubuntu, to execute .htm files as PHP, create file

vi /etc/apache2/conf-enabled/php-html.conf

Add following content


    SetHandler application/x-httpd-php

This is similar code from your PHP configuration. In this case, it is from /etc/apache2/mods-available/php5.6.conf

If you want it only for a specific website, edit VirtualHost entry for the website and add


        SetHandler application/x-httpd-php

Example


    ServerName serverok.in
    ServerAlias www.serverok.in
    DocumentRoot /home/www/serverok.in/html
    CustomLog ${APACHE_LOG_DIR}/serverok.in.log combined
    
        Options All
        AllowOverride All
        Require all granted
        Order allow,deny
        allow from all
    
    
            SetHandler application/x-httpd-php
    

Now restart apache

service apache2 restart

Apache | PHP

Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *