what php.ini does symfony2 cli-commands use? - php

I'm running a console command for symfony sudo php app/console assetic:dump and it is showing Warnings even though I specifically ignore Warnings on the php.ini for apache and for cli.
Is it using a different php.ini altogether?

Do sudo php -i for a readout of your PHP settings, including the path to php.ini.

Run the following command:
php -i | grep .ini
and you will see the full path of the php.ini used by cli.
Don't use sudo when dumping assets as the owner of the created files will be "root" and the nginx/apache user will not be able to use them.

Yes, it is probable that php used on the command line uses a different php.ini than php in apache.
Specifically in wamp server, php cli uses the php.ini in the php directory, and php as apache module uses php.ini situated in the apache/bin folder.

Related

Symfony 5 : could not find driver [duplicate]

A few years ago I installed Apache 2.2x and PHP 5.3.1 on a Linux server I maintain. I used .tar.gz's and built them as instructed (instead of rpms and what-have-you). And all was fine.
Today I need to install this which seems like a PHP library. I went through all the steps up to make install, and I found ibm_db2.so in $PHP_HOME/lib/extensions/somecomplicatedname/ibm_db2.so.
The great catch is the last step is to configure file php.ini, but there aren't any php.ini files on my system. Horror of horrors. PHP works fine, except of course for this newfangled ibm_db2 thingamajig that I want to use so somebody can use a GUI to tinker with DB2. (I tried a small PHP script which fails and indicates that the ibm_db2 functions are not available.)
I have to deal with PHP once every few years, so please enlighten me at a very basic level about what I could do to enable web-based GUI access to DB2.
On the command line execute:
php --ini
You will get something like:
Configuration File (php.ini) Path: /etc/php5/cli
Loaded Configuration File: /etc/php5/cli/php.ini
Scan for additional .ini files in: /etc/php5/cli/conf.d
Additional .ini files parsed: /etc/php5/cli/conf.d/curl.ini,
/etc/php5/cli/conf.d/pdo.ini,
/etc/php5/cli/conf.d/pdo_sqlite.ini,
/etc/php5/cli/conf.d/sqlite.ini,
/etc/php5/cli/conf.d/sqlite3.ini,
/etc/php5/cli/conf.d/xdebug.ini,
/etc/php5/cli/conf.d/xsl.ini
That's from my local dev-machine. However, the second line is the interesting one. If there is nothing mentioned, have a look at the first one. That is the path, where PHP looks for the php.ini file.
You can grep the same information using phpinfo() in a script and call it with a browser. It’s mentioned in the first block of the output. php -i does the same for the command line, but it’s quite uncomfortable.
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.
This works for me:
php -i | grep 'php.ini'
You should see something like:
Loaded Configuration File => /usr/local/lib/php.ini
P.S.
To get only the php.ini path, use:
php -i | grep /.+/php.ini -oE
In a command window, type
php --ini
It will show you the path something like:
Configuration File (php.ini) Path: /usr/local/lib
Loaded Configuration File: /usr/local/lib/php.ini
If the above command does not work then use this:
echo phpinfo();
Use the following command to find the php.ini file path on Linux.
locate php.ini
Output:
/etc/php.ini
/etc/php.ini.rpmnew
/usr/share/doc/php-common-5.4.45/php.ini-development
/usr/share/doc/php-common-5.4.45/php.ini-production
Or try this other way:
php --ini
It shows the path result.
This command should help you to find it
php -r "phpinfo();" | grep php.ini
PHP comes with two native functions to show which configuration file is loaded:
php_ini_loaded_file returns the loaded .ini file
php_ini_scanned_files returns a list of .ini files parsed from the additional ini directory
Depending on your setup, Apache and CLI might use different .ini files. Here are the two solutions:
Apache:
Just add the following in a PHP (.php) file and open it in your browser:
print php_ini_loaded_file();
print_r(php_ini_scanned_files());
CLI:
Copy-paste in your terminal:
php -r 'print php_ini_loaded_file(); print_r(php_ini_scanned_files());'
phpinfo();
will tell you its location, or from the command line
php -i
Try one of these solutions
In your terminal, type find / -name "php.ini"
In your terminal, type php -i | grep php.ini. It should show the file path as "Configuration File (php.ini) Path => /etc"
If you can access one of your PHP files, open it in a editor (Notepad) and insert phpinfo(); after <?php on a new line. This will tell you the php.ini location.
You can also talk to PHP in interactive mode. Just type php -a in the terminal and type phpinfo(); after the PHP interpreter initiated.
Run this in the command line:
php -r "echo php_ini_loaded_file().PHP_EOL;"
find / -name php.ini
Hey... it worked for me!
You can get more information about your configuration files using something like:
$ -> php -i | ack config # Use fgrep -i if you don't have ack
Configure Command => './configure' ...
Loaded Configuration File => /path/to/php.ini
For SAPI: php-fpm
There isn't any need to create a php.info file (it is not a good policy to leave it for the world to read anyway). On the command line:
php-fpm -i | more
Somewhere in its output, it will show this line:
Configuration File (php.ini) Path => /etc
Here is a more complete explanation:
How to Figure out Your PHP Configuration Parameters without info.php
according to this answer, as of PHP 7 the regular php.ini file was removed and added with php.ini-production and php.ini-devlopment.
so instead of php.ini which does not exist in my case (I've installed php 8.1), use php.ini-production and it's located in php installation folder (something like: C:\PHP-8.1.5) and create a file and name it php.ini and then copy contents of php.ini-production in this new php.ini.

PDOException “could not find driver” when run in command mode [duplicate]

A few years ago I installed Apache 2.2x and PHP 5.3.1 on a Linux server I maintain. I used .tar.gz's and built them as instructed (instead of rpms and what-have-you). And all was fine.
Today I need to install this which seems like a PHP library. I went through all the steps up to make install, and I found ibm_db2.so in $PHP_HOME/lib/extensions/somecomplicatedname/ibm_db2.so.
The great catch is the last step is to configure file php.ini, but there aren't any php.ini files on my system. Horror of horrors. PHP works fine, except of course for this newfangled ibm_db2 thingamajig that I want to use so somebody can use a GUI to tinker with DB2. (I tried a small PHP script which fails and indicates that the ibm_db2 functions are not available.)
I have to deal with PHP once every few years, so please enlighten me at a very basic level about what I could do to enable web-based GUI access to DB2.
On the command line execute:
php --ini
You will get something like:
Configuration File (php.ini) Path: /etc/php5/cli
Loaded Configuration File: /etc/php5/cli/php.ini
Scan for additional .ini files in: /etc/php5/cli/conf.d
Additional .ini files parsed: /etc/php5/cli/conf.d/curl.ini,
/etc/php5/cli/conf.d/pdo.ini,
/etc/php5/cli/conf.d/pdo_sqlite.ini,
/etc/php5/cli/conf.d/sqlite.ini,
/etc/php5/cli/conf.d/sqlite3.ini,
/etc/php5/cli/conf.d/xdebug.ini,
/etc/php5/cli/conf.d/xsl.ini
That's from my local dev-machine. However, the second line is the interesting one. If there is nothing mentioned, have a look at the first one. That is the path, where PHP looks for the php.ini file.
You can grep the same information using phpinfo() in a script and call it with a browser. It’s mentioned in the first block of the output. php -i does the same for the command line, but it’s quite uncomfortable.
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.
This works for me:
php -i | grep 'php.ini'
You should see something like:
Loaded Configuration File => /usr/local/lib/php.ini
P.S.
To get only the php.ini path, use:
php -i | grep /.+/php.ini -oE
In a command window, type
php --ini
It will show you the path something like:
Configuration File (php.ini) Path: /usr/local/lib
Loaded Configuration File: /usr/local/lib/php.ini
If the above command does not work then use this:
echo phpinfo();
Use the following command to find the php.ini file path on Linux.
locate php.ini
Output:
/etc/php.ini
/etc/php.ini.rpmnew
/usr/share/doc/php-common-5.4.45/php.ini-development
/usr/share/doc/php-common-5.4.45/php.ini-production
Or try this other way:
php --ini
It shows the path result.
This command should help you to find it
php -r "phpinfo();" | grep php.ini
PHP comes with two native functions to show which configuration file is loaded:
php_ini_loaded_file returns the loaded .ini file
php_ini_scanned_files returns a list of .ini files parsed from the additional ini directory
Depending on your setup, Apache and CLI might use different .ini files. Here are the two solutions:
Apache:
Just add the following in a PHP (.php) file and open it in your browser:
print php_ini_loaded_file();
print_r(php_ini_scanned_files());
CLI:
Copy-paste in your terminal:
php -r 'print php_ini_loaded_file(); print_r(php_ini_scanned_files());'
phpinfo();
will tell you its location, or from the command line
php -i
Try one of these solutions
In your terminal, type find / -name "php.ini"
In your terminal, type php -i | grep php.ini. It should show the file path as "Configuration File (php.ini) Path => /etc"
If you can access one of your PHP files, open it in a editor (Notepad) and insert phpinfo(); after <?php on a new line. This will tell you the php.ini location.
You can also talk to PHP in interactive mode. Just type php -a in the terminal and type phpinfo(); after the PHP interpreter initiated.
Run this in the command line:
php -r "echo php_ini_loaded_file().PHP_EOL;"
find / -name php.ini
Hey... it worked for me!
You can get more information about your configuration files using something like:
$ -> php -i | ack config # Use fgrep -i if you don't have ack
Configure Command => './configure' ...
Loaded Configuration File => /path/to/php.ini
For SAPI: php-fpm
There isn't any need to create a php.info file (it is not a good policy to leave it for the world to read anyway). On the command line:
php-fpm -i | more
Somewhere in its output, it will show this line:
Configuration File (php.ini) Path => /etc
Here is a more complete explanation:
How to Figure out Your PHP Configuration Parameters without info.php
according to this answer, as of PHP 7 the regular php.ini file was removed and added with php.ini-production and php.ini-devlopment.
so instead of php.ini which does not exist in my case (I've installed php 8.1), use php.ini-production and it's located in php installation folder (something like: C:\PHP-8.1.5) and create a file and name it php.ini and then copy contents of php.ini-production in this new php.ini.

In PHP 7.1 which ini file do I use? [duplicate]

I have found that:
When I type the following on terminal:
php -i | grep php.ini
I get the output:
The Loaded Configuration file is # /etc/php5/cli/php.ini
However, from phpinfo(), I get to see:
The loaded ini file is # /etc/php5/apache2/php.ini
Which one of these is working right now? How is it possible to have two php.ini files ?
Depends on where you are running PHP from. If you run it from command line, it uses the cli/php.ini and apache2/php.ini when run through apache.
You are executing phpinfo() through the browser, hence you get /etc/php5/apache2/php.ini as the answer. Running php -r "phpinfo();" | grep "Loaded Configuration" from the terminal should output the CLI ini. Same function, context changes.
The advantage of this system is obviously to allow different configurations depending on the context. For a simplified example, you might want to have safe_mode on in apache but it's unnecessary in CLI mode.
Your .ini paths are actually quite unusual. Normally, the default .ini is just php.ini and CLI .ini is called php-cli.ini and they reside in the same folder.
I'm no expert on the subject but this should be the basic idea. If anyone has any corrections, I'd be happy to hear them.

Can't set/find detect_unicode to Off

I'm want to start using phpDocumentor and the manual installation keeps throwing an error about me not having set detect_unicode = Off in my php.ini in Terminal.
When I add it to my php.ini it doesn't take and I get the same issue when running the install. Nobody seems to have this problem, and for the life of me I can't figure it out.
https://github.com/phpDocumentor/phpDocumentor2/blob/develop/README.md#installation
What am I missing? (I did restart the MAMP server after the php.ini edit)
Screenshot of the error in terminal...
If you have MAMP/MAMP Pro installed then the problem is that the PHP version available to your terminal will most probably be the system version located in:
/private/etc/
I had the same problem but in my case I didn't have a php.ini file in that directory so the best way to resolve it is to just create a symbolic link to the PHP version currently in use in your MAMP/MAMP Pro installation:
php.ini -> /Applications/MAMP/bin/php/php5.3.14/conf/php.ini
That solves the issue. Just change the php version php5.3.14 to whatever version of PHP you've selected to use in MAMP.
As #moderndegree mentions above, you can then optionally make this available to the terminal in the future by editing your path variable in your bash/zsh/etc:
export PATH="/Applications/MAMP/bin/php/php5.3.14/bin:$PATH"
You must not be editing the right php.ini if it still is enabled. Run php -i | grep ini to find all the ini files that are loaded.
The relevant lines are those two:
Loaded Configuration File => ...
Additional .ini files parsed => ...
The problem is that you are probably hitting a different php install.
Try the following:
which php
If you get anything other than, /Applications/MAMP/bin/..., you need update your environment to point to MAMP's installation.
To do this, you will need to add the following to .bash_profile (please update the path to match your setup):
export PATH="/Applications/MAMP/bin/php/php5.3.6/bin:$PATH"
Reload .bash_profile with the following command:
source .bash_profile
After you do this, you should be pointing to the correct php installation. Try which php again to confirm. Now run php -i | grep ini to confirm that the correct php.ini file is being loaded. As Seldaek stated, the relevant lines are:
Loaded Configuration File => ...
Additional .ini files parsed => ...
As I remember, MAMP uses configuration templates. So you should edit php.ini template. The actual php.ini will be regenerated from the template everytime you restart MAMP.
I faced the same problem for composer-php and i add this line manually into php.ini file. Like this:
sudo /private/etc/php.ini
then add this line "detect_unicode = Off"
detect_unicode = Off
then its work and i installed composer. You can see this
How to disable "detect_unicode" setting from php.ini? (trying to install Composer)
If you can't change your /usr/local/bin/php/php.ini file, remember to keep using '-d detect_unicode=Off' for all your php calls like so:
curl -s https://getcomposer.org/installer | php -d detect_unicode=Off
php -d detect_unicode=Off composer.phar install
If you are able to change your php.ini file, then add the following to the end of your php.ini:
detect_unicode = Off

2 php.ini files

I have found that:
When I type the following on terminal:
php -i | grep php.ini
I get the output:
The Loaded Configuration file is # /etc/php5/cli/php.ini
However, from phpinfo(), I get to see:
The loaded ini file is # /etc/php5/apache2/php.ini
Which one of these is working right now? How is it possible to have two php.ini files ?
Depends on where you are running PHP from. If you run it from command line, it uses the cli/php.ini and apache2/php.ini when run through apache.
You are executing phpinfo() through the browser, hence you get /etc/php5/apache2/php.ini as the answer. Running php -r "phpinfo();" | grep "Loaded Configuration" from the terminal should output the CLI ini. Same function, context changes.
The advantage of this system is obviously to allow different configurations depending on the context. For a simplified example, you might want to have safe_mode on in apache but it's unnecessary in CLI mode.
Your .ini paths are actually quite unusual. Normally, the default .ini is just php.ini and CLI .ini is called php-cli.ini and they reside in the same folder.
I'm no expert on the subject but this should be the basic idea. If anyone has any corrections, I'd be happy to hear them.

Categories