1

I have a problem with php_value auto_prepend_file from htaccess. It gives me 500 Internal Server Error. The following htaccess codes is working fine on localhost but gives me 500 Internal Server Error on online server. Where is the problem and what is the solution ? Anyone can help me in this regard please ?

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /script/

RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ %1 [R=302,NE,L]

RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*)index\.php$ $1 [L,R=302,NC,NE]

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^post/([\w-]+)/?$ sources/post.php?msgID=$1 [L,QSA] 

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteRule ^(.+?)/?$ index.php?pages=$1 [L,QSA]

php_value auto_prepend_file "/home/*****/public_html/script/path.php"
AlwaysStudent
  • 1,354
  • 18
  • 49
  • @anubhava Dear there is not have any error about 500 error there is just this error: `File does not exist: /home/*****/public_html/404.shtml` – AlwaysStudent Jul 01 '18 at 08:34
  • Check answer below first. Your htaccess is not using Directory directive I believe. – anubhava Jul 01 '18 at 08:41
  • @anubhava The error is this: `/home/******/public_html/script/.htaccess: Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration` – AlwaysStudent Jul 01 '18 at 08:49
  • @anubhava The tobias-k answer means your bounty answer is not working everywhere . I have used your answer on my localhost. – AlwaysStudent Jul 01 '18 at 08:57

1 Answers1

1

For the php_value directive to work it needs to be an environment where PHP is loaded as a module into the Apache webserver.

This is not necessarily the case. Your online server could for example forward PHP requests to a FPM-worker via FCGI, without mod_php enabled in Apache.

You may place a file with just a phpinfo() in it on the server to check if that is the case. For me, it then displays Server API FPM/FastCGI in the 3rd row.

In this case, overwriting php.ini settings via .htaccess is not possible. Your only options would be to change the FPM/Pool config (given you have access to that) or try ini_set.

Edit: It may also be possible to utilize .user.ini files as an alternative: https://medium.com/@jacksonpauls/moving-from-mod-php-to-php-fpm-914125a7f336 / https://secure.php.net/manual/en/configuration.file.per-user.php - thanks @anubhava

Tobias K.
  • 2,997
  • 2
  • 12
  • 29
  • I don't understood this part `Your only options would be to change the FPM/Pool config (given you have access to that) or try ini_set.` can you explain for me please ? – AlwaysStudent Jul 01 '18 at 09:04
  • It meant to point out that it **is** possible to set non-global `php.ini` settings also in PHP-FPM, but not as easily as with `mod_php` in Apache, where even a non-privileged user can do it just using a `.htaccess` file. You would need to create a custom worker-pool (that then gets a unix-socket to connect to) and could use `php_admin_value` there to change configuration per-pool. And of course it is always possible to use `ini_set` in your PHP-code, but I realize for your `auto_prepend_file` directive this may be too late. – Tobias K. Jul 01 '18 at 09:12
  • So that means i can not use it without your answer. So if you have a time can you check my bounthy question ? (HERE)[https://stackoverflow.com/questions/47801948/how-can-we-include-php-files-without-specifying-the-subfolder-path] i am using `php_value auto_prepend_file` because of the anubhavas' answer. His answer is working fine on every localhost. But not working online server – AlwaysStudent Jul 01 '18 at 09:17
  • also the error-log says this: `/home/******/public_html/script/.htaccess: Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration` – AlwaysStudent Jul 01 '18 at 09:17
  • This is exactly the error you'd get in the situation I assume (`mod_php` not enabled): _defined by a module not included in the server configuration_ Did you check `phpinfo()`? What is the _Server API_? – Tobias K. Jul 01 '18 at 09:22
  • can you answer my other question if you have a solution please ? https://stackoverflow.com/questions/47801948/how-can-we-include-php-files-without-specifying-the-subfolder-path – AlwaysStudent Jul 01 '18 at 09:26
  • yes i have checked the phpinfo() and the server API is CGI/FastCGI – AlwaysStudent Jul 01 '18 at 09:34
  • I added a possible solution/answer to your thread: https://stackoverflow.com/a/51122227/7362396 - I based it on the currently accepted answer and tried to solve that with pure PHP (without Apache/`php_value`). I admit that I didn't fully understand the question you formulated there, so I hope the answer fits. – Tobias K. Jul 01 '18 at 09:53
  • https://stackoverflow.com/a/50632691/7362396 was updated and suggests the use of an `.user.ini` file. I did not know about this until now, and it may make my earlier statement _overwriting php.ini settings via .htaccess is not possible_ false. This may be a working solution to your problem. However I still encourage you to look into a solution that does not require `php.ini` overrides, I think this would make your code more stable. – Tobias K. Jul 01 '18 at 09:59