How to change the path for additional php.ini files - php

If I run php --ini,then I get the following warnings.
Cannot load Xdebug - it was already loaded
PHP Warning: Module 'memcached' already loaded in Unknown on line 0
....
Configuration File (php.ini) Path: /opt/Qapache/etc
Loaded Configuration File: /opt/Qapache/etc/php.ini
Scan for additional .ini files in: /opt/Qapache/etc
Additional .ini files parsed: /opt/Qapache/etc/php.ini
Yeah, i run a Qnap NAS.
If I comment out the modules in the php.ini like here, they will not be loaded anymore.
So my thought is that the php.ini file is loaded twice by the path for "Scan for additional .ini files in:".
I know that I can override the php execution with the following command
php -c /PATH/TO/php.ini -n so it looks like this.
Configuration File (php.ini) Path: /opt/Qapache/etc
Loaded Configuration File: /PATH/TO/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
And that works, none module was already loaded.
But this is not persistent and I don't want to use the options for it every time.
So, how do I change the path for Scan for additional .ini files in: in general?
Thanks in advance.

That directory is defined when PHP is compiled from source code using the custom flag --with-config-file-scan-dir:
https://www.php.net/manual/en/configure.about.php#configure.options.php
You can change it at run time by setting an ENV var called PHP_INI_SCAN_DIR as defined in the documentation:
https://www.php.net/manual/en/configuration.file.php#configuration.file.scan

Related

How to change php CLI configuration in laradock?

Im using latest laradock with basic configuration.
I created my.ini file with some settings and edit php-fpm/Dockerfile as follow:
COPY ./my.ini /usr/local/etc/php/conf.d/
When i run phpinfo() in browser I see the following:
So, my.ini file successfully loaded. But when I run php -i in workspace bash:
Configuration File (php.ini) Path => /etc/php/8.0/cli
Loaded Configuration File => /etc/php/8.0/cli/php.ini
Scan this dir for additional .ini files => /etc/php/8.0/cli/conf.d
Additional .ini files parsed => /etc/php/8.0/cli/conf.d/10-mysqlnd.ini,
/etc/php/8.0/cli/conf.d/10-opcache.ini,
/etc/php/8.0/cli/conf.d/10-pdo.ini,
/etc/php/8.0/cli/conf.d/15-xml.ini,
/etc/php/8.0/cli/conf.d/20-ast.ini,
/etc/php/8.0/cli/conf.d/20-bcmath.ini,
/etc/php/8.0/cli/conf.d/20-calendar.ini,
/etc/php/8.0/cli/conf.d/20-ctype.ini,
/etc/php/8.0/cli/conf.d/20-curl.ini,
/etc/php/8.0/cli/conf.d/20-dom.ini,
/etc/php/8.0/cli/conf.d/20-exif.ini,
/etc/php/8.0/cli/conf.d/20-ffi.ini,
/etc/php/8.0/cli/conf.d/20-fileinfo.ini,
/etc/php/8.0/cli/conf.d/20-ftp.ini,
/etc/php/8.0/cli/conf.d/20-gd.ini,
/etc/php/8.0/cli/conf.d/20-gettext.ini,
/etc/php/8.0/cli/conf.d/20-iconv.ini,
/etc/php/8.0/cli/conf.d/20-igbinary.ini,
/etc/php/8.0/cli/conf.d/20-intl.ini,
/etc/php/8.0/cli/conf.d/20-mbstring.ini,
/etc/php/8.0/cli/conf.d/20-msgpack.ini,
/etc/php/8.0/cli/conf.d/20-mysqli.ini,
/etc/php/8.0/cli/conf.d/20-pdo_mysql.ini,
/etc/php/8.0/cli/conf.d/20-pdo_pgsql.ini,
/etc/php/8.0/cli/conf.d/20-pdo_sqlite.ini,
/etc/php/8.0/cli/conf.d/20-pgsql.ini,
/etc/php/8.0/cli/conf.d/20-phar.ini,
/etc/php/8.0/cli/conf.d/20-posix.ini,
/etc/php/8.0/cli/conf.d/20-readline.ini,
/etc/php/8.0/cli/conf.d/20-redis.ini,
/etc/php/8.0/cli/conf.d/20-shmop.ini,
/etc/php/8.0/cli/conf.d/20-simplexml.ini,
/etc/php/8.0/cli/conf.d/20-sockets.ini,
/etc/php/8.0/cli/conf.d/20-sqlite3.ini,
/etc/php/8.0/cli/conf.d/20-sysvmsg.ini,
/etc/php/8.0/cli/conf.d/20-sysvsem.ini,
/etc/php/8.0/cli/conf.d/20-sysvshm.ini,
/etc/php/8.0/cli/conf.d/20-tokenizer.ini,
/etc/php/8.0/cli/conf.d/20-xmlreader.ini,
/etc/php/8.0/cli/conf.d/20-xmlwriter.ini,
/etc/php/8.0/cli/conf.d/20-xsl.ini,
/etc/php/8.0/cli/conf.d/20-zip.ini,
/etc/php/8.0/cli/conf.d/25-memcached.ini,
/etc/php/8.0/cli/conf.d/xdebug.ini
How can I add my ini file when I running CLI commands?
When you using laradock, it's simple to change php version, everything config are set by .env.
So, open your .env, find PHP_VERSION change version to what you want and that's it.
Run docker-compose build workspace rebuild image, and your php-cli should be change to specific version.
Document: https://laradock.io/#change-the-php-cli-version

PHP command line loading ioncube_loader?

Does anyone know why this happens? I cannot figure it out.
I run a command line PHP script (eg. prompt$ myscript.cgi) with this at the start:
#!/usr/local/bin/php81 -q
It runs fine using the PHP.ini at:
Configuration File (php.ini) Path: /opt/cpanel/ea-php81/root/etc Loaded Configuration File: /opt/cpanel/ea-php81/root/etc/php.ini Scan for additional .ini files in: /opt/cpanel/ea-php81/root/etc/php.d Additional .ini files parsed: /opt/cpanel/ea-php81/root/etc/php.d/01-ioncube.ini,
Now when I run the exact same script via a PHP 7.2 web page with shell_exec('/path/myscript.cgi') it will switch to PHP 7.2's ini.
Configuration File (php.ini) Path => /opt/cpanel/ea-php81/root/etc Loaded Configuration File => /opt/cpanel/ea-php81/root/etc/php.ini Scan this dir for additional .ini files => /opt/cpanel/ea-php72/root/etc:/opt/cpanel/ea-php72/root/etc/php.d:. Additional .ini files parsed => /opt/cpanel/ea-php72/root/etc/php.ini,
Why?

PHP.INI do not change include_path. WHY? [duplicate]

This question already has answers here:
How can I know which 'php.ini' file is used?
(7 answers)
Closed 2 years ago.
I found my php.ini, changed its include_path but nothing change.
Fatal error: require_once(): Failed opening required 'System.php' (include_path='.:') in /Library/WebServer/Documents/estudos/db_pear.php on line 3
My phpinfo() show that my include_path is just (.:).
My include path in PHP.INI is ('.:/usr/local/share/pear').
My phpinfo() also show PHP.INI in (/etc) and command line ($php --ini) show:
Configuration File (php.ini) Path: /usr/local/etc/php/7.4
Loaded Configuration File: /usr/local/etc/php/7.4/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.4/conf.d
Additional .ini files parsed: /usr/local/etc/php/7.4/conf.d/ext-opcache.ini
I've already restarted my apachectl and my whole pc, but nothing...
Please I would like to use PEAR framework!
Thanks! Blessings!
I got it, Phill!
/etc in phpinfo() is where php.ini will be initialized, so I just put the unique php.ini I had (that was in /usr/local/etc/php/7.4 ) in there and it's work!
I'm happy!
Thanks, my brother for helping - or trying help.

I can't see the errors on MAMP PRO [duplicate]

I search the path where the php.ini file is located in our Linux Ubuntu server, and I found many php.ini files when executing the command find / -name php.ini. So how can I know exactly from a PHP script web page where the php.ini is located?
php --ini
For the webserver-SAPIs use phpinfo()
Here's some sample output:
bash-3.2# php --ini
Configuration File (php.ini) Path: /usr/local/php5/lib
Loaded Configuration File: /usr/local/php5/lib/php.ini
Scan for additional .ini files in: /usr/local/php5/php.d
Additional .ini files parsed: /usr/local/php5/php.d/10-extension_dir.ini,
/usr/local/php5/php.d/20-extension-opcache.ini,
/usr/local/php5/php.d/40-openssl.ini,
/usr/local/php5/php.d/50-extension-apcu.ini,
/usr/local/php5/php.d/50-extension-curl.ini,
/usr/local/php5/php.d/50-extension-gmp.ini,
/usr/local/php5/php.d/50-extension-imap.ini,
/usr/local/php5/php.d/50-extension-intl.ini,
/usr/local/php5/php.d/50-extension-mcrypt.ini,
/usr/local/php5/php.d/50-extension-mssql.ini,
/usr/local/php5/php.d/50-extension-pdo_pgsql.ini,
/usr/local/php5/php.d/50-extension-pgsql.ini,
/usr/local/php5/php.d/50-extension-propro.ini,
/usr/local/php5/php.d/50-extension-raphf.ini,
/usr/local/php5/php.d/50-extension-readline.ini,
/usr/local/php5/php.d/50-extension-xdebug.ini,
/usr/local/php5/php.d/50-extension-xsl.ini,
/usr/local/php5/php.d/60-extension-pecl_http.ini,
/usr/local/php5/php.d/99-liip-developer.ini
You can use php_ini_loaded_file().
Taken from php.net:
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
You may also want to check php_ini_scanned_files().
Also, you should note that if you run a PHP script from CLI, it's possible that a different php.ini file will be used than if a server (e.g., nginx or Apache) runs it.
Other options:
php -i|grep 'php.ini'
create info.php that contains <?php phpinfo(); in the webroot, and run it in your browser
Note that the configuration loaded for PHP when it's being used in the console is different from the configuration for the web process. Most PHP installations would come with a php.ini file for Apache and another for CLI.
To know which configuration file is used for the console commands, use
php -i | grep "Configuration File"
To know which configuration file is used for the web processes, follow these steps
Create an info file (preferably in the root folder)
The contents of this file should be <?php phpinfo(); ?>
Ctrl + F and search for "Configuration File"
You have to use the PHP method php_ini_loaded_file (only after PHP 5.2.4)
php_ini_loaded_file — Retrieve a path to the loaded php.ini file
PHP website example:
<?php
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
?>
Source: PHP site
Just add a file like this:
<?php
phpinfo();
?>
Then look for
Loaded Configuration File
You'll see the full path for the php.ini file.
Create a simple page and it will be listed there!
<?php
phpinfo();
?>
As mentioned, "find / -name php.ini" will help get all the php.ini files. The one you may be editing may not be the one from which the server is drawing the command from! I found php.ini for three different versions of PHP on my server and I got the fix instantly then.

How can I know which 'php.ini' file is used?

I search the path where the php.ini file is located in our Linux Ubuntu server, and I found many php.ini files when executing the command find / -name php.ini. So how can I know exactly from a PHP script web page where the php.ini is located?
php --ini
For the webserver-SAPIs use phpinfo()
Here's some sample output:
bash-3.2# php --ini
Configuration File (php.ini) Path: /usr/local/php5/lib
Loaded Configuration File: /usr/local/php5/lib/php.ini
Scan for additional .ini files in: /usr/local/php5/php.d
Additional .ini files parsed: /usr/local/php5/php.d/10-extension_dir.ini,
/usr/local/php5/php.d/20-extension-opcache.ini,
/usr/local/php5/php.d/40-openssl.ini,
/usr/local/php5/php.d/50-extension-apcu.ini,
/usr/local/php5/php.d/50-extension-curl.ini,
/usr/local/php5/php.d/50-extension-gmp.ini,
/usr/local/php5/php.d/50-extension-imap.ini,
/usr/local/php5/php.d/50-extension-intl.ini,
/usr/local/php5/php.d/50-extension-mcrypt.ini,
/usr/local/php5/php.d/50-extension-mssql.ini,
/usr/local/php5/php.d/50-extension-pdo_pgsql.ini,
/usr/local/php5/php.d/50-extension-pgsql.ini,
/usr/local/php5/php.d/50-extension-propro.ini,
/usr/local/php5/php.d/50-extension-raphf.ini,
/usr/local/php5/php.d/50-extension-readline.ini,
/usr/local/php5/php.d/50-extension-xdebug.ini,
/usr/local/php5/php.d/50-extension-xsl.ini,
/usr/local/php5/php.d/60-extension-pecl_http.ini,
/usr/local/php5/php.d/99-liip-developer.ini
You can use php_ini_loaded_file().
Taken from php.net:
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
You may also want to check php_ini_scanned_files().
Also, you should note that if you run a PHP script from CLI, it's possible that a different php.ini file will be used than if a server (e.g., nginx or Apache) runs it.
Other options:
php -i|grep 'php.ini'
create info.php that contains <?php phpinfo(); in the webroot, and run it in your browser
Note that the configuration loaded for PHP when it's being used in the console is different from the configuration for the web process. Most PHP installations would come with a php.ini file for Apache and another for CLI.
To know which configuration file is used for the console commands, use
php -i | grep "Configuration File"
To know which configuration file is used for the web processes, follow these steps
Create an info file (preferably in the root folder)
The contents of this file should be <?php phpinfo(); ?>
Ctrl + F and search for "Configuration File"
You have to use the PHP method php_ini_loaded_file (only after PHP 5.2.4)
php_ini_loaded_file — Retrieve a path to the loaded php.ini file
PHP website example:
<?php
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
?>
Source: PHP site
Just add a file like this:
<?php
phpinfo();
?>
Then look for
Loaded Configuration File
You'll see the full path for the php.ini file.
Create a simple page and it will be listed there!
<?php
phpinfo();
?>
As mentioned, "find / -name php.ini" will help get all the php.ini files. The one you may be editing may not be the one from which the server is drawing the command from! I found php.ini for three different versions of PHP on my server and I got the fix instantly then.

Categories