I've got WordPress installed on an add-on domain (shared hosting environment), with a theme that uses ini_get('allow_url_fopen') to determine how to reference post images. ini_get('allow_url_fopen') is returning a value different than what is in my custom php.ini file, which is located in the WP installation directory.
If I run phpinfo() from a test file in the WP directory, I see that PHP is has these settings:
Configuration File (php.ini) Path /usr/lib
Loaded Configuration File /home/ACCOUNT/public_html/ADD-ON DIRECTORY/php.ini
If, however, I run phpinfo() from /home/ACCOUNT/public_html/ADD-ON DIRECTORY/wp-content, a different configuration file is used:
Configuration File (php.ini) Path /usr/lib
Loaded Configuration File /usr/local/lib/php.ini
Why is the wrong configuration file being loaded?
Okay, my host is using suPHP. And with suPHP (and, I presume, phpSuExec), subdirectories do not inherit the configuration from php.ini files. (They will use the default php.ini.)
http://www.geeksengine.com/article/php-include-path.html
Two ways around this:
Place a custom php.ini file in each directory where scripts are loaded from
Use a suPHP_ConfigPath /home/username/public_html/ directive in .htaccess to point to the directory containing your custom php.ini and have it affect all subdirectories that don't already contain a php.ini
This is a problem related to your hosting company, not to php in particular. If you are using a specific system that you build yourself, you'll need to look at which apache extension is used to run php files.
For example, on my system i built for work, i use SUPHP as a script engine. This allows me to configure where to look for a specific PHP.ini file.
Good luck
Related
The php.ini file in xampp is located here: C:\Windows for php.ini
The phpinfo contains this information:
Configuration File (php.ini) Path C:\WINDOWS
Loaded Configuration File (none)
Scan this dir for additional .ini files (none)
How can i change the directory?
open this file
"\xampp\apache\conf\extra\httpd-xampp.conf"
find this block
PHPINIDir "C:/xampp/php"
change the directory
From my experience using XAMPP, it's better to put the php.ini file where XAMPP expects it to be by default. Typically XAMPP is going to look under its own dir. For Windows, it would look like, or similar to, this: [yourdrive_letter]:\xampp\php\php.ini . That's what should be showing up in your Loaded Configuration File setting. I always ignore whatever it says in Configuration File (php.ini) Path, because that's not really the ini that xampp is using.
Go look under your xampp directory and find the "php" folder. If it's not there, then it needs to be (unless you've somehow configured xampp to look elsewhere). So find the PHP folder you want to use and put it under the xampp folder. The version of xampp I have does not allow for switching php versions/folders "on the fly", so the folder MUST BE named "php". (Yeah, I've tried having two php folders with different names and just swapping them out -- that doesn't work well in xampp).
I don't see where I was telling you to edit anything under the Windows directory. If you can't copy the php.ini for some reason, then you can use the template for it provided by XAMPP and change it to your needs. You asked how to change the directory for your php.ini and your subject was about XAMPP so I assumed you have an XAMPP directory somewhere and knew how to configure it -- my bad. Most installation directions I've seen for XAMPP tell you to put it in C:\xampp. If you have it under a Windows directory, then you have my sympathy. If you DO have a C:\XAMPP, I'm simply saying to find a directory called PHP under THAT folder, and then configure your XAMPP to use the php.ini under C:\xampp\php. Under your 'config' option for Apache, you should see a file option called 'httpd-xampp.conf'. Select that to edit it; there should be a module called <IfModule php5_module> in there. Under that is your PHPINIDir directive. Change whatever path it's pointing at to "C:/xampp/php". Add the closing tag (</IfModule>). Restart Apache. (You may have to stop Apache before editing this file). If your XAMPP is in your Documents directory for some reason, then it's just a matter of changing the paths in this answer. I wouldn't put it there personally, but it seems your network people have you kind of locked down. Sorry if my previous answer was unhelpful.
How do you specify the path to the php.ini file in PhpStorm?
I am trying to build run configurations for Built-in Web Server and PHPUnit, but I cannot figure out how to specify the path of the php.ini file.
The only resource that I can find is this, but it does not appear to work for current versions of PhpStorm.
I have set the interpreter options to --php-ini C:\PHP\php-5.6.7\php.ini. This is the correct path to the file. However, when I get the phpinfo(), it reports:
Configuration File (php.ini) Path C:\Windows
Loaded Configuration File (none)
Scan this dir for additional .ini files (none)
Additional .ini files parsed (none)
(This is related to another question that I asked, but it is specific enough, I think, that a new thread is warranted.)
Working just fine using -c for specifying path to custom php.ini
P.S.
Ignore the small path difference -- it's because E:\Projects\php\ is a symlink to E:\Projects\php56\ and I did not bother to use "real" path.
P.P.S.
Works for both local "PHPUnit" and "PHP Script" types of Run/Debug configurations.
I believe that currently it's not possible to provide path to custom php.ini for built-in web server as it uses your default local PHP Interpreter and that has no options for providing custom parameters (except those passed via -d option)
My development environment is shared with other developers of my startup and is setup on Rackspace. The php.ini file is located in /etc/ folder, and I believe this is a centralized location from where every other developer's dev environment setting is being configured from. I want to customize this php.ini file specifically for myself rather than having to do it in the /etc/ location.
Specifically I am setting up XDEBUG in my environment, some other developers don't want it, so I don't want to bug em :)
To do so, I scanned the Internet on how to override the php.ini file specifically for a directory, and found this page on stackoverflow
And following that, I simply copy pasted the php.ini file within my htdocs folder and then simply echoed out phpinfo() (I echoed this in one of my Controllers, (using Zend)). The index.php file is within the htdocs folder.
When I look # "Loaded Configuration File", it still reads
/etc/ instead of ../htdocs/
Anybody know what's up?
In general, it isn't possible to load php.ini on a per directory basis, but in some special cases (CGI/FastCGI), it is: see documentation for Per-user configuration
Since PHP 5.3.0, PHP includes support for .htaccess-style INI files on a per-directory basis. These files are processed only by the CGI/FastCGI SAPI. This functionality obsoletes the PECL htscanner extension. If you are using Apache, use .htaccess files for the same effect.
In addition to the main php.ini file, PHP scans for INI files in each directory, starting with the directory of the requested PHP file, and working its way up to the current document root (as set in $_SERVER['DOCUMENT_ROOT']). In case the PHP file is outside the document root, only its directory is scanned.
If you are hosting several independent sites on one server, you should consider FastCGI anyway, to keep them separated. With php5-fpm it's very easy to setup many pools of workers.
Note that only set a limited subset of the ini-options in the user-ini-file.
As you said you don't have control on the server, the possible work-arounds would be to:
Use ini_set() to override the changes inside your script. Not all of the configuration directives can be changed using ini_set() though.
Use an .htaccess file in your directory to override the configurations in php.ini file.
(certain parts adapted from #1438393)
Hope this helps!
I'm not sure you understood the post. The post means if you run the server and want a per domain php.ini you can run the module as a per domain so each user controls there domain php.ini however it looks like your server does not offer this so you will need to us htaccess file to overwrite the php.ini settings.
By over write this doesn't mean you can change the directory this means maybe add a module or add error reporting ect...
You can do it by using this post: How can I use xdebug to debug only one virtual host?
My development environment is shared with other developers of my startup and is setup on Rackspace. The php.ini file is located in /etc/ folder, and I believe this is a centralized location from where every other developer's dev environment setting is being configured from. I want to customize this php.ini file specifically for myself rather than having to do it in the /etc/ location.
Specifically I am setting up XDEBUG in my environment, some other developers don't want it, so I don't want to bug em :)
To do so, I scanned the Internet on how to override the php.ini file specifically for a directory, and found this page on stackoverflow
And following that, I simply copy pasted the php.ini file within my htdocs folder and then simply echoed out phpinfo() (I echoed this in one of my Controllers, (using Zend)). The index.php file is within the htdocs folder.
When I look # "Loaded Configuration File", it still reads
/etc/ instead of ../htdocs/
Anybody know what's up?
In general, it isn't possible to load php.ini on a per directory basis, but in some special cases (CGI/FastCGI), it is: see documentation for Per-user configuration
Since PHP 5.3.0, PHP includes support for .htaccess-style INI files on a per-directory basis. These files are processed only by the CGI/FastCGI SAPI. This functionality obsoletes the PECL htscanner extension. If you are using Apache, use .htaccess files for the same effect.
In addition to the main php.ini file, PHP scans for INI files in each directory, starting with the directory of the requested PHP file, and working its way up to the current document root (as set in $_SERVER['DOCUMENT_ROOT']). In case the PHP file is outside the document root, only its directory is scanned.
If you are hosting several independent sites on one server, you should consider FastCGI anyway, to keep them separated. With php5-fpm it's very easy to setup many pools of workers.
Note that only set a limited subset of the ini-options in the user-ini-file.
As you said you don't have control on the server, the possible work-arounds would be to:
Use ini_set() to override the changes inside your script. Not all of the configuration directives can be changed using ini_set() though.
Use an .htaccess file in your directory to override the configurations in php.ini file.
(certain parts adapted from #1438393)
Hope this helps!
I'm not sure you understood the post. The post means if you run the server and want a per domain php.ini you can run the module as a per domain so each user controls there domain php.ini however it looks like your server does not offer this so you will need to us htaccess file to overwrite the php.ini settings.
By over write this doesn't mean you can change the directory this means maybe add a module or add error reporting ect...
You can do it by using this post: How can I use xdebug to debug only one virtual host?
How do I include a php.ini file in another php.ini file?
I don't think you can "include" .ini files from the main php.ini file.
One possible solution, though, might be to use this option on the configure line, when compiling PHP:
--with-config-file-scan-dir=PATH
Set the path where to scan for configuration files
If this option is used at compile-time, PHP will look for every .ini file in this directory, in addition to the "normal" php.ini file.
I suppose this is what is used by Ubuntu, for instance, which uses a different .ini file for each downloaded extension, instead of modifying php.ini.
The path to the php.ini file is being defined with this option, on the configure line:
--with-config-file-path=PATH
Set the path in which to look for php.ini [PREFIX/lib]
Still, it probably means you'll have to re-compile PHP -- which is not that hard, btw -- the hardest part being to get the dependencies you need.
And, here is a post on the internals# mailling-list that says the same thing as I do: config files and PHP_CONFIG_FILE_SCAN_DIR
One can also define the path in ~/.bashrc
export PHP_INI_SCAN_DIR=/usr/local/lib/php.d
I installed Memcached for php and wasn't sure how to make sure that its ini was included in my php.ini file, but as it turns out, it automatically is. You can validate what is being loaded by running php --ini.
php --ini
Configuration File (php.ini) Path: /opt/local/etc/php5
Loaded Configuration File: (none)
Scan for additional .ini files in: /opt/local/var/db/php5
Additional .ini files parsed: /opt/local/var/db/php5/memcached.ini
EDIT: My answer was mistaken. This only works in .conf files, which is not the question asked. Better testing showed that it won't work in php.ini files, where include statement is ignored.
I just tested it on DebianĀ 9 (Stretch) with PHP-FPM. From some .conf file, use this syntax:
include=/path/to/special-php.ini
or even
include=/path/to/special-dir-full-of-conf-files/*.conf
as it is used in
/etc/php/7.0/fpm/php-fpm.conf
include=/etc/php/7.0/fpm/pool.d/*.conf
By the way, this will be most useful if you split your settings by topic, and or if you want a set for development and another one for production. Then you could do it the Debian/Apache style like
/etc/php/conf-available/
/etc/php/conf-enabled/
with symliks from the second to the other and an include to that one.
It seems you cannot include one ini file into another so it gets referenced and loaded. But you can set php up to load several files by telling it which folders to look into.
When using a FastCGI setup (possibly in FPM, too, though I don't know that for sure) you can export environment variables from within the PHP wrapper.
There you could do:
export PHP_INI_SCAN_DIR=/etc/php5/cgi/conf.d:/var/www/mydomain.net/etc
/var/www/mydomain.net/etc is just an example. It's the folder where you put your additional ini files into. It seems this can be a : separated list.
Use a phpinfo.php (file called arbitrarily containing only <?php phpinfo();), open the corresponding URL in your browser and check the list of directories that are parsed and the list of files that get loaded in the top area of it.
/etc/php5/cgi/conf.d should always be included (I guess because it was compiled into the PHP executable) and possibly not really be needed.
You can't. Read online pages:
The configuration file
SUMMARY: The configuration file
(php.ini) is read when PHP starts up.
For the server module versions of PHP,
this happens only once when the web
server is started. For the CGI and CLI
version, it happens on every
invocation.
.user.ini files
SUMMARY: In addition to the main
php.ini file, PHP scans for INI files
in each directory, starting with the
directory of the requested PHP file,
and working its way up to the current
document root (as set in
$_SERVER['DOCUMENT_ROOT']). Only INI
settings with the modes PHP_INI_PERDIR
and PHP_INI_USER will be recognized in
.user.ini-style INI files.
You could try to simulate it making use of the ini_set function. But as the "man page" indicates, not all ini options can be changed using ini_set. It's definitely a useful function, though.