Configuring OpenLiteSpeed web server to support PHP includes on static .html pages


Instructions for setting up MIME types in OpenLiteSpeed (OLS)

Searching the internet for the query ‘how to enable PHP processing in HTML’ leads to enabling PHP parsing in OpenLiteSpeed Server and configuring the .htaccess file settings such as:

AddType application/x-httpd-php .html .htm

or

AddType application/x-httpd-php .php .htm .html .tpl

or AddHandler

AddHandler application/x-httpd-php .htm .html .php .phtml

or

<IfModule mod_mime.c>
AddType application/x-httpd-php .php
AddType application/x-httpd-php .htm
AddType application/x-httpd-php .html
AddType application/x-httpd-php .tpl
</IfModule>

Or using SetHandler

<FilesMatch "\.(php|htm|html|tpl)$">
SetHandler application/x-httpd-php
</FilesMatch>

In my case, none of the above helped, so I had to find the solution in the OLS settings myself: On the left side of the admin panel, select

Server Configuration > General, In the General Settings section, click on conf/mime.properties in the MIME Settings line:

В левой части административной панели выбираем Server Configuration > General, в секции General Settings жмём в строке MIME Settings на conf/mime.properties

In the General > MIME Type Definition tab, click the plus (Add):

Во вкладке General > MIME Type Definition жмём на плюс (Add)

Fill in the fields in the MIME Type Entry tab with your data (Suffixes * — html, MIME Type * — application/x-httpd-php):

Заполняем строки во вкладке MIME Type Entry своими данными (Suffixes * — html, MIME Type * — application/x-httpd-php)

Save the changes (Save) and restart the OLS server using the Graceful Restart button:

Сохраняем изменения (Save) и перегружаем сервер OLS кнопкой Graceful Restart

That’s all! MIME Type configuration to support PHP functions like include(), require() is now set up for static .html pages, and similarly for other extensions (.htm, .tpl, and others).

*MIME Type — Multipurpose Internet Mail Extensions is an IT standard that documents the format of a file or byte stream. It is standardized in RFC 6838. It consists of a type and a subtype, two strings separated by a slash (/), without spaces. All types are divided into two categories: discrete and multipart. Discrete types represent single files, while multipart types represent documents made up of several parts.