skip to Main Content

I want to change the PHP version because my version is 7.1.23 and I need to upgrade to 7.2 for install a package that I want to use.

I’m using MAMP on Macbook Pro.
Here’s what I’ve done :

I’ve add this line in this .bash_profile file :

export PATH=/Applications/MAMP/bin/php/php7.2.14/bin:$PATH

In the composer.json file I’ve update the version to

"require": {
        "php": "^7.2.14"

I’ve create a .php-version in the project directory. It contains :

7.2

If I do "php -v" in my terminal I’ve that :

~ php -v
PHP 7.2.14 (cli) (built: Feb  1 2019 12:25:00) ( NTS )

When I launch my project with "symfony serve", that give me :

The Web server is using PHP CGI 7.2.14                                                                            
      https://127.0.0.1:8000  

But when I want to make "composer update" or "symfony local:php:list" it return me that I’m still using PHP version (7.1.23).

How can I finally upgrade the version ?

Here’s a screen from my terminal :

enter image description here

2

Answers


  1. okay, so as far as I can tell, your symfony command already uses 7.2.14 (highlighted version in first column, ignore the * in the last column, it only tells what is the system’s default), since it says so on symfony serve.

    composer however doesn’t, which is most likely due to the fact that composer is a php script that is made executable via a hash bang at the very first line of the file (and the x chmod):

    #!/usr/bin/php
    

    which essentially says, "run me with the interpreter/command /usr/bin/php". There are other variants of composer around, some have #!/usr/bin/env php which will look for a php in the PATH variable and use that instead.

    However, to fix this, I propose these reasonable options

    • run composer with an explicit php (check composer path with which composer):

        php /usr/bin/composer update
      

      which obviously is a bit inconvenient, or

    • just install another composer, which is most likely more recent anyway and add it to your PATH before /usr/bin like you did with your alternative php version, which will allow you to run it standalone/independent, or

    • use the symfony script to run composer:

      symfony composer update
      

      disclaimer. I haven’t actually tried this, but I would be surprised if this didn’t run composer with the correct php version…

    Login or Signup to reply.
  2. I had the same problem and I solved it by creating a file ".php-version" that contains the php version number (ex : 8.1.2) in the project directory

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search