Home > Article > Backend Development > How to install pdo_mysql extension in php
How to install the pdo_mysql extension in php: 1. Download the source code package of the pdo_mysql extension and unzip it; 2. Execute phpize to generate the makefile; 3. Open the php.ini configuration file; 4. Modify the php extension path and open [ extension=pdo_mysql.so].
Specific steps:
(Learning video recommendation: php video tutorial)
Download first The source code package of pdo_mysql extension. You can use wget to download directly to the server
# wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
and then decompress it.
# tar -zxvf PDO_MYSQL-1.0.2.tgz
Enter the decompressed directory and execute phpize.
# /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20100412 Zend Module Api No: 20100525 Zend Extension Api No: 220100525
The next two parameters generated in the makefile
must be added. I did not add them at the beginning, but the result was that the header files of php-config and mysql could not be found.
# ./configure –with-php-config=/usr/local/php/bin/php-config –with-pdo-mysql=/usr/local/mysql
Before making, you need to make a soft connection to the mysql header file. Because the directory is specified when MySQL is installed, the header file will still not be found without making a soft connection.
# ln -s /usr/local/mysql/include/* /usr/local/include/
Then make and make install
# make # make install
(recommended related tutorials: php graphic tutorial)
will prompt you As follows, it means that the extension is installed in the following directory.
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/
For convenience, I moved the pdo_mysql.so file to the extensions directory
# mv /usr/local/php/lib/php/extensions/no-debug-zts-20100525/pdo_mysql.so /usr/local/php/lib/php/extensions/
Then you can modify the php.ini file.
Find the line; extension_dir = “./”, remove the comment, and modify the path.
extension_dir = “/usr/local/php/lib/php/extensions/”
After testing here, it was found that php will only look for the extension so from this directory, but not the subdirectories under this directory. So before, I moved all so files to this directory for unified management.
Find the line; extension=php_pdo_mysql.dll, remove the comment, and modify the following file name.
extension=pdo_mysql.so
The file names are different. You need to remove the php_ prefix here, otherwise the file cannot be found. The following dll is the file name under windows, we change it to so.
Finally just restart apache. Use phpinfo() to check and find that it has taken effect.
The above is the detailed content of How to install pdo_mysql extension in php. For more information, please follow other related articles on the PHP Chinese website!