- Setting Your PHP Settings in Command Line
- Specify the php.ini File in Command Line
- Change PHP settings
- How to find the php.ini file used by the command line?
- What is php.ini
- Where is php.ini file located by default
- How can I find the php.ini file from command line
- php –ini
- php-config –ini-dir
- php -i and grep
- Conclusions
- Where is php.ini? Find the Correct PHP Configuration File
- Method 1: Use phpinfo() function
- Method 2: Use the command line
- Method 3: Check default locations
- On Linux:
- On Windows:
- Conclusion
- Where is php.ini? Find the Correct PHP Configuration File
- Method 1: Use phpinfo() function
- Method 2: Use the command line
- Method 3: Check default locations
- On Linux:
- On Windows:
- Conclusion
Setting Your PHP Settings in Command Line
When you are running a PHP file from the command line (on Cloud VPS Hosting or otherwise), there may be times when you need to make changes to the PHP settings. In this guide, we will show you how to specify the php.ini file, and change a PHP setting in the command line. If you are not working in the command line, you can change your PHP settings in cPanel.
Specify the php.ini File in Command Line
- Connect to your server using SSH.
- You can specify the php.ini file in the command line by using the following syntax: php -c [Path to php.ini file] [Path to .php file] For example: php -c /home/userna5/public_html/php.ini /home/userna5/public_html/example.php Now the example.php file will run, with the limitations set in the php.ini file located here: /home/userna5/public_html
Change PHP settings
- Connect to your server using SSH.
- You can specify php.ini settings in the command line with this syntax: php -c [Path to php.ini file] [Path to .php file] -d [PHP setting] For example: php -c /home/userna5/public_html/php.ini /home/userna5/public_html/example.php -d memory_limit=256M In this example, you can see I am setting the memory limit to 256 Megabytes. Here are some other PHP settings that are often modified:
max_execution_time max_input_time upload_max_filesize
Congratulations, now you know how to set the php.ini file, and change your PHP settings from the command line!
John-Paul is an Electronics Engineer that spent most of his career in IT. He has been a Technical Writer for InMotion since 2013.
How to find the php.ini file used by the command line?
There are a few ways to locate php.ini file by command line on Linux Ubuntu, Linux Mint, and other Linux distributions. Some of the options showed here are also compatible with Windows, specially usin WSL.
What is php.ini
The php.ini file is the configuration file that 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.
It is the main place where you declare changes to your PHP settings. The server is already configured with standard settings for PHP, which your site or application will use by default. Unless you need to change one or more settings, there is no need to create or modify a php.ini file.
Where is php.ini file located by default
The php.ini file is searched for in these locations (in order):
- 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() (returns the type of interface between web server and PHP).
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.
How can I find the php.ini file from command line
php –ini
There is a simple option called —ini that you can use when run php command:
The output will show where is the php.ini used by command line, as well additional scanned configuration files:
Configuration File (php.ini) Path: /etc/php/7.4/cli Loaded Configuration File: /etc/php/7.4/cli/php.ini Scan for additional .ini files in: /etc/php/7.4/cli/conf.d Additional .ini files parsed: /etc/php/7.4/cli/conf.d/10-mysqlnd.ini, /etc/php/7.4/cli/conf.d/10-pdo.ini, /etc/php/7.4/cli/conf.d/15-xml.ini, /etc/php/7.4/cli/conf.d/20-bcmath.ini, /etc/php/7.4/cli/conf.d/20-exif.ini, /etc/php/7.4/cli/conf.d/20-gd.ini, /etc/php/7.4/cli/conf.d/20-gettext.ini, /etc/php/7.4/cli/conf.d/20-iconv.ini, /etc/php/7.4/cli/conf.d/20-intl.ini, /etc/php/7.4/cli/conf.d/20-json.ini, /etc/php/7.4/cli/conf.d/20-mbstring.ini, /etc/php/7.4/cli/conf.d/20-mysqli.ini, /etc/php/7.4/cli/conf.d/20-pdo_mysql.ini, /etc/php/7.4/cli/conf.d/20-pdo_pgsql.ini, /etc/php/7.4/cli/conf.d/20-pdo_sqlite.ini, /etc/php/7.4/cli/conf.d/20-pgsql.ini, /etc/php/7.4/cli/conf.d/20-redis.ini, /etc/php/7.4/cli/conf.d/20-simplexml.ini, /etc/php/7.4/cli/conf.d/20-sockets.ini, /etc/php/7.4/cli/conf.d/20-sqlite3.ini, /etc/php/7.4/cli/conf.d/20-xmlreader.ini, /etc/php/7.4/cli/conf.d/20-xmlwriter.ini, /etc/php/7.4/cli/conf.d/20-xsl.ini, /etc/php/7.4/cli/conf.d/20-zip.ini, /etc/php/7.4/cli/conf.d/xdebug.ini
php-config –ini-dir
Using php-config you can list only the path where the main PHP configuration file is located:
The output is something like:
php -i and grep
The command php -i shows a complete phpinfo() result. You can find all configurations and apply grep command to filter only the .ini configuration file:
php -i | grep 'Configuration File'
Or in Windows you can use find instead:
php -i | find/i"configuration file"
The result to both command will be similar to:
Configuration File (php.ini) Path => /etc/php/7.4/cli Loaded Configuration File => /etc/php/7.4/cli/php.ini
Finally you can use grep to filter all lines of the phpinfo() that shows .ini :
The output will be similar to php -i command:
Configuration File (php.ini) Path: /etc/php/7.4/cli Loaded Configuration File: /etc/php/7.4/cli/php.ini Scan for additional .ini files in: /etc/php/7.4/cli/conf.d Additional .ini files parsed: /etc/php/7.4/cli/conf.d/10-mysqlnd.ini, /etc/php/7.4/cli/conf.d/10-pdo.ini, /etc/php/7.4/cli/conf.d/15-xml.ini, /etc/php/7.4/cli/conf.d/20-bcmath.ini, /etc/php/7.4/cli/conf.d/20-exif.ini, /etc/php/7.4/cli/conf.d/20-gd.ini, /etc/php/7.4/cli/conf.d/20-gettext.ini, /etc/php/7.4/cli/conf.d/20-iconv.ini, /etc/php/7.4/cli/conf.d/20-intl.ini, /etc/php/7.4/cli/conf.d/20-json.ini, /etc/php/7.4/cli/conf.d/20-mbstring.ini, /etc/php/7.4/cli/conf.d/20-mysqli.ini, /etc/php/7.4/cli/conf.d/20-pdo_mysql.ini, /etc/php/7.4/cli/conf.d/20-pdo_pgsql.ini, /etc/php/7.4/cli/conf.d/20-pdo_sqlite.ini, /etc/php/7.4/cli/conf.d/20-pgsql.ini, /etc/php/7.4/cli/conf.d/20-redis.ini, /etc/php/7.4/cli/conf.d/20-simplexml.ini, /etc/php/7.4/cli/conf.d/20-sockets.ini, /etc/php/7.4/cli/conf.d/20-sqlite3.ini, /etc/php/7.4/cli/conf.d/20-xmlreader.ini, /etc/php/7.4/cli/conf.d/20-xmlwriter.ini, /etc/php/7.4/cli/conf.d/20-xsl.ini, /etc/php/7.4/cli/conf.d/20-zip.ini, /etc/php/7.4/cli/conf.d/xdebug.ini
Conclusions
There are several ways to find php.ini file and other configurations files of your PHP installation using native commands on terminal.
Where is php.ini? Find the Correct PHP Configuration File
The php.ini file is a configuration file used by PHP to specify settings for your web server, such as file upload size, error reporting, and memory usage. However, the location of the php.ini file can vary depending on your server setup and operating system.
In this tutorial, we will explore a few methods to help you locate the correct php.ini file on your web server.
Method 1: Use phpinfo() function
The phpinfo() function displays detailed information about your PHP configuration, including the location of your php.ini file. To use this function, follow these steps:
- Create a new PHP file on your web server. You can name it anything you like, but for this tutorial, we will name it phpinfo.php.
- Open the phpinfo.php file in a text editor and add the following code:
You should see a page with detailed information about your PHP configuration. Look for the “Loaded Configuration File” section, which should contain the full path to your php.ini file.
Method 2: Use the command line
If you have access to the command line, you can use the `php —ini` command to find the location of the php.ini file. Follow these steps:
- Log in to your web server using SSH or another terminal application.
- Type the following command and press Enter:
Method 3: Check default locations
Depending on your operating system and server configuration, the php.ini file may be located in one of the default locations. Here are some common default locations:
On Linux:
On Windows:
You can try searching for the php.ini file in these locations using your FTP or file manager.
If none of these methods work, you can contact your web hosting provider or system administrator for assistance in locating the php.ini file on your server.
Conclusion
The php.ini file is an essential configuration file for PHP. By following the methods outlined in this tutorial, you should be able to locate the correct php.ini file on your web server. Remember, the location of the php.ini file can vary depending on your server setup and operating system, so it’s important to double-check the location before making any changes to the file.
Where is php.ini? Find the Correct PHP Configuration File
The php.ini file is a configuration file used by PHP to specify settings for your web server, such as file upload size, error reporting, and memory usage. However, the location of the php.ini file can vary depending on your server setup and operating system.
In this tutorial, we will explore a few methods to help you locate the correct php.ini file on your web server.
Method 1: Use phpinfo() function
The phpinfo() function displays detailed information about your PHP configuration, including the location of your php.ini file. To use this function, follow these steps:
- Create a new PHP file on your web server. You can name it anything you like, but for this tutorial, we will name it phpinfo.php.
- Open the phpinfo.php file in a text editor and add the following code:
You should see a page with detailed information about your PHP configuration. Look for the “Loaded Configuration File” section, which should contain the full path to your php.ini file.
Method 2: Use the command line
If you have access to the command line, you can use the `php —ini` command to find the location of the php.ini file. Follow these steps:
- Log in to your web server using SSH or another terminal application.
- Type the following command and press Enter:
Method 3: Check default locations
Depending on your operating system and server configuration, the php.ini file may be located in one of the default locations. Here are some common default locations:
On Linux:
On Windows:
You can try searching for the php.ini file in these locations using your FTP or file manager.
If none of these methods work, you can contact your web hosting provider or system administrator for assistance in locating the php.ini file on your server.
Conclusion
The php.ini file is an essential configuration file for PHP. By following the methods outlined in this tutorial, you should be able to locate the correct php.ini file on your web server. Remember, the location of the php.ini file can vary depending on your server setup and operating system, so it’s important to double-check the location before making any changes to the file.