In the process of developing web applications using PHP, PDO is a very commonly used extension library. It provides us with a series of functions and classes for accessing the database, which can simplify our operations on the database. This article will introduce how to install PDO extension on Linux operating system.
Preparation before installation
Before installing PDO, we need to ensure that the following software has been installed:
Installing PDO
Before starting to install PDO, we need to check whether PHP has the pdo extension installed.
You can check it with the following command:
php -m | grep pdo
If "pdo_mysql" is output, it means that the pdo_mysql extension has been installed. Otherwise, follow the steps below to install.
The pdo_mysql extension is a PDO driver connected to MySQL. We need to use the package manager to install the extension.
In Debian/Ubuntu system, use the following command to install:
sudo apt-get install php-pdo-mysql
In CentOS/RHEL system, use the following command to install:
sudo yum install php-pdo_mysql
After the installation is completed, PHP needs Reload the configuration file. Reload the PHP configuration using the following command:
sudo systemctl restart php-fpm
Install the PDO extension using PECL. First you need to install the PECL tool.
In Debian/Ubuntu system, use the following command to install:
sudo apt-get install php-pear
In CentOS/RHEL system, use the following command to install:
sudo yum install php-pear
After the installation is complete, you can use The following command installs the PDO extension:
sudo pecl install pdo
After completion, you need to add "extension=pdo.so" to the PHP configuration file to enable the extension.
In Debian/Ubuntu system, open the "/etc/php/
extension=pdo.so
In CentOS /RHEL system, open the "/etc/php.ini" file and add the following content at the end of the file:
extension=pdo.so
After the installation is complete, PHP needs to reload the configuration file. Use the following command to reload the PHP configuration:
sudo systemctl restart php-fpm
Verification
After the installation is complete, you can verify whether the PDO extension has been enabled by running the following command:
php -m | grep pdo
If "pdo" is output, it means that the PDO extension has been successfully installed.
Summary
This article introduces the steps to install the PDO extension on a Linux system, including installing the pdo_mysql extension and using PECL to install the PDO extension, and provides methods to verify the installation results. When using PDO extensions, be sure to pay attention to PHP and MySQL version compatibility to prevent problems.
The above is the detailed content of How to install PDO extension on Linux system. For more information, please follow other related articles on the PHP Chinese website!