Debiprasad
Debiprasad

Reputation: 6173

500 Internal Server Error when using .htaccess for PHP Settings

When I am using .htaccess for the following PHP settings, I am getting 500 Internal Server Error while accessing the website.

the code in the .htaccess file:

php_flag display_errors off
php_flag log_errors on

The file permission for the .htaccess file is 644

I know that code above is correct. But when it showed me 500 Internal Server Error, I tried different code (most probably wrong) too, but nothing worked. The different code tried are:

php_value display_errors off
php_value log_errors on

and

php_value display_errors 0
php_value log_errors 1

What can be the cause of 500 Internal Server Error?

After learning from the comments on this question, I found that PHP settings on .htaccess does not work with FastCGI. So, to change PHP settings, I need to modify the php.ini or I need to do it in the php code. Is there any alternate way, when I don't have access to modify php.ini file and I don't want to individually modify all the PHP files?

Upvotes: 26

Views: 32853

Answers (3)

Rob Stocki
Rob Stocki

Reputation: 156

I know it has been a while since this question was asked but if your .htaccess doesn't contain errors it could be the comments that are causing your headache.

I recently upgraded WHM and suddenly I was getting 500 Internal Server Errors on some pages. After going through the logs I could see that the .htaccess file was the issue and I solved the problem since they were being caused by the comments.

Here's what cleared the problem up for me.

Previously, I had directives in the .htaccess file that looked like this:

Order Deny,Allow
Deny from 52.87.112.125   # whattheme.com
Deny from 192.163.217.239 # scanwp.net

I started getting the 500 Internal Server Error after the WHM upgrade (likely apache was included in the upgrade).

Suddenly, apache didn't like comments mid line in the directives. I modified the .htaccess file for the code above to look like this:

Order Deny,Allow
#  whattheme.com
Deny from 52.87.112.125

#   scanwp.net
Deny from 192.163.217.239

Problem Solved.

This may not be your issue, but after a hunt, this solution worked for me. Good luck.

Upvotes: 0

Gerard ONeill
Gerard ONeill

Reputation: 4102

As you've discovered, modifying .htaccess only works with an apache module, where it would add to the directives that apache can understand. This wont work with cgi and others.

The php way is to modify the php.ini for the entire site, or modify it on a per directory or per user basis.

For php5.5 (not sure about other versions) modify the .user.ini file in which ever directory you want these settings to apply to. Obviously setting this at the root directory for the site would make it apply to the entire site.

Go here for information on .user.ini: http://php.net/manual/en/configuration.file.per-user.php

Go here to check the list of directives and where they can be changed: http://php.net/manual/en/ini.list.php

Lastly, to check on your file (probably mentioned in the comments), add a phpinfo.php (the name doesn't matter) file containing

<?php phpinfo() ?>

to the directory so you can see what the settings are for php scripts that run in that directory.

Upvotes: 6

Harald Brinkhof
Harald Brinkhof

Reputation: 4455

Like the comments above said: you need to run your php module as Dynamic Shared Object to make it work, as described in the Apache PHP Request Hanlding Documentation

DSO considerations:

libphp provides Apache directives such as php_$value and php_admin_$value. DSO is the only option where these directives will be valid inside .htaccess files or httpd.conf. When these directives are compiled with the concurrent DSO patch, they should be named php4_$value and php5_$value instead.

cgi, fcgi, suphp it will not work.

Upvotes: 7

Related Questions