When I run laravel command in terminal php artisan cache:clear, I got error could not find driver (SQL: delete from "cache") .
I have done some solution that I found like :
uncomment extension pdo_pgsql in php.ini
clear files in /storage/framework/cache directory
clear config.php, packages.php and services.php files in /bootstrap/cache directory
uninstall and install nginx, php and postgresql
None of them worked.
I migrate data using php artisan command is worked well. If I run php artisan route:cache, php artisan config:cache and php artisan view:clear, they are also worked well. Only php artisan cache:clear command got problem.
For additional information, this happened after I update my OS to Big Sur (11.1) and these are the version I am using.
nginx 1.19.6
php 7.3.24
postgresql 10.15
laravel 5.5.45
Please help me.
if you use Linux os you should install PHP PDO extension and MySQL extension
apt-get install php-mysql
apt-get install php-pdo
if was not work that , you can install it with the following
apt-get install php-common
I found the solution. PHP cause this problem. Actually mac has preinstalled PHP and this was what I use. This PHP got trouble if we upgrade OS to Big Sur (11.1).
I install PHP from homebrew. I use brew link to make homebrew PHP default. I also set the PATH variable. Restart my terminal and it works.
I tried to install opencats on linux server. Running ubuntu version is 18. When I try to install opencats via http://localhost/opencats (server ip address used as localhost) and click installwizard.php I get the following errors/warnings:
It won't work on PHP7 if it wants the MySQL extension. It has been removed. Its sounds like a very very old project you are trying to install.
I had a quick look on their homepage:
Opencats has a minimum supported PHP version of PHP 5.5, and are working towards full PHP 7 compatibility.
http://www.opencats.org/
OpenCATS does not currently support php7. It must be 5.6.X
you should install PHP5.6, Open your terminal and execute those commands as follow:
1- to install PHP5.6
sudo apt-get install php5.6
2- Now, you should know which PHP version you are using
php --version
3- To stop running the current PHP version, run the commands below to disable it for Apache2 (ex: PHP7.2)
sudo a2dismod phpX
where X is your PHP version
4- Then run the commands below to enable PHP 5.6 for Apache2 to use
sudo a2enmod php5.6
5- Now, You can install the needed PHP extensions like MySQL
sudo apt-get install php5.6-mysql
5- Restart Apache2 for the changes to apply by running the commands below
sudo systemctl restart apache2.service
Hope that this can help you.
OK so I am experiencing something quite odd. My phpinfo() shows one version while php -v shows another.
I am running locally on a MacBook Air (Mojave), with Laravel and Valet.
phpinfo():
PHP Version 7.2.13
Configuration File (php.ini) Path /usr/local/etc/php/7.2
Loaded Configuration File /usr/local/etc/php/7.2/php.ini
Scan this dir for additional .ini files /usr/local/etc/php/7.2/conf.d
While in my terminal, it shows:
php -v
PHP 7.3.0 (cli) (built: Dec 7 2018 11:00:11) ( NTS )
Now, if I do a which php I get this:
/usr/local/bin/php
In my ~/.bash-profile, I have this:
export "PATH=~/.composer/vendor/bin:$PATH"
I have tried to:
Restart Nginx
Restart Valet
Unlink PHP#7.2 and link PHP#7.3with Homebrew:
Olivers-MacBook-Air:~ oliverbusk$ brew unlink php#7.2
Error: No such keg: /usr/local/Cellar/php#7.2
How can I get my actual valet site to use php#7.3?
Below simple fix worked for me.
rm ~/.config/valet/valet.sock
valet restart
In my case it worked after forcing the specific PHP version:
valet use php#7.4 --force
Good news, please upgrade to latest valet version, you can easily switch php version.
Source: https://laravel.com/docs/5.8/valet
PHP Versions
Valet allows you to switch PHP versions using the valet use php#version command. Valet will install the specified PHP version via Brew if it is not already installed:
valet use php#7.2
valet use php //without any specification, it will be using latest version
Something so basic as rebooting my Macbook solved this issue. Once rebooted, the correct version 7.3 showed in my phpinfo();
From MacBook pro (Mojave), with Laravel and Valet:
valet use php#7.2
To be able to effectively change the version of php on my machine I use the following script:
Add to your user's .bash_profile
Then use the following command to switch
switch-php7.x
switch-php() {
valet stop
brew unlink php#7.2 php#7.3 php#7.4
brew link --force --overwrite php#$1
brew services restart php#$1
composer global update
rm -f ~/.config/valet/valet.sock
valet install
}
https://gist.github.com/r1tt3r/e0f199eb274d5ff186b73956af594316
I am running linux valet on Ubuntu 20.04 , The following command works for me
valet use 8.0
Here, 8.0 refers to the php version.
NB: Tested this solution on Ubuntu 20.04 Desktop
If you are using Valet Linux Plus(Has more features than Valet Linux) Just do valet use {your PHP version} --update-cli. For instance to use php8.0 just run:
valet use 8.0 --update-cli
This will update both php-fpm version plus php-cli version too.
Basically the php valet uses and the one used by your macbook is different.
But as already mentioned by #Shiro and #Israel Alexis Palma Quezada, in newer versions valet use php73 would solve your problem.
If it's not working, try running composer global update to update your global packages, thus updating valet
To update the mac php version, execute the following lines:
export PATH="your/path/to/php#7.3/bin:$PATH"
export PATH="your/path/to/php#7.3/sbin:$PATH"
or simply add these two lines to your ~/.profile or ~/.bash_profile
Don't forget to run source ~/.profile or source ~/.bash_profile or whatever file you chose to edit.
Yesterday I encountered the same problem on Ubuntu 18.
At first I changed the PHP version:
$ sudo a2dismod php7.2
$ sudo a2enmod php7.3
$ sudo update-alternatives --set php /usr/bin/7.3
But valet was still showing the wrong PHP version. Rebooting did not work. In fact, phpinfo() was displaying PHP 7.1.
After run ps -aux | grep php I noticed few instances of php-fpm (5.6, 7.1 and 7.2) running.
I stopped them
$ sudo service php5.6-fpm stop
$ sudo service php7.1-fpm stop
$ sudo service php7.2-fpm stop
Then started 7.3
$ sudo service php7.3-fpm start
And now my phpinfo() display the correct version of PHP
I ran into this same problem while using valet plus today. When I switched PHP versions it was showing the previous one in my browser but the correct one in my terminal. Looking at the my brew services list:
brew services list
It showed that one of the valet-php services (valet-php#7.2) was not in the service list but somehow my valet was able to switch to it. Valet didn't install this PHP properly and that's what was causing the issue. I did the following to uninstall that PHP and reinstall it with brew.
brew uninstall valet-php#7.2
sudo rm -rf /usr/local/Cellar/valet-php#7.2/7.2.34_1
brew install valet-php#7.2
The PHP version that was once not showing in the brew services list now showed and I was able to "stop" that php version's service:
brew services stop valet-php#7.2
which made everything work properly again without a restart.
I'm new to laravel, My commands of PHP artisan were working fine in localhost.
When i shifted my project to live server the commands stopped working and gives me following error:
Warning: require(): Invalid date.timezone value 'GST', we selected the
timezone 'UTC' for now. (I fixed this by defining my timezone) Parse
error: syntax error, unexpected '?'
laravel/framework/src/Illuminate/Foundation/helpers.php on line 500
There are actually no errors the project is working fine,My PHP version is 7.2.10.
I'm inside the directory where PHP artisan is installed but of no use.
I hope I have to clear the cache but how can I clear cache when my artisan commands are not working?
Any ideas?
try to change version in apache
find total install version in server
sudo update-alternatives --config php
then select one version then check php version again.
sudo php -v
second way u can do by this command
sudo a2dismod php5.6 //disable old version
sudo a2enmod php7.2 //enable new version
and restart apache2 server
sudo service apache2 restart
and check php version
sudo php -v
for more better understanding see
did you install composer and packages? with composer install command on the server.
You should perform below steps.
1) First you have to check the apache is starting or not.
2) Then you have to Install the composer and command like (i.e.
composer update)
3) You have to clear cache and command like below
1) php artisan config:cache
2) php artisan view:clear
Downgraded the PHP version to 7.1 and upgraded the system to same php version.
Got some exceptions later but it resolves the issue.
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.