Home > Backend Development > PHP7 > How to install pdo_mysql extension in php7

How to install pdo_mysql extension in php7

PHPz
Release: 2023-03-31 09:35:23
Original
2054 people have browsed it

When doing PHP programming, we often need to use the MySQL database. In PHP, the PDO extension is one of the important tools for connecting to the MySQL database. It can provide a database access interface with high efficiency, reusability and security. In versions above PHP 7, you need to go through certain steps to install the PDO_MYSQL extension.

This article will teach you how to install the PDO_MYSQL extension on PHP 7.

1. Preparation before installation

1. You need to install the PHP development environment, including PHP, Apache and MySQL.

2. You need to download the PDO_MYSQL extension, download address:

http://pecl.php.net/package/PDO_MYSQL

3. You need to check your PHP Whether the PDO extension is already installed in the environment. Run the following command in the terminal:

php -m | grep pdo
Copy after login

If you have installed the PDO extension, this command will return something similar to the following:

pdo_mysql
pdo_sqlite
pdo_pgsql
pdo_sqlsrv
Copy after login

2. Install PDO_MYSQL

Next, We will perform different installation methods based on your PHP version and operating system type.

1. Install PDO_MYSQL in CentOS 7

1) Install pdo and pdo_mysql:

yum install php-pdo
yum install php-pdo_mysql
Copy after login

2) Install the Pecl tool:

yum install php-pear
Copy after login

3) Install PDO_MYSQL extension:

pecl install pdo_mysql
Copy after login

4) Modify the php.ini file:

Add the following content at the end of the php.ini file:

extension=pdo_mysql.so
Copy after login
Copy after login

5) Restart Apache:

systemctl restart httpd
Copy after login

2. Install PDO_MYSQL in Ubuntu

1) Install pdo and pdo_mysql:

sudo apt-get install php7.0-mysql
sudo apt-get install php7.0-mysql
Copy after login

2) Install PDO_MYSQL extension:

sudo pecl install pdo_mysql
Copy after login

3) Modify php.ini File:

Add the following content at the end of the php.ini file:

extension=pdo_mysql.so
Copy after login
Copy after login

4) Restart Apache:

sudo service apache2 restart
Copy after login

3. Check whether PDO_MYSQL is installed successfully

Execute the following command to check whether there is already a pdo_mysql extension in your PHP environment:

php -m | grep pdo_mysql
Copy after login

If the execution result contains the "pdo_mysql" extension, the installation is successful.

Summary

Through the method in this article, you can successfully install the PDO_MYSQL extension. Properly installing and configuring extensions is very important for programming development, allowing developers to develop more efficiently. If you encounter problems during the installation process, you can ask questions in the community and the community will provide you with support.

The above is the detailed content of How to install pdo_mysql extension in php7. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template