PHP is a popular server side scripting language, helps to build dynamic web page. Mostly developers like PHP to build website because it is simple and easy to deploy. But sometime we get an error 'Composer detected issues in your plateform: Your composer dependencies require a PHP version ">= 8.1.0"', when we deploy our website on server.
This is seen when we work on Laravel or other PHP's framework. It means your composer version is not compatible with your current PHP version.
This issue often occurs when we develop our website in PHP latest version and server PHP version not upgraded. So, either we can upgrade our server PHP version or can install the same PHP version and composer in our local system.
There are two ways to fix this problem:
We will use both the methods one by one, just follow the following steps and read the article till last line for better understanding.
Go to the cpanel and find the 'Software' section, under Software section click on 'Select PHP Version'
A new screen will be opened, select your required PHP version. Come to your project and refresh it.
If you don't want to upgrade your current PHP version and want to run your laravel project on current version, then you have to install or reduce composer version that can work with current PHP version.
Just follow the second method, and I ensure you, the problem will be resolved.
Be careful during changing the configuration. Here is the guide to install PHP in Ubuntu. Same approach can be followed to install in any operating system.
First of all check your PHP version by using command php -v on your terminal.
$ php -v
PHP 7.3.0 (cli) (built: Dec 21 2023 20:19:26) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.27, Copyright (c) Zend Technologies
with Zend OPcache v8.1.27, Copyright (c), by Zend Technologies
In my case, PHP version is '7.3.0' and I have to install PHP 8.1.
Either we can remove our current version or can install PHP 8.1 directly.
Check the list of PHP version installed in your system. Use command sudo update-alternatives --list php
$ sudo update-alternatives --list php
Run the following command to install the specific PHP version in your system.
$ sudo apt-get install php8.1
Now, run the command on your terminal to install all required packages in PHP.
$ sudo apt-get install -y php8.1-cli php8.1-common
php8.1-mysql php8.1-zip php8.1-gd php8.1-mbstring php8.1-curl php8.1-xml php8.1-bcmath
These are the required modules to install:
But, still it is not complete, we need to configure our latest installed PHP8.1. So, to do this follow the step 5.
To configure PHP8.1, run sudo update-alternatives --config php command in terminal.
$ sudo update-alternatives --config php
When you run this command, a list of PHP version will be displayed and you will be asked to choose a PHP version. You just have to enter the serial number of the specific version and press enter.
Your current version display with asterisk '*' sign in the list.
Now you can run the command php -v to check it is configured or not. This process will install the specific version of PHP that you need.