Search code examples
phphomebrewvisual-studio-codemampmacos-sierra

How to check php version in MacOS sierra?


I have mac os sierra machine. When I start a php project in vs code, I get the following warning

language server needs php 7, and the version found is 5.6.27.

So I used homebrew to upgrade to version 7 and confirmed it from the terminal. I am also running mamp which show version 7. But in the terminal of vs code the php version is still 5.6.27. So I am bit confused?

enter image description here

I changed the value of php.validate.executablepath in settings.json in vs code from usr/bin/php to usr/local/bin/php, but still vs code terminal showing the older version (viz. 5.6.27)

enter image description here


Solution

  • This is because VM Code still checking /usr/bin/php directory which is php5

    You have to configure the path to the PHP executable in the user settings file. Follow the following steps to change it

    1. Go to File > Preferences > User Settings > Settings.json
    2. Change the value of php.validate.executablePath according to the installed directory of php7.

      "php.validate.executablePath": "/Applications/MAMP/bin/php/php7.0.14/bin/php"

    3. Relaunch VM Code

    Setting.json

    1. If the problem remains same, then add the path to PHP7 to your environment variables, run where php and php --version to verify. To add path in your macos sierra do the following:

      • Within the Terminal, run vim ~/.bash_profile
      • Type i and then paste the following at the top of the file:

        export PATH=/user/local/bin:$PATH
        
      • Hit ESC, Type :wq, and hit Enter.

      • In Terminal run source ~/.bash_profile
      • In Terminal, type in which php again and look for the updated string.
      • If everything went successful, it should output the new path to MAMP PHP install.
      • In case it doesn't output the correct path, try closing the terminal window (exit fully) and open again, it should apply the changes (Restart in short)