Note: This proper Configuration will solve any of the following errors below:
- PHP ERROR "Undefined function mysql_connect()".
- test.php or phpinfo.php page not displaying or showing as a blank page the monitor screen.
- Configuration File (php.ini) Path: c\windows | Loaded Configuration File:(none) not showing the correct installation path to the php.ini (showing as none)
- Error with PHP.INI path location in the test.php or phpinfo.php page, "Configuration File (php.ini) Path from".
Note: If you follow each single step in this tutorial you should not have to move any files to C:\WINDOWS or C:\WINDOWS\system32, yes you heard me right! After hours of searching forums trying everything suggested I found I was following fake prophets. So don't pay attention to those self proclaim gurus in those forums, they are just throwing punches in the air without ever hitting the target.
MY Machine is using: Apache Server 2.2.6, Windows XP SP2, PHP 5.2.5, MYSQL SERVER 5.0
1. Make Sure you downloaded the right PHP zip file from www.php.net for Apache configuration download PHP 5.2.5 zip package:
Visual Example:
2. Unzip the PHP 5.2.5 zip package in the root (for newbies: root means at top level of your hardrive not inside a folder). I am using hardrive E: so I unzipped it there:
Visual Example:
3. Make a copy of the file php.ini-dist and rename it php.ini. Also put brackets around the php.ini-dist. I put place brackets around this just as a pre-caution to avoid Apache server from reading it. In actuality it should not because of the hyphen and the dist but just in case.
Visual Example:
4. Configuration of Apache http.conf file:
- Go the your Apache Installation folder > conf folder > Double click on httpd.conf. On my computer the path is: E:\Program Files\Apache Software Foundation\Apache2.2\conf on your computer the path may be different.
- Add the lines below at the bottom of your http.conf file: ( # sign means comments in the http.conf file, comments are not read by the Apache server).
# TELLS APACHE SERVER WHERE THE PHP DLL FILE FOR YOUR APACHE VERSION IS LOCATED.
LoadModule php5_module "e:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
# Tells APACHE SERVER WHERE YOUR PHP.INI FILE IS LOCATED.
PHPIniDir "E:/PHP"
Warning: ALL LINE ENTRIES TO THE APACHE HTTP.CONF FILE SPECIFING A FOLDER PATH SHOULD USE FORWARD SLASH ( / ). An example is below, notice in the httpd.conf all paths are using the forward slash which is different from the path shown in the explorer windows.
Visual Example:
5. Configuration of the PHP.INI to use MYSQL: By default on PHP 5 mysql drivers are disabled, follow the steps below to enable them.
- Go PHP folder installation > Double click on PHP.INI file, on my computer it is: E:\PHP
- Once the PHP.INI file is open, search for extension_dir and enter the line below with the location where the mysql driver php_mysql.dll is located. In php 5 by default the folder containing mysql drivers is called EXT.
extension_dir = "E:\php\ext"
Warning: All Path Location entries to the PHP.INI SHOULD USE BACK SLASH ( \ ). Also make sure the entry does not have a semi colon ( ; ) in front of the line otherwise it will be read as comment.
Visual Example:
- Search down in the PHP.INI file for extension=php_mysql.dll, extension=php_mysqli.dll and remove the semi-colon ( ; ) in front of them and save the changes to the PHP.INI file.
Visual Example:
- Restart the Apache Server: go to Start menu > All programs > Apache HTTP Server 2.2.6 > restart.
Visual Example:
6. CREATING test.php or phpinfo.php: TEST.PHP and PHPINFO.PHP are the same thing, it is just the name that you wish to assign to the function <? phpinfo( ); ?> when you save it.
- Open notepad and type the line below .
<? phpinfo(); ?>
- Save the notepad as test.php or phpinfo.php in the htdocs folder inside your apache installation, on my computer: E:\Program Files\Apache Software Foundation\Apache2.2\htdocsz
Visual Example:
- Restart the Apache Server: go to Start menu > All programs > Apache HTTP Server 2.2.6 > restart.
7. Type the following URL in your browser http://localhost/phpinfo.php. If you did all the 5 steps above correctly you should see the page below:
Visual Example:
Extremely Important: pay attention to the 2 values below in your test.php or phpinfo.php page.
Configuration File (php.ini) Path E:\WINDOWS
//comment: Configuration File (php.ini) Path this is where Apache expects the PHP.INI file to be by default but it does not have to be here E:\WINDOWS or C:\WINDOWS
Loaded Configuration File E:\PHP\php.ini
//comment: Loaded Configuration File is the Folder location where Apache is really loading the PHP.INI file from your computer. This has to match the location that you added to the HTTPD.CONF file in step 4. Example: PHPIniDir "E:/PHP"
8. TROUBLESHOOTING ERRORS:
- TEST.PHP or PHPINFO.PHP NOT DISPLAYING: if a blank test.php or phpinfo.php page is loaded to your browser without displaying error is because you created these pages using the PHP Short hand <? ?> ex: <? phpinfo( ); ?> .
SOLUTION:
- To correct this problem use the complete PHP hand <?php ?> in your test.php or phpinfo.php page. Example of the complete syntax: <?php phpinfo( ); ?>
- PHP 5 by default turns off the PHP short hand <? ?>. You can turn on the short hand by going to you PHP.INI file, if you wish to use the short hand notation/syntax in your coding.
Visual Explantion:
- MYSQL Connection ERROR mysql_connect()" : below I explain the steps that apache takes to load the PHP.INI file and how the PHP.INI tells apache where mysql drivers are located.
- Apache first look for the PHP.INI in the path location that you specify using PHPIniDir. Make sure your PHP.INI file is this location.
- Double checking PHP.INI:
Tells apache to include the folder where mysql driver resides.
which drivers to load from that folder (do not forget to remove semicolon in front of it ;)
Note: Make sure the drivers are in the folder you specified in the PHP.INI file section "extension_dir "
- To make sure your PHP.INI file is configured correctly double click on the php.exe in your PHP folder. If you PHP.INI configuration is not correct you will see an error when PHP.EXE tries to launch, if you do not see an error just a black screen PHP.INI is working properly you can close the PHP.EXE window.
- Finally make sure the Test.php or PHPINFO.PHP is displaying the right location of your PHP.INI file.
Note: this is the most important part of the Mysql, PHP and APACHE configuration that the php.ini file is getting loaded from the right location
Personal Comments: I come from the microsoft house and I am trying to make the transition to Open Source House. My fiance' and I spent hours troubleshooting why php.ini file was not getting loaded from the right location, why "Undefined function mysql_connect()" error kept popping up but no forum including those from respected websites like www.mysql.com, www.php.net, www.phpfreaks.com/ were any help to us. We also wondered when we did try certain changes suggested the phpinfo page was showing up blank. I am very disappointed at these forums for failing to explain in detail how to solve this problem. Many of the people in these forums gave bits and pieces but never good explanations to solve the puzzle. This is very unfortunate for the Open Source community in its competion with microsoft. Nobody in the microsoft house wants to spent as many hours as we had to, reading through documentation, forums that do a poor job for explaining the installation process etc. We all want to spent time building applications and having our projects done within the dead lines.
Note: If you followed each single step in this tutorial you do not have to move any files to C:\WINDOWS or C:\WINDOWS\system32, yes you heard me right don't pay attention to those self proclaim gurus in those forums, they are just throwing punches to the air without ever hitting the target.
Sign Guestbook
View Guestbook