If you've recently upgraded to PHP 8.5 and started seeing deprecation warnings in a Laravel application, you may run into an error similar to this:
Deprecated: Constant PDO::MYSQL_ATTR_SSL_CA is deprecated since 8.5,
use Pdo\Mysql::ATTR_SSL_CA instead
In my case, the warning was pointing to:
config/database.php
at line 62.
Here's how I fixed it and what I learned along the way.
The Problem
After upgrading to PHP 8.5, I ran:
php artisan config:clear
Instead of clearing the configuration cache, Laravel returned:
Deprecated: Constant PDO::MYSQL_ATTR_SSL_CA is deprecated since 8.5,
use Pdo\Mysql::ATTR_SSL_CA instead
In database.php line 62:
Undefined constant PDO::mysql_ATTR_SSL_CA
The important part is:
Undefined constant PDO::mysql_ATTR_SSL_CA
This happened because the constant had been changed incorrectly.
The Old Constant
Older PHP versions commonly use:
PDO::MYSQL_ATTR_SSL_CA
PHP 8.5 deprecates this form and recommends the MySQL-specific class instead.
The new form is:
Pdo\Mysql::ATTR_SSL_CA
Notice that PHP class and constant names are case-sensitive.
Incorrect
PDO::mysql_ATTR_SSL_CA
Correct
Pdo\Mysql::ATTR_SSL_CA
The difference is important:
PDO::mysql_ATTR_SSL_CA
^^^ ^^^^^^^^^^^^^^^
Pdo\Mysql::ATTR_SSL_CA
^^^ ^^^^^ ^^^^^^^^^
Fixing database.php
Open your Laravel project's database configuration:
config/database.php
Look for:
PDO::MYSQL_ATTR_SSL_CA
Replace it with:
Pdo\Mysql::ATTR_SSL_CA
For example, if you have:
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
change it to:
'options' => extension_loaded('pdo_mysql') ? array_filter([
Pdo\Mysql::ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
What If You Can't Edit the File With Nano?
If you're using Ubuntu and nano isn't working for you, there are several alternatives.
Using VS Code
If VS Code is installed:
code config/database.php
Or use the full path:
code /home/tommi/Desktop/Development/programmer/samupos/config/database.php
Then replace:
PDO::MYSQL_ATTR_SSL_CA
with:
Pdo\Mysql::ATTR_SSL_CA
Using the Terminal
If you only need to replace the constant, you can use sed:
sed -i 's/PDO::mysql_ATTR_SSL_CA/Pdo\\Mysql::ATTR_SSL_CA/g' config/database.php
If you get a permission error, you can use:
sudo sed -i 's/PDO::mysql_ATTR_SSL_CA/Pdo\\Mysql::ATTR_SSL_CA/g' config/database.php
Then verify the change:
grep -n "SSL_CA" config/database.php
You should see:
Pdo\Mysql::ATTR_SSL_CA
Verify That PHP Supports the New Constant
Before trying Laravel again, you can check whether PHP recognizes the new constant:
php -r 'var_dump(Pdo\Mysql::ATTR_SSL_CA);'
If everything is working correctly, PHP should return an integer value.
For example:
int(10023)
The exact integer isn't the important part. What matters is that PHP recognizes the constant without throwing an error.
Clear Laravel's Configuration Cache
Once the constant has been corrected, go back to your Laravel project:
cd /home/tommi/Desktop/Development/programmer/samupos
Then run:
php artisan config:clear
You can also rebuild the configuration cache:
php artisan config:cache
If those commands complete successfully, Laravel should no longer complain about:
PDO::MYSQL_ATTR_SSL_CA
Another PHP 8.5 Warning
During this process, I also encountered another warning:
Deprecated: Using null as an array offset is deprecated, use an empty string instead
It pointed to:
vendor/laravel/framework/src/Illuminate/Log/LogManager.php
This is a different issue from the PDO constant.
It's important not to directly edit files inside vendor/.
The vendor directory contains dependencies installed by Composer, so changes made there can be overwritten the next time you run:
composer install
or:
composer update
Instead, check your Laravel version:
php artisan --version
and your PHP version:
php -v
If you're running an older Laravel version with PHP 8.5, you may need to update Laravel or one of its dependencies to a version that properly supports PHP 8.5.
Don't Mix Ubuntu PPAs Just to Fix This
Another potential problem I encountered while setting up PHP was an Ubuntu repository error involving the Ondřej PHP PPA:
The repository 'https://ppa.launchpadcontent.net/ondrej/php/ubuntu resolute Release'
does not have a Release file.
If you're running a newer Ubuntu release and the PPA doesn't provide packages for that release, don't simply change the distribution name in the repository from something like:
resolute
to:
noble
just to make apt update work.
Mixing packages from different Ubuntu releases can cause dependency problems.
Instead, verify what PHP version and packages your current Ubuntu release provides.
Useful Diagnostic Commands
When troubleshooting PHP and Laravel compatibility issues, these commands are useful:
Check PHP version
php -v
Check Laravel version
php artisan --version
Check whether PDO MySQL is installed
php -m | grep pdo_mysql
Expected output:
pdo_mysql
Check the new PHP 8.5 constant
php -r 'var_dump(Pdo\Mysql::ATTR_SSL_CA);'
Find the SSL constant in Laravel's configuration
grep -n "SSL_CA" config/database.php
Final Fix
The key change is simply:
- PDO::MYSQL_ATTR_SSL_CA
+ Pdo\Mysql::ATTR_SSL_CA
Then clear Laravel's configuration:
php artisan config:clear
and, if necessary:
php artisan config:cache
Conclusion
PHP upgrades can expose deprecated functionality that previously worked without any problems. PHP 8.5 is a good example of this: code using the old PDO::MYSQL_ATTR_SSL_CA constant can start producing deprecation warnings.
The important thing is to distinguish between a deprecation warning, an actual PHP error, and a framework compatibility problem.
For this particular issue, the solution is straightforward:
Pdo\Mysql::ATTR_SSL_CA
instead of:
PDO::MYSQL_ATTR_SSL_CA
And when another warning points into vendor/, resist the temptation to edit the dependency directly. Check your Laravel and package versions first and upgrade them where appropriate.
Hopefully this saves someone else a few minutes when upgrading a Laravel project to PHP 8.5.
Top comments (0)