Search code examples
php.htaccessphp-5.2

PHP 5.2.x php_value auto_prepend_file in htaccess is not working


Have a sub directory in a shared server.
So cannot modify php.ini.
php_value auto_prepend_file "config.php"
Want to include config.php but is not working as if it never been executed.

phpinfo.php is the same folder, and it shows auto_prepend_file no value

I also find this but just come into internal server error.


Solution

  • .htaccess is a configuration file for the Apache HTTP Server and, as such, it can be used to configure PHP as long as it's running as Apache module. You have the php_value directive available, or otherwise you wouldn't be able to use it at all, what means your server has some Apache module running, but your current interpreter is not that one. You can only have one PHP version running as Apache module, but you can have as many versions as you want if running through other server APIs.

    For CGI-based interpreters you can either use a custom php.ini file arranged by your hosting provider, if any (look for such file in your account), or create a .user.ini file (mind the leading dot) in your document root. That is a PHP INI file, it doesn't have anything to do with Apache, so you need to use the syntax as in any other PHP INI file rather than .htaccess syntax:

    auto_prepend_file = "/path/to/config.php"
    

    As you kindly noted, per-directory INI files are a PHP/5.3+ feature. So I think you're essentially out of luck with this path. You need to either use whatever Apache module version your hosting service provides, or contact their support to see if you have a custom php.ini file available for the CGI setup.