Your Composer dependencies require a PHP version ">= 8.1.0" [duplicate] - php

This question already has answers here:
Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 7.3.0"
(22 answers)
Closed 2 days ago.
I am getting this error with Laravel 9, I have PHP 8.1.7 installed
Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.0".
I can see other have asked the question, bit non of the solutions seem to be working

TIPS
Add this lines in composer.json file:
{
"config": {
"platform-check": false
}
}
Or set the version:
{
"config": {
"platform": {
"php": "7.1.0"
}
}
}
And run composer dump-autoload

I had the same problem and it was because I configured a version of PHP 8.1 on the command-line while I kept the PHP module at 8.0.
So PHP_VERSION_ID gave me 80020, while php -v gave me 8.1.7.
It reminded me to reconfigure the PHP Module to PHP version 8.1:
sudo a2dismod php8.0
sudo a2enmod php8.1
sudo systemctl restart apache2
And then everything worked like intended.
Reference:
phpinfo() and php -v shows different version of PHP

If #eril answer did not help you by disabling old PHP version
sudo a2dismod php8.0
sudo a2enmod php8.1
sudo systemctl restart apache2
also check composer using a correct version of PHP
composer -vvv about 2>&1 | grep "PHP"
if composer about already shows a correct version of PHP,then check to see the real PHP binary path that composer is using by putting PHP_BINARY inside vendor/composer/platform_check.php like this:
if (!(PHP_VERSION_ID >= 80100)) {
$issues[] = 'You are running ' . PHP_VERSION . ' located at: ' . PHP_BINARY;
}
in my case, an old version of php-fpm was enabled.
a2disconf php8.0-fpm
a2enconf php8.1-fpm
sudo systemctl restart apache2

If you install composer globally, just run composer global update. It will solve your problem.

Open your composer.json and check where the 'require' block says 'php'. It has an expression that can put a constraint on the PHP version or version range that is allowed for all of your projects' dependencies.
A good value would be to use the one below. Change it and run composer update afterwards.
"require": {
"php": "^8.0|^8.1",
Contrary to the composer.json which laravel 9 ships with:
"require": {
"php": "^8.0.2",
(see laravel 9 composer.json in the official repository: https://github.com/laravel/framework/blob/9.x/composer.json)

Don't change any thing in your application. In your shard hosting, go to cPanel and find/search Multi PHP Manager. Select your domain or sub domain (whatever you are working with), from dropdown list select PHP 8.1 and apply.
Now find/search PHP Selector and for Current PHP Version select 8.1.
in the same window go to Extensions and enable pdo_mysql.
You are good to go.

Your Composer dependencies require a PHP version ">= 8.1.0"
I had this same issue while I downgraded my php to v7.4 from 8.1. I somehow messed up with php7.4-fpm mod. However, when I again tried to upgrade my php v8.1 composer started to complain about that error.
I simply removed my both php versions that's 7.4 and 8.1 and re-installed only 8.1, which fixed my issue.
To remove, here are the steps I followed....
sudo apt-get purge php8.*
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php8.1
and then finally,
sudo service apache2 restart

If you are simply using git to version your Composer dependencies for a deployment, consider the --ignore-platform-reqs flag.
For more info, see Options at https://getcomposer.org/doc/03-cli.md#install-i
composer update --dry-run --ignore-platform-reqs
--ignore-platform-reqs: ignore all platform requirements (php, hhvm, lib-* and ext-*) and force the installation even if the local machine does not fulfill these. See also the platform config option.

If you are operating on nginx server, It's likely the php-fpm8.1 is not active.
Try to:
sudo systemctl status php-fpm8.1.service
Depends on the status of the php-fpm version, you can act, and if it's stopped, you may want to do the following:
sudo systemctl enable php-fpm8.1.service
sudo systemctl start php-fpm8.1.service
Then double-check the status, and if it's active. You're good to go.
Note: This applies to any php-fpm version, not just 8.1.
Hope this help!

if you use XAMPP, check that the PHP version of your XAMPP is the correct one (the same one you have on your computer). Otherwise, download and install the correct version of XAMPP

Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.0".
I faced the same problem.
Just go to Cpanel.
Then PHP Selector
and finally, change PHP version

If you are in the process of upgrading Laravel versions and you switch to the version which requires PHP8 (8 or 9 cant remember)
And you also switch PHP versions,
you need to restart your
php artisan serve

in my case everything is fine
composer.json is fine
php 8.1 is installed
I am using nginx I restart nginx but I found that my configuration is wrong it looks like this
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
}
so the correct configuration is
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}
Hope this will help someone

I had the exact issue.
I added the line phpversion() and found that the version was different from what was set for my apache.
I enabled the php8.1-fpm with this command:
sudo a2enconf php8.1-fpm
After restarting Apache I got it working.

It's just until I find how to solve it but it's working
So that's what i've done :
download php 8.1.9 (nts)
extract it in bin/php/ (i use Laragon)
move php 7.14.19 in a new folder(just for preventing)
and rename my php 8 folder to php 7 folder name
it's still working
Just find the php folder of your server

Related

update php and php-fpm in nginx server

I have a requirement where I need to update the PHP and PHP-fpm to the latest version of the server. this server is hosted using Nginx and WordPress. We are using amazon Linux 2 when I disable php7.4 and enable php8 in amazon-Linux-extras and install I'm getting an error.
php error
I have a couple of questions:
what happens when I uninstall and install PHP to the latest version does it after the site?
Do we have any workaround for this PHP error?
Thanks in advance.
I'm expecting a solution to update my PHP to the latest version without any issues. I have just started learning DevOps. I'm not familiar with these errors
I removed php-json by sudo yum remove php-json and installed of php
sudo yum install php php-{pear,cgi,common,curl,mbstring,gd,mysqlnd,gettext,bcmath,json,xml,fpm,intl,zip}
Still the application works.
php-json is available in Amazon Linux Extra topic "php7.4"
$ sudo amazon-linux-extras install php7.4

Illuminate\Database\QueryException could not find driver Laravel

I deploy a laravel project on an apache server on a Debian 10 machine.
The database is an MySQL deployed on another debian 10 machine on the same network.
I can go to the connection interface of the application but when I connect this error appears :
Illuminate\Database\QueryException
could not find driver (SQL: select * from `users` where `email` = test#gmail.com limit 1)
I have already tried these commands :
php artisan migrate
sudo apt install php-mysql
sudo apt install php7.4-mysql
sudo systemctl restart apache2
composer require doctrine/dbal
composer update
these commands work but do not solve the problem.
and I already tried to comment and uncomment this line in the php.ini :
extension=pdo_mysql
in php-m i have
PDO and pdo-mysql
and i have restart my server with :
systemctl restart apache2
after modification
I got the same error when running my test suite. It was working before but it stopped working after I upgraded php. So I did and it worked for me.
sudo apt-get install php-sqlite3
If you have no problem using php artisan migrate, there is no problem for the command line to call the php script. If you use fpm and install a new extension, you need to restart it and try.
I finally found the solution
infact the php version used by apache was 7.3 and not 7.4 with :
<?php phpinfo() ?>
however when I did:
php --version
the version was indeed 7.4.
I followed this tutorial to change the version
https://tecadmin.net/switch-between-multiple-php-version-on-debian/?amp
and it works

Nginx SOAP extension is installed for PHP 7.0 but not 7.4

I have an Ubuntu 16.04.6 machine and need the SOAP extension enabled for PHP 7.4, but right now it's only installed for 7.0 The extension itself is present in path /usr/lib/php/20151012/soap.so
I've used apt-get remove php-soap and the apt-get install php-soap but it does not get installed anywhere except the 7.0 folder. I have noticed in the 7.0 folder there are certain files and symlinks, which I have duplicated into the 7.4 folder structure. /etc/php/7.4/mods-available now contains soap.ini and a symlink to it named 20-soap.ini was placed in folder /etc/php/7.4/fpm/conf.d This is in keeping with all the other extensions, which were all installed almost exactly a year ago when I upgraded PHP.
In the php.ini file I have uncommented extension=soap.so and I have tried changing that line to extension=/usr/lib/php/20151012/soap.so
service php7.4-fpm restart
service nginx restart
All this to no avail. Can someone slap me upside the head and tell me what I'm missing? Should I try deleting previous PHP versions, then reinstalling the soap extension? I've seen threads mentioning specific packages for 7.4 such as php7.4-soap but this is not found in my repositories.
Any help is appreciated!
Try this command apt install php7.4-soap
sudo add-apt-repository ppa:jczaplicki/xenial-php74-temp
sudo apt-get update
sudo apt install php7.4-soap
This is adding an external PPA repository to your system. If you do not trust the maintainer you should not do this, since it possibly exposes your system. Also note that this might work for installing php, but there will not be a guarantee that you recvive updates through it (The word "temp" in the repository name indicates that this is only temporary). I would rather recommend compiling it yourself if you really need to have it installed on 16.04.
Also this will install you php version 7.4.13 , you may have to remove the already installed php 7.4 , and reinstall after you add this ppa

PHP: Cleanly upgrading/replacing PHP from unavailable repository on Ubuntu 12.04

I am running an Ubuntu 12.04 Apache2/PHP/MYSQL server that was using a deprecated version of PHP. I realized this once I tried to install the sqlite3 extension I get an error:
Failed to fetch http://ppa.launchpad.net/ondrej/php5-5.6/ubuntu/dists/precise/main/source/Sources
Research shows me that this is no longer used and instead use ondrej/php instead. This is a production server and I need to figure out steps to replace the PPA with the correct one.
Will I need to uninstall PHP and reinstall using the new packages? If so how should I go about doing this cleanly?
Is there a way to temporarily install sqlite3 without having to change repositories completely (I do not have php-dev installed at the moment either).
First you should check if there are any compatibility issues with the version you want to upgrade to (did a quick google to find this: https://github.com/squizlabs/PHP_CodeSniffer). Then, add the repository that contains the version you want, sudo apt-get update and install the version of php you want. To switch the version apache uses, do the following:
sudo a2dismod php5
sudo a2enmod php5.6
sudo service apache2 restart

php artisan migrate throwing [PDO Exception] Could not find driver - Using Laravel

I have a bad experience while installing laravel. However, I was able to do so and move to the next level. I used generators and created my migrations.
But when I type the last command
php artisan migrate
It's throwing a PDOException - could not find driver.
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
'database' => 'database',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
That's my configuration in config/database.php.
I tried searching on stackoverflow and laravel forums and people suggest that it's PDO problem and not artisan's or php's - I followed those suggestions like adding
extension=pgsql.so
extension=pdo_pgsql.so
in php.ini
No positive result. It always says [PDOException]could not find driver.
Can someone please help resolving this.
Environment that I am using: Mac, laravel 4, MAMP PRO with php 5.4.4
You can use
sudo apt-get install php7-mysql
or
sudo apt-get install php5-mysql
or
sudo apt-get install php-mysql
This worked for me.
You need to specifically enable the pdo_mysql plugin. Assuming you're using a standard PHP installation, then generally you would simply need to add this to your PHP.ini file:
extension=pdo_mysql.so
You need to ensure that this file exists in the extension directory though.
Adding pdo_pgsql.so doesn't help because that is for PostgreSQL.
Additionally, you should ensure that you restart the web-server after you make the changes to the PHP ini file, as the changes may not be reflected otherwise.
This worked for me:
sudo apt-get install php5-sqlite
This installed sqlite for php5, then I ran the php artisan migrate command again and worked perfectly.
Ran into the same issue here, and turns out this is because PHP at the command line uses a different php.ini file from the browser version, which is why it looks like it's loading the extension correctly when you look at phpinfo() in a browser.
As per this answer, you just need to run:
php --ini
At the command line, which will tell you the path to the currently loaded php.ini (probably actually a php-cli.ini file located in the same place as your regular php.ini file).
Once you've found that, modify it with the pdo extensions you want (in this case for MySQL):
extension=pdo_mysql.so
Or, for any other users that are on Windows using some kind of WAMP server, it probably looks like this instead:
extension=php_pdo_mysql.dll
I think you missed the mysql driver for php5.
Execute below command:
sudo apt-get install php5-mysql
/etc/init.d/php5-fpm restart
You must be installing the latest version of php mysql
in my case I am install php7.1-mysql
Try this
sudo apt-get install php7.1-mysql
I am using the latest version of laravel
You are missing a PDO driver.
First install the driver
For ubuntu: For mysql database.
sudo apt-get install php5.6-mysql/php7.2-mysql
You also can search for other database systems.
You also can search for the driver:
sudo apt-cache search drivername
Then Run the cmd php artisan migrate
Please check your Laravel .env file also. Make sure DB_CONNECTION=mysql, otherwise it won't work with MySQL. It tried to load something else.
I got this error for the PostgreSQL and the solution is:
sudo apt-get install php7.1-pgsql
You only need to use your installed PHP version, mine is 7.1.
This has fixed the issue for PostgreSQL.
Had the same issue and just figured, website is running under MAMP's php, but when you call in command, it runs mac's(if no bash path modified). you will have issue when mac doesn't have those extensions.
run php -i to find out loaded extensions, and install those one you missed. or run '/Applications/MAMP/bin/php/php5.3.6/bin/php artisan {your command}' to use MAMP's
I was also getting the same error --> "[PDOException]
could not find driver "
After that I used many commands but not didn't get any help
Finally I used the following command, which solved my problem.
sudo apt-get install php5-sqlite
Laravel Testing with sqlite needs php pdo sqlite drivers
For Ubuntu 14.04
sudo apt-get install php5-sqlite
sudo service apache2 restart
In ubuntu 16.04 there is no php5-sqlite
sudo apt-get install php7.0-sqlite
sudo service apache2 restart
This worked with me:(for pgsql: use 'pgsql' instead of 'mysql')
Step 1)
sudo apt-get install php-mysql
Step 2)
php artisan config:clear
Step 3)
php artisan config:cache
Step 4)
Then restart your server, and generate key again and migrate it, Its Done
I'm unsing ubuntu 14.04
Below command solved this problem for me.
sudo apt-get install php-mysql
In my case, after updating my php version from 5.5.9 to 7.0.8 i received this error including two other errors.
errors:
laravel/framework v5.2.14 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
phpunit/phpunit 4.8.22 requires ext-dom * -> the requested PHP extension dom is missing from your system.
[PDOException]
could not find driver
Solutions:
I installed this packages and my problems are gone.
sudo apt-get install php-mbstring
sudo apt-get install php-xml
sudo apt-get install php-mysql
I had this problem on debian. The issue was, I was using the dotdeb repository for more recent PHP packages. For some reason, it updated the php cli to 7.0, while the web php binary remained php 5.6. I used this answer to link the php command line binary to the 5.6 version, like so:
$ sudo ln -sfn /usr/bin/php5 /etc/alternatives/php
first check your php version like this :
php -v
after you get version number for example i get 7.1 then install like that
sudo apt-get install php7.1-sqlite //for laravel testing with sqlite
sudo apt-get install php-mysql //for default mysql
sudo apt-get install php7.1-mysql //for version based mysql
sudo apt-get install php7.1-common //for other necessary package for php
and need to restart apache2
sudo service apache2 restart
For future searchers.
On FreeBSD try the next
pkg_info | grep php5-pdo_mysql
if you see the empty line in return do the following:
cd /usr/ports/databases/php5-pdo_mysql
and the do the install
make install clean
then simply restart your apache and you are done
e.g. sudo /usr/local/etc/rc.d/apache22 restart
Install it via this command
sudo apt-get install php5-gd
this worked for me.
In my case I wasn't aware that the PHP run by Apache was different from the one run by CLI. That might be the case if during configuration in httpd.conf you specified a PHP module, not being the default one your CLI uses.
I found the proper solution for this error! Either you don't have any database installed or your default database in this file
config/database.php
is set to some other database like this
'default' => 'sqlite',
'default' => env('DB_CONNECTION', 'sqlite'), //laravel 5.2
change the default to which one you have installed or install that database which is made to be default! I had installed mysql and php artisan migrate worked after i changed that line to this:
'default' => 'mysql',
'default' => env('DB_CONNECTION', 'mysql'), //laravel5.2
I was also getting the same error --> "[PDOException]
could not find driver "
I realized that the php was pointing to /usr/bin/php instead of the lampp /opt/lampp/bin/php so i simply created
and alias
alias php="/opt/lampp/bin/php"
also had to make update to the .env file to ensure the database access credentials were updated.
And guess what, it Worked!
If you are using Laravel 5.x, and the error is from trying to modify the attributes of a column, it is possible the error comes from a missing pre-requisite.
Try this:
composer require doctrine/dbal
Then try running your migrations.
From here:
https://laravel.com/docs/master/migrations#modifying-columns
If you are using arch based system like in manjaro
just use
sudo pacman -S php-sqlite
Restart your httpd
systemctl restart httpd
for those users of windows 10 and WAMP that found this post, i have a solution.Please go visit this link. It worked for me and it was difficult to come to the solution but i hope it might be of help for others in the future.
Assuming you did the normal installation with virtual box, vagrant etc..
This can happen to new people.
PHP can be installed on your PC but all the modules PHP for your laravel project is on your VM
So to access your VM, go to your homestead folder and type:
vagrant ssh
then to go your project path and execute the php artisan migrate.
It's an issue with MAC and MAMP.
Try to add in your .env file this:
DB_SOCKET= /Applications/MAMP/tmp/mysql/mysql.sock
It work for me
This expands on Sven P's answer:
I was baffled by this error message myself when upgrading to a new DigitalOcean Droplet running Ubuntu 20.04 and Laravel 8.x. One thing to keep in mind is that you are running php artisan migrate on the command line and that might be different from the version of PHP you're running on Apache server. My Laravel test apps were working smoothly, but I couldn't run Postgresql related commands from the command line. Then I remembered that the default version of PHP for Ubuntu 20.04 was 8.x and I had configured my Apache server to run PHP 7.4. This tutorial was my salvation: How To Switch PHP Version on Ubuntu 20.04 LTS. Check your PHP version. Sure enough, my CLI PHP was version 8.x so it didn't have the Postgresql driver installed and enabled. Following the tutorial, I ran
sudo update-alternatives --config php
and selected my PHP 7.4 installation and now when I log in to my SSH client and check the PHP version, it displays 7.4, where I have installed and enabled Postgresql. So now my php artisan migrate command runs smoothly and I can get back to work.
This tip is relevant to any database connection you're using. For instance, if you normally used MySQL for your Apache apps, you would have the same error if your CLI PHP version was different and didn't have MySQL installed and enabled.

Categories