Home >Backend Development >PHP Problem >How to install php mysql extension

How to install php mysql extension

藏色散人
藏色散人Original
2020-11-05 10:54:143001browse

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.

How to install php mysql extension

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(&#39;localhost&#39;,&#39;root&#39;,&#39;&#39;);
if($con){
    die(&#39;ok&#39;);
}else{
    die(&#39;Could not connect: &#39; . 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!

Statement:
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