Using a different PHP version to compile Magento project
-
09-10-2020 - |
Question
I have a site running Magento-CE-2.1.5 in a ubuntu server.
I have 2 PHP versions running alongside:
- PHP 7.0.18
- PHP 7.1.6.
Each time i try to setup Magento it shows PHP version 7.0.18 but the real problem is that I need to make few changes and compile the projects.
At the time of compiling, the Magento PHP command uses PHP version 7.1.6. How can i make the project use PHP version 7.0.18 during compilation?
I have PHP 7.1.6 version as it was required by a Laravel site running PHP 7.1.6.
Solution
Depending upon how you installed the different PHP versions (e.g. using ondrej's PPA to install 5.6/7.0/7.1 or compiling from source) you should have two separate "php" executables under /usr/bin
or /usr/local/bin
. I use the PPA and it provides the following executables for me:
/usr/bin/php5.6
/usr/bin/php7.0
/usr/bin/php7.1
To run the bin/magento
command using a specific version of PHP, just call that specific version of the executable followed by bin/magento <command>
. For example:
php5.6 bin/magento setup:di:compile
php7.0 bin/magento setup:di:compile
Also if you're using the PPA and providing multiple versions of one package, you could look to see if /usr/bin/php
links to /etc/alternatives/php
. If so, then you can do sudo update-alternatives --config php
and select which one /usr/bin/php
will use, thus allowing you to just use php
to be running whichever you choose (on the command-line).
OTHER TIPS
You can modify the path variable to match to version of php that you want to run.
php -v
set PATH="/usr/bin/php7.0:$PATH"
php -v
Note that I assume you php7.0 is under /usr/bin/php7.0
but that can easily be changed base on where your system stores it's files.
Also on some systems you will be able to find php
, php7.0
and php7.1
commands on the CLI