2.8. Troubleshooting

This section describes some common problems encountered with the installation of PHP.

Figure 2-4. MySQL settings.

2.8.1. Unable to change PHP settings

If you change settings in your php.ini file but the changes don't seem to have the expected effect on PHP operations, one of two things is probably the cause:

  • You didn't restart the Web server. If that's the case, just restart the Web server so that the changes will go into effect.

  • You might not be editing the php.ini file in the location where PHP is reading it. You can check which php.ini file PHP is reading. You might have more than one php.ini file or you might have it stored in the wrong location. When you test PHP using the phpinfo() statement, as shown in the "Testing PHP" section, PHP outputs many variable values and settings. One of the settings close to the top is Configuration File Path, which shows the path to the location where PHP is looking for the configuration file. If the path ends in a filename, that's the file PHP is using for its configurations. If the path ends in a directory name, PHP is looking in the directory for the configuration file but can't find it, so PHP is using its default configurations.

2.8.2. Displays error message: Undefined function

You might see an error message stating that you called an undefined function. This message means that you're calling a function that PHP doesn't recognize. You might have misspelled the function name, or you might be calling a function in an extension that isn't activated.

You might see an error message complaining of a mysql function, similar to the following:

Fatal error: Call to undefined function mysqli_connect()

This means that MySQL support isn't activated for the mysqli functions. Either you didn't activate any MySQL support or you activated the mysql extension, rather than the mysqli function.

2.8.2.1. Windows

If MySQL support isn't activated, either the extension line in php.ini is not activated or PHP cannot find the necessary files. Check the extension line in php.ini to be sure the semicolon is removed from the beginning of the mysqli extension line. If php.ini looks correct, you might have forgotten to restart the Web server after making the change. You can also try stopping the Web server completely and then starting it, rather than restarting it. And finally, you might be editing the wrong php.ini file. Make sure the php.ini file you're editing is in the location where PHP is looking for it, as shown in the output from phpinfo().

Check that the directory where php_mysql.dll and libmysql.dll are located is in your system path. You can check your path in the output from phpinfo(). The Environment section toward the end of the output shows the path. However, the path shown is not the path that's currently in effect unless you restarted the system after changing the path. When you change the path, the new path is displayed, but it doesn't actually become active until you restart the system.

2.8.2.2. Linux or Mac

You did not activate a mysql extension when you installed PHP. When installing PHP 5 or 6, you must use one of the MySQL options in Step 4 (the configuration step) of the installation.

2.8.3. MySQL functions not activated (Windows)

When you look at the output from phpinfo(), you don't see a section for the mysql or mysqli extension. However, in your php.ini file, one or both of the extensions are activated. Some possible causes are

  • You didn't restart your server after changing your settings in php.ini.

  • You're editing the wrong php.ini file. Check the phpinfo() output for the location of the file that PHP is reading the settings from.

  • The necessary .dll files are not in a directory that is specified in your system path.

  • The MySQL .dll files that PHP is reading are for a different version of PHP. Sometimes when you update PHP, you don't replace the .dll files with the new .dll files. For instance, suppose you're running PHP 5.0 and the php_mysqli.dll file is located in c:windowssystem32. You upgrade to PHP 6.0. You copy the .dll file from ext to the main PHP directory and add c:php to the end of your system path. However, you forget to remove the old .dll file from its current location. When PHP starts, it encounters the old .dll file first, because the system32 directory is first in the system path, and PHP tries to use the old file. Because it can't use the old file, PHP doesn't activate the mysqli extension. This can be extremely confusing, speaking from painful experience.

2.8.4. Displays a blank page or HTML output only

When you look a Web page in your browser and a blank page displays or only the HTML output displays, the Web server isn't sending the PHP code to PHP for processing.

You might not be viewing the Web page through the Web server. You can't open the Web page by selecting FileOpen Page in your browser menu. You must type the URL to the page, such as localhost/test.php, in the browser address window.

You might not have your Web server configured correctly for PHP. Check the section "Configuring Your Web Server for PHP," earlier in this chapter. Double-check that the Apache directives are typed correctly and in the correct location. Be sure to restart the Web server after making any changes.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.0.159