composer always detect wrong version of my local php - php

Whenever I try to test PHPUnit or composer update, I get this error:
PHP Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 7.4.0". You are running 7.3.19
but when I put on the terminal: source ~/.bash_profile it reads that I have 7.4 on my local machine and all works OK. Is there any solution for that issue, to not need to put every time that command source ~/.bash_profile before every start of the console?
Before run source ~/.bash_profile:
PHP 7.3.19 (cli) (built: Jun 12 2020 00:29:59) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.19, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.19, Copyright (c) 1999-2018, by Zend Technologies
After run source ~/.bash_profile:
PHP 7.4.13 (cli) (built: Nov 30 2020 14:57:43) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.13, Copyright (c), by Zend Technologies

I was facing the same issue, I was using command prompt for laravel artisan commands. Which was showing wrong php version. I closed it and from Xampp Control Pannel Open the Shell for artisan commands and now its detecting the correct PHP Version. It fixed my problem.

Related

Change CLI PHP version on Mac

I using Mac BigSur lastest update.
I have install Bitnami MAPP with PHP version 8.0.8.
But in CLI still PHP 7.3.24
I try create PATH to Bitnami PHP8.0.8 but have warning like below
WARNING: PHP is not recommended
PHP is included in macOS for compatibility with legacy software.
Future versions of macOS will not include PHP.
PHP 7.3.24-(to be removed in future macOS) (cli) (built: Dec 21 2020 21:33:25) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.24, Copyright (c) 1998-2018 Zend Technologies
How to switch PHP CLI to PHP8.0.8 of Bitnami?
Bitnami engineer here!
The output you are seeing is produced by the PHP binary that comes preinstalled in macOS. When you install Bitnami MAMP, a standalone, updated version of PHP will also be installed in your system. In order to use it instead of the default one, you have two options:
Use the full path to the binary (installdir/php/bin/php)
$ /Applications/mampstack-8.0.9-0/php/bin/php --version
PHP 8.0.9 (cli) (built: Jul 30 2021 07:59:45) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.9, Copyright (c) Zend Technologies
with Zend OPcache v8.0.9, Copyright (c), by Zend Technologies
Add the directory containing the PHP binary to your path
$ export PATH=/Applications/mampstack-8.0.9-0/php/bin:$PATH
$php --version
PHP 8.0.9 (cli) (built: Jul 30 2021 07:59:45) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.9, Copyright (c) Zend Technologies
with Zend OPcache v8.0.9, Copyright (c), by Zend Technologies
For the examples above, /Applications/mampstack-8.0.9-0 was the installation directory (installdir) of the stack.

PhpStorm: Run PHP server doesn't work: could not find driver

I am using PhpStorm for a year and now I want to run my PHP server using the PHP Run menu:
I run the server pushing the green arrow button. Then the console show:
/home/john/.cache/JetBrains/PhpStorm2020.1/plugins/idea-php-latest-plugin/php-v7.3.1/php.sh -S localhost:8080 -t /home/john/my-nice-project/backend/web
Then I go to localhost:8080 in my browser and I see this error:
I execute php -v in my terminal and I can see this:
PHP 7.2.34-18+0~20210223.60+debian10~1.gbpb21322 (cli) (built: Feb 23 2021 16:47:51) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.34-18+0~20210223.60+debian10~1.gbpb21322, Copyright (c) 1999-2018, by Zend Technologies
So maybe the problem is the version of the PHP interpreter: I have 7.2.34 and PhpStorm has php-v7.3.1 configure.
Is there any way to configure the version?
But if I execute this command, it works fine:
php yii serve --docroot="backend/web/"
Add this to your php.ini file:
extension=pdo.so
https://www.php.net/manual/en/pdo.installation.php

How use different versions of PHP in command line

I'm facing an issue. I've multiple projects thats using different version of PHP. I world like to have a way to define for example:
sites/project1 -> php 5.6
sites/project2 -> php 7.0
sites/project3 ->
php 7.1
I'm currently using MAMP PRO to manage web-server but my issue is regarding to command line.
I don't want to use docker or vagrant for each project just configure a specific binary php per project folder.
Is there a way to do that?
Best!
You can use phpbrew, it's very simple and convenient when you want to switch between PHP versions as well as for PHP extension management.
For changing the PHP CLI version you just run one command:
$ phpbrew list
* php-7.1.12
php-5.5.15
$ php -v
PHP 7.1.12 (cli) (built: Jan 14 2018 22:25:40) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.12, Copyright (c) 1999-2017, by Zend Technologies
$ phpbrew use php-5.5.15
$ php -v
PHP 5.5.15 (cli) (built: Nov 9 2018 00:22:21)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
If you use MAMP your php bin files are located under:
/Applications/MAMP/bin/php/php*.*.*/bin/php
I can recommend to create alias/symbolic link for each PHP version
/Applications/MAMP/bin/php/php7.1.12/bin/php => php7.1
/Applications/MAMP/bin/php/php5.6/bin/php => php5.6
etc..

ln: /usr/bin/php: Operation not permitted OSX 10.11

I use PHPStorm on OSX with PHPUnit and Laravel.
When I go inside my project from the PHPStorm console and type:
$ php --version
PHP 5.5.29 (cli) (built: Sep 9 2015 00:26:40)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
$ which php
/usr/bin/php
From my terminal:
$ php --version
PHP 5.6.16 (cli) (built: Nov 27 2015 21:37:15)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans
$ which php
/usr/local/php5/bin/php
The above I installed. I have edited my PATH to use it.
Now I want to change the PHP version inside my PHPStorm.
I tried editing composer.json:
"require": {
"php": ">=5.6.16",
and then running update:
$ composer update
Your requirements could not be resolved to an installable set of packages.
Problem 1
- This package requires php >=5.6.16 but your PHP version (5.5.29) does not satisfy that requirement.
I also tried to create a symbolic link .
$ sudo ln -s /usr/local/php5/bin/php /usr/bin/php
It fails with:
ln: /usr/bin/php: Operation not permitted
I am not sure what to do. I would like to update Php to 5.6.16.
It appears you have at least two versions of Php installed.
Try changing the interpreter path within PhpStorm.
File->settings->languages & frameworks->interpreter ...

How to update PHP CLI OSX?

I just updated to php 5.4 using http://php-osx.liip.ch/ on osx lion.
when i type:
php -v
i still see:
PHP 5.3.15 with Suhosin-Patch (cli) (built: Jul 31 2012 14:49:18)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
But phpinfo() shows 5.4.
How do i update this?
Just Export installed PHP path ,type this on Terminal
export PATH=/usr/local/php5/bin:$PATH
I checked that /usr/local/php5/bin/php existed. It did, so I added /usr/local/php5/bin to my PATH.
Thank you #AD7six
The answer shared by both Chutipong Roobklom and user1168427 helped, if you want to update to the latest php cli which is 7.2.7 (most current and stable release as of 2018 when this post was created originally so check the latest php version, methods for switching versions may vary) then just use this instead of the php5 command. export PATH=/usr/local/php7/bin:$PATH then type php -v and you should have something that reads like this(on MACOSX by the way):
PHP 7.2.7 (cli) (built: Jun 22 2018 06:27:50) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.7, Copyright (c) 1999-2018, by Zend Technologies
so you shouldn't be getting any errors. Hope this helps and for Kamel, that is how it is installed. You're kind of 'exposing' it in a way for your machine to now recognize which php version you are using.

Categories