how does php composer know the php version?
Asked Answered
U

2

7

Having successfully upgraded my test site (Debian Linux) to Zend Framework 3, I want to repeat the exercise on OS X El Capitan running Server 5.1.5. Originally this had PHP 5.5.x installed but I've upgraded to PHP 5.6.x and verified this with a phpinfo() display. However, when I try to run composer to install Zend Framework 3 modules, it responds that it can't be done as PHP 5.5.x is installed. Restarting etc. makes no difference. How does composer tell which PHP version is in use and how can I convince it that PHP 5.6.x is installed?

Unblock answered 19/7, 2016 at 12:27 Comment(5)
Did you check your environment variables? Perhaps you have two versions of php installed.Cheek
did you install your php with brew ?Coenesthesia
I would imagine that composer uses the version of PHP which shows up under which php. Did you run phpinfo() in a web-server or in a cli script? It may be that your web server is pointing to the 5.6.x version, but the cli path still points to the 5.5.x version.Torytoryism
OS X comes with Apache and PHP. However when the Server app is installed it brings its own versions of Apache and PHP. Its the Server version that I've updated. I then ran phpinfo() in a browser.Unblock
Solved. I just had to add a ~/.bash_profile with a PATH definition putting the location of the new PHP before the generic $PATH.Unblock
M
1

When i understand correctly, then your server is already PHP 5.6 and should be able to run ZF3, but the CLI is PHP 5.5 and Composer stops fetching the ZF3 modules, because the PHP is too low, right?

You have one PHP for the CLI and another PHP for the server. When you run composer it will check the PHP version of the currently running PHP used from the CLI.

Two solutions come to my mind:

  • update your PHP used on the CLI or
  • append --ignore-platform-reqs to your composer command. This will ignore the env checks and pretend everything is ok. Keep in mind that this will also disable checks for extensions, which might be needed by some of the modules.
Mechanotherapy answered 20/7, 2016 at 9:32 Comment(0)
M
1

For others who don´t know how to change the PHP version for Composer when using WAMP on Windows:

Composer uses the PHP version which can be run from the terminal. So on Windows the Composer (and so the terminal) knows the PHP version from the systems Path variable.

You can easily change the value inside System -> Advanced system settings -> environment variables. Inside the Path variable should be a value like C:\wamp64\bin\php\php5.6.25. After changing the value a restart is necessary.

You can always find out the currents system PHP version by running php -v inside the terminal.

Meri answered 17/4, 2017 at 17:9 Comment(1)
+1 for this; probably holds true for any local dev setup (I'm on XAMPP, personally). Well-explained; this solved it for me!Mishnah

© 2022 - 2024 — McMap. All rights reserved.