When you use "php" in the command line to execute some commands or script, system will point to a default version of the php, it could be any one of the php version you installed in the system. For example it could be php 7.1 or php 8.1, it depends on your installation and configuration.

But to execute few commands, for example, to clean up the cache in your laravel 9 project you might use  php artisan cache:clear  command, but since the required php version for laravel 9 project is php 8.1. If your command line "php" points to some other version, say version 7.1 then you might experience issues.

In such cases, we have to make our command line "php" to point to php version 8.1. You can still directly use actual php version like  /usr/bin/php8.1 artisan cache:clear  but it is cumbersome to use this way all the time. Instead we can make our command line version of php point to actual required version using the following command:

sudo update-alternatives --config php

It will ask you the password and list you number of php versions available in the system. Each php version is allocated with number in the "selection" column and current default php version highlighted with  near by the number. You can type in the number related to our required php version. In our case, it is 5.

Once you type in the required selection number and press enter, selected version will be made as default php version when you use "php" in the command line. See below image as an example:

Comments (0)
Leave a Comment

loader Posting your comment...