Moving my website to a new webhost, I'm having an issue with apache / server conf files. PHP files aren't interpreted by the browser but only downloaded. I'm quite a beginner in that domain.
MySQL: 5.0.84
PHP Version 5.2.17
Apache 20051115
in .htaccess file, I wrote
AddType application/x-httpd-php5 .php
to make sure every php file is read by php5.
Running a php info in the backend ( frontend doesnt interpret php ... ) shows well, if you need infos from it.
I really need some help, ty
php is interpreted server side. so it's a server problem.
check your .htaccess to make sure it's picking up php.
might need to add a line to it:
AddType application/x-httpd-php .php .php3 .phtml .htm .html
Related
I am moving from a server with PHP 5 to a new server with PHP 7, and I am having issues to tell Apache to parse .html as PHP scripts.
In my .htaccess file I have this line working correctly on my current server with PHP 5:
AddType application/x-httpd-php .html
But on the new server, that directive makes any .html file being downloaded instead than executed as a PHP script.
I know that on the current server with PHP 5 installed, PHP is configured with API set as "Apache 2.0 Handler" whereas on this new server it is configured as "FPM/FastCGI" and I guess that maybe that's the problem? If so, how can I overcome it without having to change that API setting?
I look forward to hearing from you. Thank you in advance for any help!
After hours of research, I ended up reading this page:
https://www.digitalocean.com/community/questions/php-fpm-security-limit_extension-issue
And I fixed the problem by adding this code inside .htaccess:
<FilesMatch ".+\.html$">
SetHandler "proxy:unix:/run/php/php7.0-fpm-[myhostname].sock|fcgi://localhost"
</FilesMatch>
And to avoid the server to give me an 'access denied' error I had to put this line inside /etc/php/7.0/fpm/php-fpm.conf:
security.limit_extensions = .php .htm .html .inc .rss .rdf .xhtml
Then restarted PHP daemon with:
service php7.0-fpm restart
Now everything seems to work fine! Quite complex I'd say, and I think that'd due to the fact PHP is configured with the FPM/FastCGI API.
Comments and thoughts are welcome!
Thanks again to everyone.
I am designing a website that requires me to show the outputs of a mysql database on a webpage written in html. However my browser doesn't seem to recognize the php scripts within the html file and returns blank values where their should be details. The scripts worked fine in the .php files but have no effect when included in the .html files even after creating a .htaccess file as instructed in previously asked questions. Is there anything else that can be done to solve this issue?
There are two methods (that I've encountered) of changing the environment on an Apache server via .htaccess to allow PHP scripts to be processed in .html files, depending on the configuation. Whichever of these you've attempted, try the other.
AddHandler application/x-httpd-php5 .php .html .htm
Or
AddHandler cgi-script .html
SetEnv PHP_EXTENSION .html
Just wanted to know what code I have to put in my .htaccess file so my html pages read php that im going to put in there, (just a contact form), I did find it once but can't remember, sorry and thanks.
You have to convert your html files to php
put this line in your .htaccess if you're using apache2
AddType application/x-httpd-php .html .htm
but make sure that your .htaccess file is in the root directory of the website
If you want PHP in HTML files to be interpreted just add this line to your .htaccess file:
AddType application/x-httpd-php .html .htm
HTML Pages don't read your PHP. Instead Apache is reading your file and executes it with a PHP interpreter if some PHP is in there.
Just in case you have a debian server with apache2 you can apt-get install php5. But there is a lot more work to do, for example FCGI and so on.
I've read everything here and tried almost all the suggestions, nothing is helping.
I've got several static .htm pages that all call common headers & footers via a php include:
<?php include('inc_logo_nav.htm');?>
So I just moved to a new server with all kinds of higher level security and nothing we have tried helps.. the system refuses to allow these include calls unless I change the file extension to .php
On the old server I was using in my .htaccess:
AddType application/x-httpd-php .html
AddType application/x-httpd-php .htm
But on this new box I had to comment out those lines to get the pages to even come up. The tech guy is stumped too..
back to suphp & seuexec but no nginx
and that didnt help either...
cPanel Server running: CENTOS 6.5 x86_64 vmware – WHM 11.40.
I'm already suffering from loss of traffic, changing all the pages to .php after 20+ years is going to kill the site... Can anyone help here??
Thanks
Have you tried these in your .htaccess?
AddHandler x-mapp-php5 .html .htm
AddHandler x-mapp-php6 .html .htm
I needed them on a server hosted by 1&1 to cause HTML files to be parsed as PHP.
index.htm I have 6 lines of PHP code that wont run on my page I don't get an error of any kind it just wont run if you look in source it shows my raw PHP. I have a file named test.php that works fine. in test.php I only have those 6 lines of code that you can see in my index.htm
Server Name defiro
cPanel Version 11.36.2 (build 9)
Theme x3
Apache version 2.2.24
PHP version 5.2.17
MySQL version 5.5.30-30.2
Architecture x86_64
Operating system linux
i have tryed to fix the problem by putting AddType application/x-httpd-php .html in my websites .htaccess file as listed in PHP not working on HTML file i have tryed a few other things by trying to get an error out of the php with no luck
Edit__
it wont let me use php or html in a file together no matter if it is .html or .php it wont work i don't know how to fix it?
Let me see
index.htm I have 6 lines of PHP code that wont run on my page I don't get an error of any kind it just wont run if you look in source it shows my raw PHP. I have a file named test.php that works fine. in test.php I only have those 6 lines of code that you can see in my index.htm
Let me make some assumptions
index.htm has php tags inside (<?php echo 'if this works'; ?>) that do not parse when you make your request. The tags don't even show up in your browser.
test.php is a file that starts and ends with php tags (<?php /*php content*/ ?>). It runs as expected. (mind you, you can add content before or after php tags and it will be displayed raw).
If these assumptions are not correct please say so in a comment
Some other assumptions
you set up your own server or you haven't fiddled with the configuration yet
my suggestion
Go to your httpd.conf apache configuration file
Look for something that resembles the following
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
The one that's talking about php is the line you're interested in, it determines which file extensions will be parsed by the php interpreter before being sent to the client. OK, change it to look like this
AddType application/x-httpd-php .php .html .htm
You can add as many space-separated extensions you want, but be warned, sometimes you want a raw file, so be carefull
SAVE and RESTART the server. Important, everytime you change the conf
Please give feedback if this does not help you
you have put the following in
AddType application/x-httpd-php .html
That targets .html files, You need to target .htm files so changing to
AddType application/x-httpd-php .htm
should fix it