I am working on the codespace on some PHP-based code. when I am running this command:
php --ini
Configuration File (php.ini) Path: /opt/php/8.2.4/ini
Loaded Configuration File: /opt/php/8.2.4/ini/php.ini
Scan for additional .ini files in: /opt/php/8.2.4/ini/conf.d
Additional .ini files parsed: (none)
So I install PHP v7.4 by using this command:
sudo apt install php7.4-common
and when I am trying to update-alternatives --config php
it says:
There is only one alternative in link group php (providing /usr/bin/php): /usr/bin/php7.4 Nothing to configure.
but my code has some dependencies on php7.4 and still I cannot run my code completly.7
the php --ini
command also returns the same result.
the php --version
returns PHP 8.2.4
Seems that said php8 is installed outside package manager for some reasons? But regardless of that you may still invoke any binary you want by providing full path to it, so instead of doing
$ composer install
you can just do
$ /usr/bin/php7.4 composer install
which will run composer using 7.4. If you want to dig deeper, you need to check your $PATH
as it can have /opt/php
prioritized.
EDIT: as composer
is now argument to PHP, it will no longer be automatically located by the shell, so you need to provide full path to composer
if it's not in your current directory. You can get it with i.e. which composer
or you can make you shell invocation like this (assuming it's bash):
$ /usr/bin/php7.4 "$(which composer)" install
which (assuming composer is in your $PATH
) should solve the problem.
Alternatively, if there's a possibility, you can check if you can use dedicated image with PHP7.4 - that'd be much cleaner approach.