How to Install PHP PDO MySQL Extension in Ubuntu 22.04?

By Hardik Savani May 14, 2024 Category : PHP Ubuntu

Hello Developer,

This definitive guide, we will show you how to install php pdo_mysql extension in ubuntu. you'll learn php pdo mysql extension ubuntu. If you have a question about ubuntu php pdo mysql missing extension ubuntu then I will give a simple example with a solution. It's a simple example of ubuntu php install php ext-pdo_mysql extension. So, let us see in detail an example.

We can install php pdo_mysql extension using php-mysql library. i will give you following list of commands to install php pdo_mysql extension in ubuntu 22.10, ubuntu 22.04, ubuntu 21.10, ubuntu 21.04, ubuntu 20.04, ubuntu 18.04 and ubuntu 16.04 server.

Install php-mysql Extension:

Solution:

You need to run both commands one by one:

sudo apt-get install php-mysql

Solution for PHP 8.3

You need to run both command one by one:

sudo apt-get install php8.3-mysql

Solution for PHP 8.2

You need to run both command one by one:

sudo apt-get install php8.2-mysql

Solution for PHP 8.1

You need to run both command one by one:

sudo apt-get install php8.1-mysql

Solution for PHP 8.0

You need to run both command one by one:

sudo apt-get install php8.0-mysql

Solution for PHP 7.4

You need to run both command one by one:

sudo apt-get install php7.4-mysql

Solution for PHP 7.3

You need to run both command one by one:

sudo apt-get install php7.3-mysql

Solution for PHP 7.2

You need to run both command one by one:

sudo apt-get install php7.2-mysql

Restart Apache Server:

Now, restart apache2 server using following command:

sudo service apache2 restart

Check php-mysql Extension Installed:

Here, we will run following command to check extension is installed or not:

php -m | grep -i mysql

You can check if the mysql extension is enabled by creating a PHP file with the following content and accessing it through your web browser:

<?php

phpinfo();

?>

Look for a section that mentions "mysql." If you see it, the extension is successfully installed and enabled.

Please note that the package name (php-mysql) and web server commands may vary slightly depending on your PHP version and web server. If there are any changes in Ubuntu 22.04, make sure to check the official documentation or community resources for the most up-to-date information.

I hope it can help you...

Tags :
Shares