Changing the default PHP Command Path - php

I'm running Ubuntu Natty.
I recently installed PHP 5.3.8 from Source and it works ok. However, as part of my installation, I had to install php5-dev so I guess this has installed another PHP on the server (I needed to do this for phpize).
My main PHP binary is at /usr/local/php/bin. However, when I run php from the command line with something like this php --ini I get the following:
$ php --ini
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/pdo.ini
I can still run PHP from /usr/local/php/bin, but that would mean me having to type the whole path out for all my command line scripts.
Is there a way I can change this behaviour so that when I use the php command, it points to the php binary inside /usr/local/php/bin instead?!
Thanks in advance

You can edit your .bash_profile file to change your default search path. Or update it using PATH=/usr/local/php/bin:$PATH or somesuch.

The below code worked for the specific circumstance in my earlier question:
printf "\nexport PATH=/usr/local/php/bin:\${PATH}\n" >> /etc/profile
source /etc/profile
Hope it helps.

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.

Laravel - could not find driver when migrating

Hello I'm using latest version of Laravel, PHP 7.1.9 and MySQL 5.7.19. I'm also using WAMP stack.
When I run the command:
php artisan migrate
I get the following error:
I googled a lot and I' m 100% sure my php.ini file does not have the driver line commented out and the driver is properly working, as seen here:
The driver is obviously present:
Also the path to extension dir is absolute:
extension_dir ="c:/wamp64/bin/php/php7.1.9/ext/"
What else can I do? This thing is driving me crazy
There are 2 php.ini files in the WAMPServer implementation.
One for APACHE which is the one accessed from the menu system and one in each wamp\bin\php\phpx.y.z folder
As you are using the PHP CLI you have to check that all the required extensions are also activated in PHP you are using for the CLI wamp\bin\php\phpx.y.z
Do this from the command line
php --ini
It should show you something like this
Configuration File (php.ini) Path: C:\WINDOWS
Loaded Configuration File: C:\wamp64\bin\php\php7.0.29\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
Look at this param Loaded Configuration File: to see which php.ini file you should be checking.
This post may also be useful to you for making a batch file to run from the command prompt to switch easily from one version of PHP CLI to another from the command window How To Run PHP From Windows Command Line in WAMPServer

How do I get PHP command line to use a php.ini file when it is not using one?

This is for a Mac OS X. I need to put a line in the php.ini file for PHP 5.6 - however, I have found out from this:
php -r "php_ini_loaded_file();"
That PHP is not using an ini file!
OK, so that was a surprise... How do I either tell PHP to use an ini file, or add the line I would have added in that ini file?
Using php --ini gives me the same thing:
Configuration File (php.ini) Path: /etc
Loaded Configuration File: (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
The following worked for me. I typed
php --ini
which also told me that there was no config file, but it DID tell me the default directory was /etc.
So I did a sudo nano /etc/php.ini
and added a comment (starting with a ;) and did php --ini again - and it showed the file was present! Just to be sure, I added some illegal characters, and went back to php --ini which told me there was a parse error.
So it appears you can always add a php.ini file - even if it starts out blank.
You can find the command-line switches in the manual or with the help switch:
php -h
I believe you want one of these:
-c <path>|<file> Look for php.ini file in this directory
-d foo[=bar] Define INI entry foo with value 'bar'
Otherwise, PHP will search for the php.ini file according to the documented rules. I understand that CLI interface makes use of the PHPRC environment variable if it exists.

Where can I find php.ini?

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.

Categories