Laravel Migration Error :: PDOException, Could not find driver - laravel

I am trying to make a laravel and stucked when migration. when i enter php artisan migrate in terminal, showing PDOException error. attaching my screenshot of terminal and phpinfo.
What i sthis issue, How can i solve this,
I am using Xampp.
Anybody please help me.
Thanks

Try re-installing Xampp? You could use Laravel homestead for a virtual machine, it makes sure you have the proper PHP version and the required dependencies needed to install and avoids having to run Xampp or MAMP or WAMP or any of the amps.
It looks like Xampp cannot find: /usr/lib/php5/20121212/php_pdo_mysql.dll, so make sure that file exists.
You may need to re-install PHP PDO on your machine, refer to: http://php.net/manual/en/pdo.installation.php
Also per PHP docs:
PDO and all the major drivers ship with PHP as shared extensions, and
simply need to be activated by editing the php.ini file:
extension=php_pdo.dll

Please check you have installed more than one php version in your system, one is running for web server and another for php CLI, using PHP_INFO for web and php --ini in commandline, if different version found then upgrade or downgrade means make it one version configuration, and make sure PDO is enable in your system.
From php5.6 to php7.0:
Apache:
sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restart
CLI:
sudo update-alternatives --set php /usr/bin/php7.0
From php7.0 to php5.6:
Apache:
sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart
CLI:
sudo update-alternatives --set php /usr/bin/php5.6

Related

Laravel 8 Project is not opening in the server..getting error in TestDatabases.php

I am Getting error when I open the laravel 8 project
protected function switchToDatabase($database)
{
DB::purge();
$default = config('database.default');
config()->set(
"database.connections.{$default}.database",
$database,
);
}
"syntax error, unexpected ')'" in vendor/laravel/framework/src/Illuminate/Testing/Concerns/TestDatabases.php
Gert B. answer does solve the situation, but you should instead update your PHP to version 7.3 or higher, as Mohammad mentioned, to solve this. Changing platform/vendor code is not the best option.
You're using a PHP version lower than 7.3
in: vendor/laravel/framework/src/Illuminate/Testing/Concerns/TestDatabases.php
Change:
if ($url) {
config()->set(
"database.connections.{$default}.url",
preg_replace('/^(.*)(\/[\w-]*)(\??.*)$/', "$1/{$database}$3", $url),
);
} else {
config()->set(
"database.connections.{$default}.database",
$database,
);
}
to:
if ($url) {
config()->set(
"database.connections.{$default}.url",
preg_replace('/^(.*)(\/[\w-]*)(\??.*)$/', "$1/{$database}$3", $url)
);
} else {
config()->set(
"database.connections.{$default}.database",
$database
);
}
Removing the comma at the end of line fixes the issue.
remove the trailing "," in your set function call:
config()->set(
"database.connections.{$default}.database",
$database
);
Remove the "," directly from file placed in vendors folder isn't a good idea.
To resolve the issue update your php version (7.3 or higher).
If you are using valet:
execute valet use php#7.3 or higher
If you are using something like vagrant (and apache):
connet to server via "vagrant ssh"
install php7.3 or higher (sudo apt install php7.3) and then the related packages that you want
disable your current php version via "sudo a2dismod php7.2" (if your current version is 7.2)
enable php7.3 via "sudo a2enmod php7.3"
restart apache "sudo service apache2 restart"
phpinfo() gives you the version of apache which is the actual version the project runs on and in case you want to change it simply follow these steps:
install php version that you wish to install:
sudo add-apt-repository ppa:ondrej/php -y
sudo apt-get update
//replace X with the version you want
sudo apt-get install php7.X-fpm php7.X-curl php7.X-mbstring php7.X-mysql -y
Now restart your apache:
sudo service apache2 restart
disable current php version(the one that phpinfo() gives you):
sudo a2dismod php7.2
And now enable php version that you just installed:
sudo a2enmod php7.X
In case anyone is as stuck on this as I was, here were the steps I followed. If you have the same situation as me, your php versions might be different. I was going from 7.2 to 7.4. I had to:
Uninstall my old version of php via homebrew
brew uninstall php#7.2
Completely delete the reference I had to that old version of php even though I had uninstalled it via homebrew.
rm -rf /usr/local/Cellar/php#7.2
Unlink all versions except php#7.4. For me that was php#7.2 and php with no version specification.
brew unlink php
brew unlink php#7.2
For my experience in Ubuntu Linux, check your php version
php -v
You may switch to require version, install if you don't have php#7.4
sudo update-alternatives --set php /usr/bin/php7.4
Do your requirements. I have migration issue. So
php artisan migrate
switch back to default version
sudo update-alternatives --set php /usr/bin/php7.2

In Laravel - could not find driver on xampp using ubuntu 16.04

I am working on xampp 7.3 version of PHP.
I am facing the below error.
Illuminate\Database\QueryException: could not find driver (SQL: select name from table where id = e690ddc2-a2b6-4aad-8a73-dab1771c0ea6 limit 1) in file /opt/lampp/htdocs/ProjectFolder/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 669
Also, I have uncommented the pdo_mysql.dll in php.ini file it still giving me an error.
Also, it is working in the windows system but not in Ubuntu16.04.
how can solve this?
You should install the necessary packages
sudo apt-get install php*-mysql
Then uncomment the MySQL extensions on php.ini and restart your server
sudo service apache2 restart
In your project set the correct parameters and in the root of your project run
php artisan config:cache
I resolve this issue on Ubuntu 18.04 by:
"Control C" out of the php artisan serve command to stop the application.
Stop all the servers running on XAMPP -> (Apache, MySQL and ProFTPD).
Enable mysql inside of XAMPP via path $ cd /opt/lampp/etc .
$ sudo nano php.ini or open in your choice of text editor. I use PHPStorm.
Search for "php_mysql.dll".
Removed the ";" in front of ";extension=php_mysql.dll" -> hit save.
Back in the terminal -> $ cd.. back one folder into the /opt/lampp.
Run $ sudo apt-get install php*-mysql. -> Could take a couple minutes based on your internet connection.
After the install is complete -> restart all the XAMPP servers.
Run $ php artisan config:cache.
Run $ php artisan serve.

Laravel: [ErrorException] "continue" targeting switch is equivalent to "break". during "composer install"

When I run ...
composer install
... on a server with PHP and nginx installed.
I get the following exception:
[ErrorException]
"continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?
How can I fix this?
This is a new warning introduced in PHP 7.3.
It means you are not allowed to have a continue statement inside of a switch, you should use break instead.
To fix this you most likely just have to update composer, this can be done simply by running composer self-update.
You can also just run php without warnings, this can be done by setting the ini config values as a start parameter.
php -d error_reporting=0 composer.phar
Check your current PHP version if it's greater than 7.2, then execute follow below simple steps
1. Disable the latest php version
sudo a2dismod php7.3
2. Restart the nginx service
sudo service nginx restart
3. If you are using Apache2 run as below
sudo service apache2 restart
4. Set alternatives
sudo update-alternatives --set php /usr/bin/php7.2
5. Check the PHP version
php -v
6. Now, Install Composer as below
composer install
Old composer uses continue statement in their code within the switch which is outdated and cannot be used anymore with latest version of php.
you need to update your composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=bin
for more details visit composer download
It was because of an outdated composer. After searching a lot finally the following works for me:
Uninstall the old composer.
Install a new updated composer.
You can download or install composer from this link: https://getcomposer.org/download/
For me,
just go to this file
sudo nano /usr/share/php/Composer/DependencyResolver/RuleSetGenerator.php
As a quick and dirty alternative, you can fix the error in that file. Just replace "continue" with "break"

How to enable php-Mcrypt extension in Laravel Homestead

I am trying to get an old Laravel 4.1.x app up and running again so that it can be modernized. This requires an environment with PHP 5.6 and the Mcrypt extension. I have installed Homestead 9.0.3 (the latest stable version). Within the VM, I have set the PHP version to 5.6
sudo update-alternatives --config php
I have then installed the php-mcrypt extension
sudo apt-get install php5.6-mcrypt
I am now able to create a new Laravel 4.1.x project, which is a process that requires Mcrypt to complete, so we're certainly getting somewhere:
composer create-project laravel/laravel="4.1.*" myAppName
However, when I browse to the webpage for myAppName, I see the message:
Mcrypt PHP extension required.
I have also tried steps that are usually recommended for this problem, ie:
sudo ln -s /etc/php/5.6/conf.d/mcrypt.ini /etc/php/5.6/mods-available/mcrypt.ini
sudo phpenmod mcrypt
sudo service php5.6-fpm restart
But I still get the same message in the browser.
What step have I missed?
With homestead v9 you should be up and running with php5.6 out of the box as stated in
here, but unfortunately it is not your case, and I understand that...
Old packages were not installed by default (php5.6-mcrypt), as you mentioned and they should be added by hand via:
sudo apt-get install php5.6-mcrypt
After that all packages are ready, up and working, especially php5.6-mcrypt.
The root of your problem is in multiple site definitions under your homestead.yaml.
Most probably some of them are overlapping and your nginx is referring to the wrong resource/site_definition, and wrong paths.
Therefore you might think some strange php versions or routes are run/executed.
You can verify that, by deleting some/all of them, leaving the only one important for you - in (/etc/nginx/sites-enabled/...).
Of course please do that inside the container and issue sudo service nginx restart, afterwards...
All of your problems should be gone after that.
If something goes wrong. You could easily recover your current installation to current state using vagrant destroy and vagrant up afterwards, cause all is saved in Homestead.yaml.
In my installation Homestead v9 is running with php5.6 on laravel 4.1 without any problems...
Hope it helps #jsm...
Because all the PHP versions installed on homestead you need to set the PHP version for a site in the Homestead.yaml.
First check what version the server is running with phpinfo();
Check the file /etc/nginx/sites-enabled/homestead.test and look for this line:
fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
If you didn't set the php version on the sites list, this file will be pointing to the php7.3.sock.
In this case the version 5.6 has mcrypt installed, but 7.3 don't.
You can just replace the line
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
for
fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
and then reload nginx with sudo nginx -s reload.
Or set the php version on Homestead.yaml:
sites:
- map: homestead.test
to: /home/vagrant/code/public
php: "5.6"
And then run vagrant provision, it will change the nginx configuration for PHP 5.6.

Laravel 5.5 "Class 'PDO' not found"

Here is the actual error when I open the site
Actually, I have successfully run php artisan migrate:refresh, and there is no error.
Already tried the following command.
php artisan cache:clear
php artisan config:clear
composer install
composer clearcache
composer dump-autoload
php artisan clear-compiled
I also checked if pdo is installed, thru php -m and its already installed
I'm using CentOS.
What is most likely happening here is that the PDO module is enabled in the php-cli config (hence it works from command line), but is not enabled on the web server configuration file.
I am adding all possible options which can solve the issue
Add use PDO; after your namespace or just before your class or at the top of your PHP file
As you are using centOS try the below commands
yum install php-pdo
yum install php-pdo_mysql
service httpd restart
If still its not solved check the php.ini file path to see which is being loaded in the phpinfo() output.
Sometimes there are two different PHP versions installed on a machine, one for CLI and one for the web server.
Restart your apache, nginx, php-fpm
Run <?php phpinfo(); ?> and find out the /path/to/php.ini
Open php.ini
sudo nano /path/to/php.ini
Add these lines to enable the extensions
extension=openssl
extension=pdo_firebird
extension=pdo.so
extension=pdo_mysql
extension=pdo_oci
extension=pdo_odbc
extension=pdo_pgsql
extension=pdo_sqlite
Restart the server
sudo apachectl restart

Resources