How to install php mysql extension

藏色散人
Release: 2023-03-07 10:38:01
Original
2951 people have browsed it

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()
Copy after login

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/
Copy after login

2. Run phpize and generate a configure file in this directory (php installation directory: /usr/local/php/)

/usr/local/php/bin/phpize
Copy after login

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/
Copy after login

4. Compile and install, generate mysql.so

make && make install
Copy after login

5. Modify the php.ini file, add the mysql.so extension configuration, save and exit

extension=mysql.so
Copy after login

6. Restart php-fpm

service php-fpm restart
Copy after login

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());
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template