Parsing .html as PHP: how to check which method would be right? – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.
But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about php, linux, apache-2.2, .htaccess, lamp.
The usual way of parsing
.html files as PHP is to add either the first (PHP as an Apache module) or both (PHP as CGI) of the following lines to an
AddType application/x-httpd-php .html .htm AddHandler application/x-httpd-php .html .htm
Sometimes that needs to be
x-http-php5, depending on the host:
AddType application/x-httpd-php5 .html .htm AddHandler application/x-httpd-php5 .html .htm
However, I am now on a new host and no permeation of those lines work. In all cases the raw file is being sent to the browser, and
wget shows that
x-httpd-php is being presented as the Content-Type!
HTTP request sent, awaiting response... HTTP/1.1 200 OK Date: Tue, 07 Aug 2012 14:16:40 GMT Server: Apache Last-Modified: Tue, 07 Aug 2012 07:46:44 GMT ETag: "862239-14-4c6a83216c100" Accept-Ranges: bytes Content-Length: 20 X-Powered-By: PleskLin Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Content-Type: application/x-httpd-php Length: 20 [application/x-httpd-php] Remote file exists.
Length: 20 is exactly the length of
<?php phpinfo(); ?>, and that is what it is serving. I have confirmed that PHP is running as a module with the terrific tip in this SO answer. I have spoken with the maintainer of the server (an associate, so even if I switch hosts I would still like to help him resolve the issue) and he does not know what the issue or correct configuration is. The server is running Plesk on a Debian-based distro, if that matters at all.
This was in fact an Apache configuration issue, this page had the solution:
Reproduced here for posterity:
.htaccess files can be enabled by placing the following in the
AccessFileName .htaccess <Directory "/var/www/vhosts"> Options +All AllowOverride All Order allow,deny Allow from all </Directory>
Then restart Apache:
#service httpd stop #service httpd start