Home  >  Article  >  System Tutorial  >  Install PDO extension for PHP on CentOS

Install PDO extension for PHP on CentOS

WBOY
WBOYforward
2024-01-04 12:00:45943browse

PHP Data Object PDO extension defines a lightweight consistent interface for PHP to access the database. PDO provides a data access abstraction layer, which means that no matter which database is used, the same functions (methods) can be used to query and obtain data.

environment:

Server system: Centos6.5 (virtual machine demonstration)

PHP software package storage directory:/data/php-5.6.14/

PHP installation directory:/usr/local/php/

mysql installation directory:/usr/local/mysql/

Operating procedures:

Through the phpinfo() function we can check whether the PDO extension is installed on the server. If the PDO extension information is not found, then we install it through the following steps:
Find your PHP installation package (mine is placed in the /data/php-5.6.14/ directory), enter the pdo_mysql directory of the PHP extension, and run the following command:

/usr/local/php/bin/phpize

(/usr/local/php/ is my PHP installation directory, you can modify it according to the actual situation)

Install PDO extension for PHP on CentOS
After executing the above command, we will find that the configure file appears in the current pdo_msyql directory.

Install PDO extension for PHP on CentOS
However, we execute the following command:

./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql/

Parameter Description:
--with-php-config=/usr/local/php/bin/php-config Specifies the configuration when installing PHP
--with-pdo-MySQL=/usr/local/mysql/ Specify the installation directory location of the MySQL database
(The specific installation directory of PHP and msyql here depends on your actual situation)

Continue to compile and install:

make && make install

After the command is executed, the effect is as follows:
Install PDO extension for PHP on CentOS

The directory that is sufficient for the last line will be used later. The pdo_mysql.so file generated at this time is in this directory:

Install PDO extension for PHP on CentOS

Next we modify the PHP configuration file, open your php.ini file, and add a line of code:

extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/pdo_mysql.so

(Here is the pdo_mysql.so directory I demonstrated. You can add it according to your actual directory when setting up)

Install PDO extension for PHP on CentOS

Finally save and launch, and restart the service. Then use the phpinfo() function to check whether the PDO extension is installed successfully. The results are as follows, indicating that the PDO extension is installed successfully.
Install PDO extension for PHP on CentOS

The above is the detailed content of Install PDO extension for PHP on CentOS. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:linuxprobe.com. If there is any infringement, please contact admin@php.cn delete