How to Install PHP PDO MySQL Extension in Ubuntu 22.04

Websolutionstuff | Feb-28-2024 | Categories : PHP

Hey there! If you're diving into PHP development on Ubuntu 22.04 and need to connect your applications to MySQL databases, you're in the right place. In this step-by-step guide, I'll walk you through installing the PHP PDO MySQL extension on your Ubuntu 22.04 system.

PHP PDO (PHP Data Objects) provides a consistent interface for accessing databases, and MySQL is one of the most popular database management systems out there.

By installing the PDO MySQL extension, you'll be able to seamlessly interact with MySQL databases from your PHP applications.

Also, you can install the PHP pdo_mysql extension in Ubuntu 16.04, ubuntu 18.04, and ubuntu 20.04.

So, let's see how to install the PHP PDO MySQL extension in Ubuntu 22.04, install the PHP extension in Ubuntu 20.04, how to install the PDO php extension in Ubuntu, and how to install the PDO MySQL extension.

Update Package Lists:

First, I'll make sure my package lists are up-to-date by running the following command in the terminal:

sudo apt update

 

Install PDO MySQL Extension:

This extension allows PHP to communicate with MySQL databases using the PDO (PHP Data Objects) interface:

sudo apt install php-mysql

For PHP 8.3

sudo apt-get install php8.3-mysql

For PHP 8.2

sudo apt-get install php8.2-mysql

For PHP 8.1

sudo apt-get install php8.1-mysql

For PHP 8.0

sudo apt-get install php8.0-mysql

For PHP 7.4

sudo apt-get install php7.4-mysql

 

Restart Apache Server:

After installing, restart the Apache server using the following command.

sudo service apache2 restart

 

Verify Installation:

To confirm that the PDO MySQL extension has been successfully installed, I'll create a PHP script to check for its presence. I'll create a new file named check_pdo_mysql.php using a text editor such as Nano or Vim:

nano check_pdo_mysql.php

Inside the file, I'll add the following PHP code:

<?php
if (extension_loaded('pdo_mysql')) {
    echo "PDO MySQL extension is installed.\n";
} else {
    echo "PDO MySQL extension is not installed.\n";
}
?>

I'll save the file and exit the text editor.

 

Run the PHP Script:

Now, I'll run the PHP script to verify the installation of the PDO MySQL extension. I'll navigate to the directory containing the script in the terminal and execute the following command:

php check_pdo_mysql.php

If the PDO MySQL extension is installed correctly, I should see the message "PDO MySQL extension is installed.

That's it! I've successfully installed the PHP PDO MySQL extension on my Ubuntu 22.04 system.

 


You might also like:

Recommended Post
Featured Post
Laravel 10 Delete Multiple Records Using Checkbox
Laravel 10 Delete Multiple Rec...

In this article, we will see laravel 10 delete multiple records using the checkbox. Here, we will learn about how to del...

Read More

Mar-03-2023

How to Deploy Laravel on Heroku with Database
How to Deploy Laravel on Herok...

In this article, we will see how to deploy laravel on heroku with database. Heroku is a cloud platform as...

Read More

Feb-12-2021

Laravel 11 Livewire Datatable Example
Laravel 11 Livewire Datatable...

Hello, laravel web developers! In this article, we'll see how to create datatable in laravel 11 livewire using medic...

Read More

Jun-05-2024

How To Generate QRcode In Laravel
How To Generate QRcode In Lara...

In this example, I will give information about how to generate QR code in laravel. As per the current trend, many w...

Read More

Jun-01-2020