PHP correctly configures mysql (apache environment)

Source: Internet
Author: User

Write a PHP file to test mysql as follows: Copy codeThe Code is as follows: <? Php
$ Link = mysql_connect ('localhost', 'root', 'root ');
If (! $ Link) echo "failed! ";
Else echo "successful! ";
Mysql_close ();
?>

The error message is: Fatal error: Call to undefined function mysql_connect (). Obviously, the mysql database cannot be found. Baidu has a lot of errors, it is too complicated to copy mysql lib library and system32 directory to windows. In fact, the correct configuration should be in apache httpd. add the following settings to the conf file:Copy codeCode: LoadModule php5_module d:/tools/php-5.3.1/php5apache2_2.dll
AddType application/x-httpd-php. php
PHPIniDir d:/tools/php-5.3.1

Note that the last line is the key. Tell apache where your php configuration file is, or you have to copy the php. ini file to the windows System directory. Generally, we can use the configuration here to complete the combination of apache and php. In the php. ini file, you only need to modify the following:

# Modify the php extension library directory to your actual path
Extension_dir = "D:/tools/php-5.3.1/ext"

# Remove the previous one;
Extension = php_mysql.dll
The last step is to add your PHP installation path to the system environment variable (note that it is the system environment variable, not the user environment variable) path. After the setting is successful, use phpinfo () you can see your PHP installation directory in the path of the Apache Environment segment. Otherwise, the Environment variable is not configured successfully (note that apache is restarted after the Environment variable is configured ).

After completing these steps, you can connect to the database correctly, but the premise is that the integration of apache and php is normal, and then consider the mysql configuration. If the effect cannot be achieved, you can ask me, huh, huh!

To sum up, the correct configuration steps for integrating apache and php (including mysql) on windows are as follows:

1. install apache and ensure that apache runs properly independently

2. decompress the zip package of php (such as 5.2.17 or 5.3.1) to a directory, such as D: \ php-5.3.1

3. Add the following section at the end of the httpd. conf file of apache:Copy codeThe Code is as follows: # php5 support
LoadModule php5_module D:/php-5.3.1/php5apache2_2.dll
AddType application/x-httpd-php. php
PHPIniDir D:/php-5.3.1

4. Add D:/php-5.3.1 path to the path of the operating system environment variable (must be a system variable instead of a user variable)

5. Rename php. ini-dist in the php installation directory to php. ini and modify the following content:

# Set the php extension file directory
Extension_dir = "D:/php-5.3.17/ext"

# Enable mysql extension and remove the preceding annotations.
Extension = php_mysql.dll

After completing the above five steps, Your php will work properly with apache, and common examples include: PHP Warning: PHP Startup: Unable to load dynamic library ...... , Fatal error: Call to undefined function mysql_connect ()...... And it will be gone forever! Pai_^

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.