Author Topic: PHP Processing in .htm & .html files  (Read 2621 times)

0 Members and 1 Guest are viewing this topic.

Offline
*
PHP Processing in .htm & .html files
« on: March 28, 2023, 08:54:57 PM »
Hi,

I am trying to enable PHP processing in .htm & .html pages for a legacy website.

On our cPanel server we simply use addHandler in the .htaccess file. But with CWP we are getting errors that it can't be found.

htaccess:
AddHandler application/x-httpd-php81 .php

Error Log:
Caused by SystemException in API_Linux.cpp:444: execve() for program "/opt/alt/php81/usr/bin/php-cgi" failed: No such file or directory

Any guidance much appreciated.

Offline
*****
Re: PHP Processing in .htm & .html files
« Reply #1 on: March 28, 2023, 09:56:08 PM »
Are you running php-fpm? Or PHP via CGI?

Offline
*
Re: PHP Processing in .htm & .html files
« Reply #2 on: March 29, 2023, 05:43:46 AM »
I was using cgi but when that failed I switched to php-fpm to see if that resolved it but it still doesn't work.

We are happy to use CGI or FPM as it's only a development server. Whatever gets it to work.

Offline
*****
Re: PHP Processing in .htm & .html files
« Reply #3 on: March 29, 2023, 07:43:55 AM »
I am using php-fpm for performance reasons and to give each account its own possible choice of PHP version. In your use case, it probably doesn't matter. Except I could guide you better if you switch back to php-fpm, since that is what I use :D

It doesn't sound as if PHP 8.1 is installed properly under the CGI PHP. Can you confirm that it is present and built successfully? Does it have an ini file? Otherwise, php-fpm for 8.1 should be:
/opt/alt/php-fpm81/usr/bin/php
and in fact, I also have:
/opt/alt/php-fpm81/usr/bin/php-cgi

Offline
*
Re: PHP Processing in .htm & .html files
« Reply #4 on: March 29, 2023, 10:45:43 AM »
Thanks for the assistance.

Its now working. I don't think I changed anything accept re-compiling PHP 8.1 from the control panel.

However, I have noted that phpinfo() call from a php vs htm files shows different server API being used.

.htm returns Server API: CGI/FastCGI
.php returns Server API: FPM/FastCGI

I am using this handler in the .htaccess

AddHandler application/x-httpd-php81 .htm .html

Should I be using something else so they are both using FPM?

Offline
**
Re: PHP Processing in .htm & .html files
« Reply #5 on: May 12, 2023, 09:22:28 PM »
I am not 100% sure but I guess:

When you put:

Code: [Select]
AddHandler application/x-httpd-php81 .htm .html
into .htaccess your .htm, .html files are handled by suPHP. That is why you see
Code: [Select]
Server API: CGI/FastCGI
To solve this you need to customize the Apache template file (you wrote about .htaccess that is why I am sure you use Apache :) ).

The Apache php-fpm template files are located in the folder:
/usr/local/cwpsrv/htdocs/resources/conf/web_servers/vhosts/httpd/php-fpm/
Probably you need to change the lines:

Code: [Select]
        <IfModule proxy_fcgi_module>
                <FilesMatch \.php$>
                        SetHandler "proxy:%backend_fcgi%|fcgi://localhost"
                </FilesMatch>
        </IfModule>

inside the template files to something like:

Code: [Select]
        <IfModule proxy_fcgi_module>
                <FilesMatch \.php$|\.htm$|\.html$>
                        SetHandler "proxy:%backend_fcgi%|fcgi://localhost"
                </FilesMatch>
        </IfModule>

then rebuild virtual hosts and restart Apache.

Sorry, I use a free version of CWP on my test box, so I don't use php-fpm there and can't be sure it is 100% working solution (make backups before you modify something :) ).