Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

500 Internal Server Error when using .htaccess for PHP Settings

Tags:

php

.htaccess

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?

like image 494
Debiprasad Avatar asked Jun 07 '12 08:06

Debiprasad


2 Answers

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.

like image 169
Harald Brinkhof Avatar answered Nov 11 '22 08:11

Harald Brinkhof


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.

like image 21
Gerard ONeill Avatar answered Nov 11 '22 06:11

Gerard ONeill