Home >Backend Development >PHP Problem >How to install php mysql extension
php mysql extension installation method: first enter the ext/mysql directory of the php source code; then run phpize and run configure; then compile and install to generate mysql.so; finally modify the php.ini file and add mysql.so Just expand the configuration.
Recommended: "PHP Video Tutorial"
PHP Installation mysql.so Extension
The mysql_connect module in PHP has been gradually deprecated. I did not install the mysql extension when setting up the environment, but today when I was maintaining an old project, an error occurred.
Fatal error: Uncaught Error: Call to undefined function mysql_connect()
So I googled it. It is found that if php and mysql have been installed, you can use the phpize tool to manually compile and generate the mysql.so extension to solve the problem.
The following are the steps:
1. Enter ext/mysql of the php source code Directory
cd /usr/local/src/php-5.6.29/ext/mysql/
2. Run phpize and generate a configure file in this directory (php installation directory: /usr/local/php/)
/usr/local/php/bin/phpize
3. Run configure and specify php-config File location (/usr/local/php/bin/php-config) and mysql installation directory (/usr/local/mysql/)
./configure --with-php-config=/usr/local/php/bin/php-config --with-mysql=/usr/local/mysql/
4. Compile and install, generate mysql.so
make && make install
5. Modify the php.ini file, add the mysql.so extension configuration, save and exit
extension=mysql.so
6. Restart php-fpm
service php-fpm restart
7. Test and add the php file in the web directory , such as /usr/local/nginx/html/mysql.php
Copy code
<?php $con = mysql_connect('localhost','root',''); if($con){ die('ok'); }else{ die('Could not connect: ' . mysql_error()); }
Access URL, such as: http://192.168.8.9/mysql.php
If ok is displayed, the configuration is successful
The above is the detailed content of How to install php mysql extension. For more information, please follow other related articles on the PHP Chinese website!