PHP correctly configures MySQL (Apache environment) _php Tips

Source: Internet
Author: User
Write a test of MySQL PHP file is as follows:
Copy Code code as follows:

<?php
$link =mysql_connect (' localhost ', ' root ', ' root ');
if (! $link) echo "Failed!";
else echo "Success!";
Mysql_close ();
?>

Results reported errors: Fatal error:call to undefined function mysql_connect (), obviously unable to find the corresponding library of MySQL, Baidu a lot of, is what copy MySQL Lib library, is also copied to Windows System32 directory, too complex, in fact, the correct configuration should be in the Apache httpd.conf file to add the settings:
Copy Code code as follows:

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'll have to copy the php.ini file to the Windows system directory. In general, we can complete the combination of Apache and PHP through this configuration. And in the php.ini file only need to modify the following several places to:

# Modify PHP's extension library directory for your actual path
Extension_dir = "D:/tools/php-5.3.1/ext"

# Remove the front;
Extension=php_mysql.dll
The final step is to add your PHP installation path to the system environment variable (note the system environment variable, not the user environment variable) path, and after the setup succeeds, the phpinfo () should be available in Apache Environment section of the path can be seen in your PHP installation directory, otherwise the environment variable is not configured successfully (note, configure the environment variable restart Apache).

Complete these steps can be correctly connected to the database, but the premise is that your Apache and PHP integration is normal, and then consider this MySQL configuration, if you can not reach the effect, you may query me, hehe!

To summarize, the correct configuration steps for the integration of Apache and PHP (including MySQL) under Windows platform are as follows:

1, the installation of Apache, and to ensure that Apache can operate independently

2, the PHP (such as 5.2.17 or 5.3.1) to extract the ZIP package to a directory, such as D:\php-5.3.1

3, at the end of the Apache httpd.conf file add the following paragraph:
Copy Code code 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, in the operating system environment variables (must be system variables rather than user variables) in the path to add d:/php-5.3.1 paths

5, the PHP installation directory under the php.ini-dist renamed to PHP.ini, and modify the following:

# Set up PHP's extended file directory
Extension_dir = "D:/php-5.3.17/ext"

# Open the MySQL extension, remove the front;
Extension=php_mysql.dll

After completing the 5 steps above, your PHP will be normal and Apache, and common such as: PHP warning:php startup:unable to load Dynamic Library ..., Fatal Error:call to und efined function mysql_connect () ... Will never be gone! ^_^
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.