Linux adds MySQL to compiled PHP (PHP is compiled to add MySQL extensions).

Source: Internet
Author: User
Tags mysql client php source code

Issue background:

Under normal conditions Lamp installation order is:

linux-> apache-> mysql-> PHP

PHP If you want to connect to MySQL at compile time need to use the MySQL header files and library files.


PHP to connect Mysql need to use mysql.so extension in PHP engine, at this time, the first installation of PHP, when compiling PHP, Mysql has not been installed, so at this point need to manually compile build mysql.so extension;


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6B/69/wKiom1UsrueDnW99AADStwWroGw612.jpg "title=" 1111. PNG "alt=" wkiom1usruednw99aadstwwrogw612.jpg "/>



Solution:

You can use the Phpize tool to generate mysql.so, but you must add the path to the--with-mysql=mysql client. That is, the mysql.so module must be used by the MySQL client.

As you can see, the mysql.so internally calls the MySQL client to implement a connection to the MySQL database server.

The mysql_connect () that we often use may be the one that calls the MySQL client to complete the connection to the database.


To generate the mysql.so process:

PHP is required to use the source package, through the source package provided in the Phpize file (a special link to php extension tools)

Phpize rule: in which directory the Phpize tool is used, the Configure file is generated in which directory.


Note: The autoconf tool needs to be installed;

[Email protected]:/# apt-get Install autoconf <-ubuntu installation Method

[Email protected]:/# yum Install autoconf <-centos installation Method


Installation steps:

1. Enter PHP source code directory

[Email protected]:/# cd/root/php-5.3.27/


2. Enter the extension directory

[Email protected]:~/php-5.3.27# cd Ext/mysql


3. Call the compiled PHP executable phpize generate the Configure file:

[Email protected]:~/php-5.3.27/ext/mysql#/usr/local/php/bin/phpize

# # # # # # # # # # # # # # Configure/root/php-5.3.27/ext/mysql/ # # # Cannot find autoconf. Please check your autoconf installation and the

# # # $PHP _autoconf environment variable. Then, rerun the this script.

# # # appears here error is not installed autoconf tool, according to the above method to install;  

4. Execute the Compile command:

./configure--with-php-config=/usr/local/php/bin/php-config \

--with-mysql=/usr/include/mysql--with-zlib-dir=/usr/lib/mysql

# # You need to install a separate header and library file in Ubuntu apt-get install Libmysqlclient-dev

Note:--with-mysql is used to specify the MySQL header file location;

--with-zlib-dir used to specify the location of Mysql library files;

Make && make install

a directory is output after successful compilation:

Installing shared extensions:/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/

# # This directory is the PHP extended dynamic Inventory put directory, the compilation will be successful after the mysql.so into this directory;


5. Modify the PHP configuration file:

Note: The module name that you just generated is called mysql.so (you can go to the extension directory with LS view), and php.ini This profile is called msql.so, you must change the PHP configuration file so that the module name referred to in the configuration file has the same name as the generated module;

Vim/etc/php/php.d/php.ini

Extension=mysql.so <<<-here about 944 rows or so;


6. Restart Apache:

/usr/local/apache/bin/apachectl Restart <<-installation methods are different, the restart method is different.


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/6B/69/wKiom1UsufSAZ5zUAAKqLzg6WM4816.jpg "title=" 321321.png "alt=" Wkiom1usufsaz5zuaakqlzg6wm4816.jpg "/>


Finally, two pieces of PHP detection code are attached:

Test if PHP is working properly:

<?php phpinfo (); ?>


Test PHP connection MySQL is normal:

<?php $link =mysql_connect (' 127.0.0.1 ', ' root ', ' 123456 '); if (! $link) echo "Connect error!"; else echo "connected!"; Mysql_close ();?>

# # # Success will output "connected!", Failure will output "connect error!" ;

This article is from "the days when those tumultuous left." "Blog, be sure to keep this provenance http://linuxzj.blog.51cto.com/6160158/1632150

Linux adds MySQL to compiled PHP (PHP is compiled to add MySQL extensions).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.