Linux где лежит php ini

[How To] find php.ini file location

If you are a Linux/Unix user who is working with PHP, you may need to edit the php.ini file at some point in time. But where do you find this file? In this article, we will discuss different ways to locate the php.ini file on Linux/Unix servers.

Table of Contents

Using the phpinfo() Function

The phpinfo() function is a great tool for checking your PHP configuration settings. It can also help you find the location of the php.ini file on your server. Here are the steps to follow:

    Create a new PHP file with the following code:

Using the Command Line

If you have access to the command line on your server, you can use the following command to find the location of the php.ini file:

This will display the location of the php.ini file on your server.

Checking with Your Hosting Provider

If you are on a shared hosting plan, you may not have access to the php.ini file. In this case, you can contact your hosting provider to find out the location of the file.

Looking for the Default Location

If you cannot find the php.ini file using the methods above, you can try looking for the default location. On Windows, the php.ini file is typically located in the Windows directory, such as C:\windows or C:\winnt. On Linux/Unix, it is typically located in /etc/ or /usr/local/lib/.

Using the locate Command

The locate command is a fast way to search for files on your server. You can use the following command to locate the php.ini file:

This will display a list of all files on your server that match the search term “php.ini”.

Using the find Command

The find command is another way to search for files on your server. You can use the following command to find the php.ini file:

This will search your entire server for the file named “php.ini” and display the location of the file.

It is important to note that you may have multiple php.ini files on your server. Make sure you are editing the correct one.

Conclusion

Locating the php.ini file on Linux/Unix servers may seem like a daunting task, but there are several ways to find it. You can use the phpinfo() function, the command line, check with your hosting provider, or look for the default location. In addition, you can use the locate or find command to search for the file. Once you have found the file, you can make the necessary changes to customize your PHP environment to suit your needs.

Источник

Linux где лежит php ini

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 versions, it happens on every invocation.

  • SAPI module specific location ( PHPIniDir directive in Apache 2, -c command line option in CGI and CLI)
  • The PHPRC environment variable.
  • The location of the php.ini file can be set for different versions of PHP. The root of the registry keys depends on 32- or 64-bitness of the installed OS and PHP. For 32-bit PHP on a 32-bit OS or a 64-bit PHP on a 64-bit OS use [(HKEY_LOCAL_MACHINE\SOFTWARE\PHP] for 32-bit version of PHP on a 64-bit OS use [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\PHP] ] instead. For same bitness installation the following registry keys are examined in order: [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y.z] , [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y] and [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x] , where x, y and z mean the PHP major, minor and release versions. For 32 bit versions of PHP on a 64 bit OS the following registry keys are examined in order: [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6421Node\PHP\x.y.z] , [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6421Node\PHP\x.y] and [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6421Node\PHP\x] , where x, y and z mean the PHP major, minor and release versions. If there is a value for IniFilePath in any of these keys, the first one found will be used as the location of the php.ini (Windows only).
  • [HKEY_LOCAL_MACHINE\SOFTWARE\PHP] or [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\PHP] , value of IniFilePath (Windows only).
  • Current working directory (except CLI).
  • The web server’s directory (for SAPI modules), or directory of PHP (otherwise in Windows).
  • Windows directory ( C:\windows or C:\winnt ) (for Windows), or —with-config-file-path compile time option.
Читайте также:  Сбросить настройки интерфейса linux

If php-SAPI.ini exists (where SAPI is the SAPI in use, so, for example, php-cli.ini or php-apache.ini ), it is used instead of php.ini . The SAPI name can be determined with php_sapi_name() .

Note:

The Apache web server changes the directory to root at startup, causing PHP to attempt to read php.ini from the root filesystem if it exists.

Using environment variables can be used in php.ini as shown below.

Example #1 php.ini Environment Variables

; PHP_MEMORY_LIMIT is taken from environment memory_limit = $

The php.ini directives handled by extensions are documented on the respective pages of the extensions themselves. A list of the core directives is available in the appendix. Not all PHP directives are necessarily documented in this manual: for a complete list of directives available in your PHP version, please read your well commented php.ini file. Alternatively, you may find » the latest php.ini from Git helpful too.

Example #2 php.ini example

; any text on a line after an unquoted semicolon (;) is ignored [php] ; section markers (text within square brackets) are also ignored ; Boolean values can be set to either: ; true, on, yes ; or false, off, no, none register_globals = off track_errors = yes ; you can enclose strings in double-quotes include_path = ".:/usr/local/lib/php" ; backslashes are treated the same as any other character include_path = ".;c:\php\lib"

It is possible to refer to existing .ini variables from within .ini files. Example: open_basedir = $ «:/new/dir» .

Scan directories

It is possible to configure PHP to scan for .ini files in a directory after reading php.ini . This can be done at compile time by setting the —with-config-file-scan-dir option. The scan directory can then be overridden at run time by setting the PHP_INI_SCAN_DIR environment variable.

Читайте также:  Запуск java файлов linux

It is possible to scan multiple directories by separating them with the platform-specific path separator ( ; on Windows, NetWare and RISC OS; : on all other platforms; the value PHP is using is available as the PATH_SEPARATOR constant). If a blank directory is given in PHP_INI_SCAN_DIR , PHP will also scan the directory given at compile time via —with-config-file-scan-dir.

Within each directory, PHP will scan all files ending in .ini in alphabetical order. A list of the files that were loaded, and in what order, is available by calling php_ini_scanned_files() , or by running PHP with the —ini option.

Assuming PHP is configured with --with-config-file-scan-dir=/etc/php.d, and that the path separator is . $ php PHP will load all files in /etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d php PHP will load all files in /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=:/usr/local/etc/php.d php PHP will load all files in /etc/php.d/*.ini, then /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d: php PHP will load all files in /usr/local/etc/php.d/*.ini, then /etc/php.d/*.ini as configuration files.

Источник

Find the correct php.ini file

I am currently trying to locate the correct php.ini file to edit it and restart apache so the changes will take place and I’m stumped. I have found three different php.ini files (no idea why there are three) this is how I found the files

$ sudo find / -name php.ini /etc/php5/cli/php.ini /etc/php5/apache2/php.ini /etc/php5/cgi/php.ini 
$ sudo php -i | grep 'Configuration File' Configuration File (php.ini) Path => /etc/php5/cli Loaded Configuration File => /etc/php5/cli/php.ini 
sudo service apache2 restart 
* Restarting web server apache2 
echo ini_get('post_max_size'); 

Which was supposed to be changed to 20M but was still only 2M I tried rebooting my computer thinking maybe that would stop the apache server and reload the php.ini file with the correct setting, but alas that attempt also failed. Is there any chance there could be another php.ini file that could be interfering?

@Michael The file is /etc/php/5.6/apache2/php.ini in Ubuntu 16.04 LTS Xenial Xerus, where 5.6/ is the version of php installed. First copy the file to php.original.ini then open for editing with sudo gedit /etc/php/5.6/apache2/php.ini

7 Answers 7

The three files you have there are each meant for different uses.

/etc/php/5.6/cli/php.ini is for the CLI PHP program, which you found by running php on the terminal.

/etc/php/5.6/cgi/php.ini is for the php-cgi system which isn’t specifically used in this setup.

/etc/php/5.6/apache2/php.ini is for the PHP plugin used by Apache. This is the one you need to edit for changes to be applied for your Apache setup which utilizes the in-built PHP module to Apache.

/etc/php/5.6/fpm/php.ini is for the php5-fpm processor, which is a fastcgi-compatible ‘wrapper’ for PHP processing (such as to hand off from NGINX to php5-fpm ) and runs as a standalone process on the system (unlike the Apache PHP plugin)

For versions of Ubuntu lower than 16.04, /etc/php/5.6/ , /etc/php/7.0/ , /etc/php/7.1/ , and so on, are replaced by /etc/php5/ and so on. Otherwise, these paths remain accurate. Adapt this accordingly for your environment, replacing the 5.6 or number with the actual version folder that exists on your environment.

Источник

How can I find the php.ini file used by the command line?

I need to enable pdo_mysql in my EasyPHP environment, so I went to the php.ini file and uncommented the following line:

extension=php_pdo_mysql.dll 

Unfortunately I still have the same problem. I’m using the CLI so I suppose I need to locate the php.ini file used by the CLI. How can I find it?

Читайте также:  Astra linux метки конфиденциальности

Some context: «The root cause of the problem is that in EasyPHP 5.3 there isn’t any php.ini file in the php folder.

15 Answers 15

Just run php —ini and look for Loaded Configuration File in the output for the location of php.ini used by your CLI.

@AntonyD’Andrea: which is exactly what the question is about. See? It does state so even in the title: How to find the php.ini file used by the command line?

@Mchl: I have shamelessly edited your answer to include the informative not to look for Loaded Configuration File in output 🙂

@Fr0zenFyr: thank you. It’s been so long time ago sine I worked with PHP I don’t even recall if the output from php —ini was always this way, or it has changed since my answer.

You can get a full phpinfo() using:

And, in there, there is the php.ini file used:

$ php -i | grep 'Configuration File' Configuration File (php.ini) Path => /etc Loaded Configuration File => /etc/php.ini 
php -i | find/i"configuration file" 

Then this php instance used no php.ini at all but the default values. The Configuration File line of phpinfo() shows the last place where php looked for an ini file. That can either be the place where it found such a file or the last option which happens to be %SYSTEMROOT% on windows.

@pascal: php -i | find «Configuration file» should work on Windows. Definitely not as powerful as grep, but find will do basic string searching for you. Of course, if php -i dumps its output to stderr, you’re probably SOL.

find is case-sensitive by default, so it has to be perfect ( php -i | find «Configuration File» ) or made case-insensitive ( php -i | find /i «Configuration file» — note the /i flag).

Nobody mentioned, that it’s possible to take that value from script by calling php_ini_loaded_file and when needed php_ini_scanned_files

To check whether the system is using a configuration file, try retrieving the value of the cfg_file_path configuration setting. If this is available, a configuration file is being used.

var_dump( get_cfg_var('cfg_file_path') ); 

And you can simply set the location of the php.ini. You’re using the command line version, so using the -c parameter you can specify the location for this particular run, e.g.

php -c /home/me/php.ini -f /home/me/test.php 

Run php —ini in your terminal, and you’ll get all details about ini files:

Configuration File (php.ini) Path: /etc Loaded Configuration File: /etc/php.ini Scan for additional .ini files in: /etc/php.d Additional .ini files parsed: /etc/php.d/apc.ini, /etc/php.d/bcmath.ini, /etc/php.d/curl.ini, /etc/php.d/dba.ini, /etc/php.d/dom.ini, /etc/php.d/fileinfo.ini, /etc/php.d/gd.ini, /etc/php.d/imap.ini, /etc/php.d/json.ini, /etc/php.d/mbstring.ini, /etc/php.d/memcache.ini, /etc/php.d/mysql.ini, /etc/php.d/mysqli.ini, /etc/php.d/pdo.ini, /etc/php.d/pdo_mysql.ini, /etc/php.d/pdo_sqlite.ini, /etc/php.d/phar.ini, /etc/php.d/posix.ini, /etc/php.d/sqlite3.ini, /etc/php.d/ssh2.ini, /etc/php.d/sysvmsg.ini, /etc/php.d/sysvsem.ini, /etc/php.d/sysvshm.ini, /etc/php.d/wddx.ini, /etc/php.d/xmlreader.ini, /etc/php.d/xmlwriter.ini, /etc/php.d/xsl.ini, /etc/php.d/zip.ini 

For more, use helping command php —help . It’ll display all the possible options.

Источник

Оцените статью
Adblock
detector