Laravel 5.5 "Class 'PDO' not found" - laravel

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

Related

BindingResolutionException Target class [hash] does not exist after deploy

I wanted to deploy my laravel 8.0 project via ssh pull to production. I did composer update in ssh to my ubuntu server and after that my website is down and showing 500 error.
when I turn on debug mode in production it shows below error:
Target class [hash] does not exist.
my website worked well before pull and composer update and after that this happened.
also there is no problem in local environment and it works properly.
my .env file in production also exists and the details are set.
I have tried lots of ways for resolving the error but none of these works:
changing permisions for bootstrap and also for the whole project :
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
removing and reverting bootstrap folder
composer dump-autoload
php artisan config:cache
composer update and sudo composer update
I also tried these commands but none of them worked:
php artisan route:clear
php artisan view:clear
php artisan config:cache
php artisan cache:clear
php artisan config:clear
I've searched alot and tried many ways but no result.
could any one say what is wrong please? thanks alot.

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.

Downloaded laravel project hangs on preloader when deployed on localhost

I'm trying to deploy a laravel project I have received onto my localhost but it hangs on the loading page and doesn't load the site.
I received the source code of a laravel project that was coded for me.
The deployed website on the shared hosting works properly, and I can also manipulate the files through my ftp access.
However, I'm trying to deploy the project on my localhost (as well as to migrate to a different shared hosting service).
I tried loading the server on wamp, homestead and with artisan serve, but all methods end up the same - the index.php seems to be loading, but is stuck eternally on the preloading .gif file and doesn't present the site.
the browser debugger is throwing a lot of javascript errors (see attached image)
I assume a have a config problem, but I can't locate it and I am unsure how to even locate & debug the issue.
I tried following these configuration steps:
1. changed .htaccess to generic laravel .htaccess (deleted cpanel related lines)
2. changed the .env to fit my wamp db / homestead db
3. composer install
4. composer update
5. php artisan key:generate
6. php artisan cache:clear
7. php artisan migrate
I also installed laravel-debugbar but it hasn't helped me out of the box, and I'm unsure where I need to try to catch the problem.
If anyone can give me pointers on how to understand my problem better, I would be very thankful.
Thanks in advance!
laravel bug
Double check your .env if all details are correct
Set APP_DEBUG=true in your .env file
Double check if your database exist and have data if you are using a database
Check if your host is added to /etc/hosts
Check if your host is added to apache/nginx config correctly
Try running these commands:
$ rm composer.lock package-lock.json
$ composer install
$ npm install
$ npm run dev
$ php artisan clear-compiled
$ php artisan optimize:clear
$ php artisan package:discover
$ php artisan storage:link
$ php artisan migrate:fresh && php artisan db:seed // optional!
Then clear browser cache to be safe.
Open web inspector to see if you can see any errors.
Open latest laravel log in storage/logs/ folder to debug.
If all fails, install laravel-debugbar and see if you can debug there.

Why command "php artisan serve" not working

I started Laravel at this path:
C:\Users\Mad\Work\trunk\product\backend\v1.2.1\laravel
but it is not working, it is not starting.
Please give me suggestions how I will do it ?
try
php -S localhost:8000 -t public/
source : http://allbitsnbytes.com/posts/php-artisan-serve-not-working/
Try this also
php -S 127.0.0.1:8000 -t public/
https://www.tutsmake.com/laravel-command-php-artisan-serve-not-working-properly/
try to execute the command : composer update.
It will update and export all the directorys/files that u need.
because sometimes when u clone/download a repository from github .. there are pretty much directorys/files that are not present (not exportable .. present in .gitignor).
then try : php artisan serve.
it works for me
composer update
This will update and export directories and files and then run the below command :
php artisan serve
or you can also try this on your terminal:
php -S localhost:8000 -t public/
Just wanted to add to Jayhuan's answer above:
Laravel does the same thing behind the scenes, you can see the code here (look in serverCommand).
So to serve locally you would do:
php artisan serve --host mysite.com --port 8000
try only this
php -S localhost:8000
Your missing some Server Requirements
See the Laravel site for requirements.
Laravel Documentation
The Laravel framework has a few system requirements.
If you are not using Homestead, you will need to make sure your server meets the following requirements:
PHP >= 7.1.3
BCMath PHP Extension
Ctype PHP Extension
JSON PHP Extension
Mbstring PHP Extension
OpenSSL PHP Extension
PDO PHP Extension
Tokenizer PHP Extension
XML PHP Extension
To see a list of your extensions... From the command line:
$ php -m
I was missing BCMath and Tokenizer so I installed them with:
$ sudo apt-get install php-bcmath
$ sudo apt-get install php-tokenizer
Now you can use $ php artisan serve
Try the below code
php -S localhost:8000 -t public
I think you also check your path which you use in the composer like C:\Users\HP>
example:if your parent folder is blog then use
C:\Users\HP> cd blog/
C:\Users\HP>blog> php artisan serve
There could be multiple reasons for this problem one of the reasons is using old dependencies.
step 1: Check your current version of PHP and version of dependencies if they don't match proceed to next step.
step 2: replace the older dependencies with the newer one in composer.json file.
facade/ignition to ^2.3.6
laravel/framework to ^8.0
laravel/ui to ^3.0
nunomaduro/collision to ^5.0
phpunit/phpunit to ^9.0
The following first-party packages have new major releases to support Laravel 8. If applicable, you should read their individual upgrade guides before upgrading
Passport v10.0
Socialite v5.0
Telescope v4.0
Try to find the appropriate dependencies for your project and make sure u add the correct version of it in the composer.json file.
step 3: Now the next step is to update the composer
`composer update`
step 4: The last step is to run the artisan serve command.
php artisan serve
If all the dependencies are perfect then it will work. All the best.

Laravel Migration Error :: PDOException, Could not find driver

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

Resources