How find 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.

Читайте также:  Html рамка вокруг div

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.

Источник

How find 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.

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.

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.

Источник

Where can php.ini be Found

This tutorial is dedicated to an issue that almost every developer may come across. It’s where to find the php.ini file.

As multiple versions of PHP exist with different server configurations, the php.ini file may be placed in different folders.

Here, we will provide you with three methods that will help you to find php.ini in a straightforward way.

Method 1: Creating a new PHP File

The first method to find the php.ini file is creating a new PHP file called info.php . Here is how you can implement it:

You need to load this file in the browser, pressing CTRL + F and looking for “Loaded Configuration File”. You may see what is demonstrated below:

It will tell you the exact location of the php.ini file.

Method 2: Using php -i

For locating the php.ini configuration file, you can run the code below in Linux:

$ php -i | grep "Loaded Configuration File"

In the Windows Command Line, you can invoke:

php -i | findstr /c:"Loaded Configuration File"

The output will look like this:

Loaded Configuration File => /etc/php/7.2/cli/php.in

So, from the example mentioned above, we found out that the PHP install is placed inside /etc/php/7.2 . But, there is an essential thing to consider: there exist three distinct configuration files. Let’s take a look at them:

CLI

For the CLI PHP program, there exists /etc/php/7.2/cli/php.ini . Modifications in this config file will only impact PHP because it operates within the terminal. Hence, the web server will not be affected by that.

APACHE

For the plugin used for APACHE, there exists /etc/php/7.2/apache2/php.ini . You are required to edit it once you work with the APACHE web server.

Nginx either Apache with PHP-FPM

Now, let’s have a look at /etc/php/7.2/apache2/php.ini . It is considered a fastcgi-compatible ‘wrapper’. You are required to edit it once you work with Apache with PHP-FPM or Nginx web server.

Method 3: Using the locate Command

The third method is using the locate command in Linux. If you haven’t installed it yet, you can act like this:

sudo apt update && sudo apt install mlocate

Then, run the locate command as follows:

After running this command, you will notice the list of php.ini files.

How to Edit php.ini in Linux

In this section, we will demonstrate how to edit php.ini on APACHE and Nginx or Apache with PHP-FPM.

APACHE

As a rule, the php.ini file is located in /etc/php/7.2/apache2/php.ini on APACHE. You can replace it with the version that you use. For example, php 7.1 , and so on.

For editing, you can act like this:

sudo nano /etc/php/7.2/apache2/php.ini

If you work with PHP FPM, it can be placed in /etc/php/7.2/fpm/php.ini . So, change the 7.2 version to your own version.

For editing, you can act like this:

sudo nano /etc/php/7.2/fpm/php.ini

Afterwards, you need to press CTRL + X , pressing Y and then — ENTER. In this way, you will save the file and exit it.

After alerting php.ini, you need to restart APACHE.

If you use PHP-FMP, you should restart it.

Nginx or Apache with PHP-FPM

As a rule, Nginx works with PHP-FPM. The php.ini file is placed inside /etc/php/7.2/fpm/php.ini . You need to replace the 7.2 version with your own one.

sudo nano /etc/php/7.2/fpm/php.ini

For saving the file, you need to press CTRL + X . Afterwards, press Y and then ENTER .

After the alert of the php.ini file, it is necessary to restart Nginx like this:

After the alert of the php.ini file, it is necessary to restart Nginx like this:

sudo service nginx restart

So, in this tutorial, we represented to you three different and efficient ways to find the php.ini file. After checking out all the examples above, you can choose the best one for you.

Источник

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