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.
Related
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
I have a local project I am working on. I have at the root of my project and index.php php.ini and local_connector.php.
When I run php -S ... from inside my project. It says that the php.ini is not loaded.
This is the code I have in my index.php
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
This is what I have in my php.ini
auto_prepend_file = "./local_connector.php"
The idea is I will have multiple pages that use the local_connector but I don't want to include it in every file. Is this possible with php's local server?
I would rather not set up an entire local apache server, so if someone knows a good way of getting this to work, or a work around. That would be very helpful.
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.
When publish PHP project to server,maybe this server not support some extensions but my project required, so I want to find all extionsions my project used.
Like...
"require": {
"php": ">=5.3.0",
"ext-gd": "*"
}
is there some Tools or Commands support?
###For Example
//filename is exp.php
class exp{
private $array = ['a'=>'b'];
private $conn = mysql_connect("....");
}
//tool or command result
require >=PHP5.4,ext-mysql,
//filename is exp.php
namespace com\core\exp
class exp{
private $array = array('a'=>'b');
private $conn = new mysqli("....");
}
//tool or command result
require >=PHP5.3,ext-mysqli
The most common way to load a PHP extension is to include it in your php.ini configuration file. Please note that many extensions are already present in your php.ini and that you only need to remove the semicolon to activate them.
;extension=php_extname.dll
change like this
extension=php_extname.dll
However, some web servers are confusing because they do not use the php.ini located alongside your PHP executable. To find out where your actual php.ini resides, look for its path in phpinfo():
Configuration File (php.ini) Path C:\WINDOWS
Loaded Configuration File C:\Program Files\PHP\5.2\php.ini
After activating an extension, save php.ini, restart the web server and check phpinfo() again. The new extension should now have its own section.
for example:
<?php
phpinfo();
?>
php -m : will give all the modules list
php -i : will give more detailed information about current configuration.
On windows8 I got this with php 5.3:
echo sys_get_temp_dir();
output:
C:\Windows
Am I not understand something or it is a bug?
UPD
trying $_ENV:
<?php
var_export($_ENV);
output:
array ( )
Checking upload_tmp_dir:
<?php
echo ini_get('upload_tmp_dir');
output:
C:\Windows\Temp
Looking at the PHP source, it will call GetTempPath to determine the temp directory. According to the documentation, the windows directory C:\Windows is the last fallthrough option. You should check under which user profile PHP or its host process is running, maybe the environment needs some fixing.
Related to this PHP Bug (only CGI context?).
I have the same problem and the solution is to change the apache configuration to expose the TEMP system environment variable to PHP with this directive in apache configuration file (httpd.conf) :
PassEnv TEMP
Don't forget to activate the env_module, generally uncomment the line "LoadModule env_module modules/mod_env.so".
This solution fixes the result of these PHP functions: sys_get_temp_dir(), tempnam().