Laravel 5.5部署至PHP7.2主机时出现Class 'PDO' not found错误
Hey there, let's cut straight to the root of your issue. Looking at your PHP configure command, the problem jumps right out: your PHP 7.2 build was compiled with the --disable-pdo flag, which completely turns off the PDO extension Laravel relies on to connect to your database. That's exactly why you're hitting the "Class 'PDO' not found" error when accessing your public directory.
Take a look at this line in your configure arguments — it's the direct culprit:
'--disable-pdo'
Laravel (and nearly all modern PHP database-driven frameworks) depends on PDO for database operations. Since your PHP installation explicitly disables this extension, the framework can't locate the PDO class when trying to establish a database connection.
How to Resolve This
Since you're using cPanel's EA-PHP72, here's the straightforward fix:
Enable PDO via cPanel's PHP Extension Manager
- Log into your cPanel account
- Head to either
Select PHP VersionorMultiPHP Manager(the exact option depends on your cPanel theme) - Look for extensions like
pdo_mysql(if you're using MySQL/MariaDB) or the relevant PDO driver for your database (e.g.,pdo_pgsqlfor PostgreSQL) - Check the box next to the extension to enable it, then save your changes
- Most cPanel setups will restart the web server automatically, but if you still see the error, you can manually restart it via the
Restart Servicessection in cPanel
Verify the Fix
To confirm PDO is enabled correctly, create a temporaryphpinfo.phpfile in your public directory with this code:<?php phpinfo(); ?>Access this file through your browser, then search for "PDO" — you should see a dedicated section for PDO, along with your enabled database driver (like PDO MySQL) listed as active.
内容的提问来源于stack exchange,提问作者A. Mohamed

