Hi everyone!

Whenever I develop something on an online web server my htaccess files and php.ini files work as expected. If I place a php.ini into a directory and then call phpinfo(), I can see that it is parsed.

However, when I use a locally installed web server working directory php.ini files are never parsed, and for some reason my htaccess file only affects the directory it is in, not its subdirectories.

I have made sure that AllowOverride is set to All, and indeed if I auto_prepend a file using htaccess it is prepended to all files in the root directory. If I go to a subdirectory however, it is not.

Also, not matter what I try, php.ini is not parsed from current working directories. I suspect this might have something to do with cgi, btu I have no experience in the area.

I am pretty sure this is a setup issue as I don't have this problem on any online servers I've encountered, but I have the same problem with MAMP and XAMPP for max and XAMPP on Windows as well.

Ultimately my goal is to be able to auto_prepend a file in the root directory and have that auto prepend rule work in all subdirectories as well. On the web server I could do this in the master php.ini, but I develop on my local MAMP installation and I need separate php.ini (or htaccess) files for the different projects.

I greatly appreciate your help,

Dani AI

Generated

Short summary and a clear way to debug what’s happening (based on ’s symptoms and ’s suggestion about per‑site php.ini): the behavior you see depends entirely on how PHP is being invoked by Apache and whether the subfolder is actually in the same Apache directory/VHost context. Do these three quick checks first so you know which route to take.

  1. Create a simple phpinfo() page in both the site root and the subdirectory and compare:
  • the "Server API" (shows if PHP is mod_php, CGI/FastCGI or FPM),
  • the "Loaded Configuration File" and "Scan this dir for additional .ini files",
  • the Local/Global values for auto_prepend_file.
  1. If Server API = Apache module (mod_php)
  • per-directory php.ini files are not read — mod_php loads a single master INI at startup. Use php_value / php_flag in .htaccess (or set php_admin_value in a VirtualHost) to set auto_prepend_file. Example:
    php_value auto_prepend_file "/full/path/to/prepend.php"

    (That only works with mod_php; the directive will error under CGI/FastCGI.)

  1. If Server API = CGI/FastCGI or PHP‑FPM
  • per-directory php.ini is typically not used unless the host uses suPHP or similar. Instead use a per-directory user INI (e.g. .user.ini) or put the setting in the FPM pool or per‑vhost configuration. Example .user.ini:
    ; .user.ini in project root
    auto_prepend_file = "/full/path/to/prepend.php"

    Note that user-INI files can be cached for a short time; restarting the PHP service forces immediate reload.

Other checks: ensure the subfolder isn’t actually an Alias or its own VirtualHost/<Directory> block (that would stop inheritance), and verify AllowOverride isn’t overridden for that nested directory. If you want a robust per-project solution, create a VirtualHost for each project and apply per-vhost php settings or an FPM pool — this is what was pointing toward.

<VirtualHost >
[...]
PHPINIDir /var/www/web1
[...]
</VirtualHost>


We can use like above syntax for separate php.ini file

---
Manoj

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.