Php can be normally combined with apache, and common examples include: PHP Warning: PHP Startup: Unable to load dynamic library ...... Fatal error: Call to undefined function mysql_connect () error
However, when I got a CMS, I still encountered an unforgivable error. I couldn't connect to mysql. I wrote a PHP file to test mysql as follows:
The Code is as follows: |
Copy code |
<? 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:
The Code is as follows: |
Copy code |
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
The Code is as follows: |
Copy code |
Extension_dir = "D:/tools/php-5.3.1/ext" |
# Remove the previous one;
The Code is as follows: |
Copy code |
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:
The Code is as follows: |
Copy code |
# Php5 supportLoadModule php5_module D:/php-5.3.1/php5apache2_2.dll |
The Code is as follows: |
Copy code |
AddType application/x-httpd-php. php |
The Code is as follows: |
Copy code |
PHPIniDir D:/php-5.3.14 |
, 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
The Code is as follows: |
Copy code |
Extension_dir = "D:/php-5.3.17/ext" |
# Enable mysql extension and remove the preceding annotations.
The Code is as follows: |
Copy code |
Extension = php_mysql.dll |