How can I know which 'php.ini' file is used?
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
How can I find the php.ini file used by the command line?
Just run php --ini
and look for Loaded Configuration File in the output for the location of php.ini
used by your CLI.
Not able to get which php.ini is used
You wrote:
phpinfo() gives path as c:\windows but there is no php.ini
This means your .dll expects the configuration file in c:\windows
.
Your tutorial mistakenly advises to create a configuration file in c:\php\php.ini
. Move it to c:\windows
, edit it to your liking, and it should work fine.
I would advise a beginner who seeks to learn PHP/Apache to use ready-to-use packages at first, such as WAMP Server. Manual installations require deeper understanding of PHP (and Apache to some extent).
Who reads the 'php.ini' file and how many php.ini files can possibly be exist there? What's the role of every such 'php.ini' file?
- The PHP compiler/parser.
- Because PHP does not persist for command line invocations, so it is read at run-time.
- Every time you call a PHP script, either CGI or CLI.
- More than one, typically 2. One for the web server and one for CLI/CGI.
Getting value of web php.ini file from console script
You can use echo php_ini_loaded_file();
from the web to find the name of the web/apache2 ini file. In my case, it is /usr/local/zend/etc/php.ini.
Then, in your CLI application, you can parse the ini file into an array which you can use to retrieve the data you need.
<?php
$config = parse_ini_file('/usr/local/zend/etc/php.ini');
// Ouput of `var_dump($config);`
array (size=118)
'engine' => string '1' (length=1)
'short_open_tag' => string '1' (length=1)
'precision' => string '14' (length=2)
'output_buffering' => string '4096' (length=4)
'zlib.output_compression' => string '' (length=0)
'implicit_flush' => string '' (length=0)
'unserialize_callback_func' => string '' (length=0)
'serialize_precision' => string '-1' (length=2)
'disable_functions' => string '' (length=0)
'disable_classes' => string '' (length=0)
'realpath_cache_size' => string '256k' (length=4)
'zend.enable_gc' => string '1' (length=1)
'expose_php' => string '1' (length=1)
'max_execution_time' => string '500' (length=3)
'max_input_time' => string '60' (length=2)
'memory_limit' => string '256M' (length=4)
'error_reporting' => string '32767' (length=5)
'display_errors' => string '1' (length=1)
'display_startup_errors' => string '1' (length=1)
...
echo $config['max_execution_time']; // 500
where php.ini of is located in laravel applications?
You can use phpinfo()
function to check where the php.ini
file is located at:
<?php
phpinfo();
Or simply run php artisan tinker
in the terminal where the laravel project is and then run phpinfo()
in same terminal.
Then, look for Configuration File (php.ini) Path
in the output of phpinfo()
.
Where can I find php.ini?
The best way to find this is:
Create a PHP (.php) file and add the following code:
<?php phpinfo(); ?>
and open it in a browser. It will show the file which is actually being read!
Updates by the OP:
- The previously accepted answer is likely to be faster and more convenient for you, but it is not always correct. See comments on that answer.
- Please also note the more convenient alternative
<?php echo php_ini_loaded_file(); ?>
mentioned in this answer.
I can not find my php.ini file
execute this command
locate php.ini
This will give you a list of all files with names where 'php.ini' is a part of it.
E.g.
/etc/php.ini
/etc/php.ini.rpmnew
/home/myuser/mywebsite.com/demo/local_php.ini
...
Which PHP Ini file does my WAMP webpage uses?
you can find it in phpinfo() output
create file info.php
<?php
phpinfo();
and call it from web server
Related Topics
How to Access Dynamic Variable Names in Twig
Mock Private Method With PHPunit
How to Enable Curl in Wamp Server
Resetting Array Pointer in Pdo Results
How to Get Enum Possible Values in a MySQL Database
How to Use a String as an Array Index Path to Retrieve a Value
Codeigniter: Passing Data from Controller to View
Generating a Drop Down List of Timezones With PHP
Get the Files Inside a Directory
MySQLi_Fetch_Array While Loop Columns
PHP Fatal Error: Call to Undefined Function Json_Decode()
How to Access MySQL Result Set Data With a Foreach Loop
How to Replace Text Urls and Exclude Urls in HTML Tags
MySQL - Ignore Insert Error: Duplicate Entry
How to Get the Real Url After File_Get_Contents If Redirection Happens
PHP: How to Read a .Txt File from Ftp Server into a Variable