How to install mysql extension in php5.6: 1. Download the extended source code package and unzip it; 2. Execute phpize; 3. Generate makefile and execute make and make install commands; 4. Modify the php.ini configuration file ;5. Restart the httpd service.
The operating environment of this article: centos 7 system, php 5.6, thinkpad t480 computer.
Recently, I accidentally discovered an error while maintaining an old project. The error message: "Fatal error: Uncaught Error: Call to undefined function mysql_connect()". After finding out the cause, I found that the mysql_connect module in PHP has been deprecated, and I did not install the mysql extension when setting up the environment, so I got this error.
Now that we have identified the cause, it will be much easier to solve it. We can solve this problem by manually compiling and generating the mysql.so extension using the phpize tool.
The specific steps are as follows:
First, download the source code package of the pdo_mysql extension.
# wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
Then decompression.
# 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
Generate the makefile below. The last two parameters must be added. I did not add them at first, 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
The following prompt will appear, which means that the extension is installed in the following directory.
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/
Modify the php.ini file
Modify: extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20100525/"
Add: extension=pdo_mysql.so
Restart httpd to reload the php configuration file
Recommended learning: php training
The above is the detailed content of How to install mysql extension in php5.6. For more information, please follow other related articles on the PHP Chinese website!