Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess php_value auto_prepend_file makes 500 error. How can I fix this?

Tags:

php

.htaccess

My .htaccess is as follows:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /school
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?page=$1
RewriteRule ^([a-zA-Z0-9]+)$ index.php?page=$1

php_value auto_prepend_file ./inc/library.php

ErrorDocument 404 /school/index.php?page=404

As of the ./, I read that indicates a relative path.

like image 516
user2060274 Avatar asked Feb 14 '13 22:02

user2060274


2 Answers

Note: This information was taken nearly verbatim from another website, I thought it explained the issue well and I highly suspect this is the problem:


Using php_flag or php_value in .htaccess files

Some PHP scripts suggest using "php_value" or "php_flag" commands in .htaccess files, as in this example:

php_value  include_path         ".:/usr/local/lib/php" 
php_flag   display_errors       Off
php_value  upload_max_filesize  2M
php_value  auto_prepend_file    "./inc/library.php"

However, some servers run PHP in "CGI mode" (not as an Apache module), so you can't use "php_value" or "php_flag" commands in .htaccess files. If you try to do so, you'll see an "internal server error" message.

You can modify your php.ini file to get the same effect, though. In fact, modifying php.ini is actually more flexible than using php_value or php_flag: there are many things you can't override using .htaccess files, but you can override almost any PHP setting in the php.ini file.

To get the same effect as the .htaccess lines above, you would simply add these lines to your custom php.ini file:

include_path = ".:/usr/local/lib/php" 
display_errors = Off
upload_max_filesize = 2M
auto_prepend_file = "./inc/library.php"

Note: Some systems will require quotes around the paths, and some must not use quotes.

like image 187
Wesley Murch Avatar answered Nov 01 '22 17:11

Wesley Murch


You could use htscanner PHP module if you want to use php_value in your .htaccess files when running php as a CGI/FastCGI application.

like image 40
Edd Avatar answered Nov 01 '22 15:11

Edd