Find php ini command line

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

Solution: Server doesn’t scan for files automatically, it loads extensions mentioned in php config files in and configurations. When PECL installs an extension, it seems to add a line to the top of php.ini immediately above the [PHP] line, e.g.: The tutorial advises going to /usr/local/etc/php/7.1/conf.d/ and creating individual config files for each extension.

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?

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

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 

On Windows, use find instead:

php -i | find/i"configuration file" 

You can use get_cfg_var(‘cfg_file_path’) for that:

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.

Apache — PHP.ini location on El Capitan, The default location on OSX El Capitan and macOS Sierra is /etc/php.ini But if that file doesn’t exist, php will use /etc/php.ini.default. Don’t forget to create a copy if you want to make changes: $ sudo cp /etc/php.ini.default /etc/php.ini Also, php will scan /Library/Server/Web/Config/php dir for additional …

No php.ini with brew

I installed PHP7 with brew and it said:

The php.ini file can be found in: /usr/local/etc/php/7.0/php.ini 

but I don’t see anything there. So I confirmed it with php-fpm -i :

Configuration File (php.ini) Path => /usr/local/etc/php/7.0 Loaded Configuration File => (none) Scan this dir for additional .ini files => /usr/local/etc/php/7.0/conf.d 

I think for this reason I’m unable to run PHP scripts, how do I fix it?

You can use the following command:

php -r "phpinfo();" | grep php.ini 

it will tell you what php.ini is being executed, in my case:

▶ php -r "phpinfo();" | grep php.ini Configuration File (php.ini) Path => /usr/local/etc/php/7.3 Loaded Configuration File => /usr/local/etc/php/7.3/php.ini 

I have the same issue. Someone has already created an issue for this:

  • https://github.com/Homebrew/homebrew-php/issues/3599
  • https://github.com/Homebrew/homebrew-php/issues/3598

It looks like running brew install php70 —build-from-source does create a php.ini file. It worked for me.

cp /etc/php.ini.default /usr/local/etc/php/8.0/php.ini 

/php/8.0/ php and 8.0 directories might not exist so you have to create them

check with php —ini where it is looking for conf files and if any is loaded

If you have installed PHP using brew and do not find php.ini file in /etc than search for php.ini.default , this is the php.ini file. Please create a copy of default php.ini and naming it php.ini using command mentioned below.

sudo cp /etc/php.ini.default /etc/php.ini 

Macos — Mac CLI PHP ini file location, I am using OSX Catalina and am trying to increase the memory limit for PHP — no matter where I look I cannot find the right PHP ini file to change this. php -v PHP 7.3.11 (cli) (built: Apr 17 2020

What is the default path for PHP extensions in php.ini?

I’m getting back in to web development so have decided to re-install my Mac’s dev environment from scratch with homebrew (I’m following the tutorial at https://getgrav.org/blog/macos-sierra-apache-multiple-php-versions which is probably the best tutorial on the subject that I’ve ever read).

Everything is going fine apart from using PECL to install extensions like APCU and Xdebug. I think I can get extensions working in a slightly hacky way, but I’d rather properly understand what’s going on here.

My php.ini file is located at /usr/local/etc/php/7.1/php.ini. When PECL installs an extension, it seems to add a line to the top of php.ini immediately above the [PHP] line, e.g.:

1 zend_extension="xdebug.so" 2 extension="apcu.so" 3 [PHP] 4 5 ;;;;;;;;;;;;;;;;;;; 6 ; About php.ini ; 7 ;;;;;;;;;;;;;;;;;;; 8 ; PHP's initialization file, generally called php.ini, is responsible for 9 ; configuring many of the aspects of PHP's behavior. 

The tutorial advises going to /usr/local/etc/php/7.1/conf.d/ and creating individual config files for each extension. i.e., lines 1 and 2 in php.ini would be deleted, and /usr/local/etc/php/7.1/conf.d/ext-apcu.ini and /usr/local/etc/php/7.1/conf.d/ext-xdebug.ini would be created, with config settings for each extension included in the relevant ext-xx.ini file.

Neither the default PECL approach of referencing the extension in php.ini nor the recommended approach of using an ext-xx.ini file for each extension seems to load the extensions successfully. I can hack round this by specifying a path to the extensions (/usr/local/lib/php/pecl/somedatestamp/extension.so), but I’d rather not have to. So:

  1. (I’m pretty sure the answer to this is «yes», but just to be sure): does the server just scan through the conf.d folder and try to load any extension.so that is described in every ext-extension.so file it finds?
  2. How do I set the equivalent of $PATH for my php configuration? phpinfo() refers to an extension_dir variable and gives the value as /usr/local/Cellar/php@7.1/7.1.20/lib/php/20160303, and there’s an extension_dir variable set in php.ini but it’s commented out. So where is PHP getting the value it’s displaying through phpinfo(), and is it possible to specify multiple directories where PHP will look for extensions?
  1. Server doesn’t scan for *.so files automatically, it loads extensions mentioned in php config files in extension=extension.so and zend_extension=extension.so configurations. To check all config files which are loaded during server start run the command php —ini , my example output is:
$ php --ini Configuration File (php.ini) Path: /usr/local/etc/php/7.1 Loaded Configuration File: /usr/local/etc/php/7.1/php.ini Scan for additional .ini files in: /usr/local/etc/php/7.1/conf.d Additional .ini files parsed: /usr/local/etc/php/7.1/conf.d/ext-opcache.ini, /usr/local/etc/php/7.1/conf.d/ext-phalcon.ini, /usr/local/etc/php/7.1/conf.d/ext-xdebug.ini, /usr/local/etc/php/7.1/conf.d/php-memory-limits.ini 

In you case it looks like you might have messed versions: your config file is located in /usr/local/etc/php/7.1/php.ini (version 7.1) but you are trying to put additional config files in /usr/local/etc/php/5.6/conf.d/ (version 5.6). Try to put them in /usr/local/etc/php/7.1/conf.d

extension_dir = "/usr/local/lib/php/pecl/20160303" 

This value is valid for php version 7.1, timestamp 20160303 specifies PHP API version for the extensions. You can also check that PECL configuration for the extension dir has the same value as in php config using the command

After these steps you can check if extension is loaded with the command

It lists all the loaded php modules and extensions. If some extension is mentioned in config file but could not be loaded, you will get warning.

Macos — Change php.ini location, It’s good practice to have separate ini’s for the two environments. If you must change the directory PHP looks for the php.ini file, you can use the PHPIniDir in your web server conf file. If you wish to just add additional directories to be scanned, you can set the PHP_INI_SCAN_DIR environment variable. Share …

Mac CLI PHP ini file location

I am using OSX Catalina and am trying to increase the memory limit for PHP — no matter where I look I cannot find the right PHP ini file to change this.

php -v PHP 7.3.11 (cli) (built: Apr 17 2020 19:14:14) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies php --ini Configuration File (php.ini) Path: /etc Loaded Configuration File: (none) Scan for additional .ini files in: (none) Additional .ini files parsed: (none) 
-rw-r--r-- 1 root wheel 5331 14 Dec 2019 /etc/php-fpm.conf.default -r--r--r-- 1 root wheel 71890 14 Dec 2019 /etc/php.ini.default -r--r--r-- 1 root wheel 71055 1 Apr 2018 /etc/php.ini.default-previous -r--r--r-- 1 root wheel 71055 1 Apr 2018 /etc/php.ini.default-previous~orig 

so it looks like there is No php.ini file to be able to change the memory limit but I assume there has to be so how do I find it?

You should find it in /private/etc if it exists, otherwise you have to make one of the defaults the file you wish to use:

sudo cp /private/etc/php.ini.default /private/etc/php.ini 

Location of php.ini file in Windows 8, I use WampServer, so first go to it’s folder, then. C:\wamp64\bin\php\php5.6.16\. In that folder you can find php.ini file. It was for PHP 5.6, but if you want PHP 7.0 version’s php ini file, just go one folder back and choose PHP 7.0 folder, here you goo. Hope it can help you )

Источник

How to Find php.ini File Location from Command Line

This article will help you to find php.ini file location. php.in file is very useful file to coustomize the PHP behaviour at runtime and it is also a configuration file. Using this you can easily administrator Apache web server. You can set the parameters like uploading director, register global variable, disable errors and many more. If you want to make a quick adjustment to php.in file but you are not sure where it is?

In this article we will learn how to find and edit the php.ini file using command line. If you want to edit php.ini file in Cpanel follow this tutorial edit php.ini file in Cpanel.

Find php.ini File Location

First of all find the php.ini file location using command line in linux.

$ php --version PHP 7.4.6 (cli) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.6, Copyright (c), by Zend Technologies

Let’s find the php.ini file using below command.

You will some output like below:

Configuration File (php.ini) Path => /etc Loaded Configuration File => /etc/php.ini

Now you found your php.ini file located in /etc/ directory.

Get PHP information using CLI

To get the php information you can also use CLI . Type “-i” follow by php command. For example:

# php -I # php -i | more # php -i | grep pdo

You can also heck the php loaded module with above but you can also I check the php module using creating php.info file.

FAQs

Where can I find php.ini file?

php.in file is very useful file to coustomize the PHP behaviour at runtime and it is default configuration file for php application. You can set the parameters like uploading director, register global variable, disable errors and many more. So run the ” php -i | grep php.ini” to find the php.ini file location.

How do I open php.ini file?

To open php.ini file you can use any txt editor like, vim, vi, nano etc. example: vim /etc/php.ini.

How do I reload php.ini file after updating?

Reload the apache service simply running, systemctl httpd reload.

How do I open php.ini file in Linux terminal?

To open php.ini file in Linux terminal and just use vim or vi command. For example : vim /etc/php.ini.

What is the location of php.ini file in WordPress?

Default location of php.ini file in WordPress is wp-admin directory.

Источник

Читайте также:  Цикл foreach php ограничить
Оцените статью