This post is about getting MySQL working with Apache/PHP because sometimes it can be a pain to get it working.
If you are having trouble getting PHP working with Apache, Nurlan has found a good guide to using the PHP MSI install wizard. You can find it at http://foundationphp.com/tutorials/php_installer.php
Before You Begin
- Read carefully
- Keep backups of the files you change (before you change them)
- Some long lines of text may run off the page, so you need to copy the whole line down correctly
Downloading & Installinghttp://httpd.apache.org/
Download the apache 2.2.8 installer (I used the one with SSL) and install it, I’ve installed to c:\apache2.2. You can run it from the start menu.http://php.net/
Download the PHP 5.2.6 zip (I used the no-msi zip) and extract it. You don’t want spaces in the path, so I suggest C:\php5.2.6.http://www.mysql.com http://dev.mysql.com/downloads/gui-tools/5.0.html
Download MySQL 5.01 try the x64 version if you have an x64 OS. I installed to C:\mysql5 because I didn’t use the installer. It will work just as well if you use the install wizard. Once installed, you can use the mysql monitor, which appears in the system tray (next to the clock) to start/stop the sql server.
Try the MySQL GUI tools, which are nice. You can login using the mysql administrator, so you can setup usernames etc. You can edit schema (databases) and tables etc. using the Query Browser, it’s pretty straight forward to use.
Configuring Apache to use PHP
I like to make it obvious where I’ve made changes to files, so I can easily see them later. I do this by putting long comment lines above and below the changes.
Go into httpd.conf. find the bunch of LoadModule lines and add this one.
LoadModule php5_module C:/php5.2.6/php5apache2_2.dll
So In my file it looks like this
#++++++++++++++++++++++++++++++++++++ # Last changed on 28 July 2008. # This line enables the PHP module LoadModule php5_module C:/php5.2.6/php5apache2_2.dll #++++++++++++++++++++++++++++++++++++
Add this line as well (i put it after the loadmodule line)
ZAUR left a useful comment on 29th June 2008. He mentions that it’s important not to have quotes around your path in this line. Thanks Zaur.
Find the bunch of AddType lines and add this one
AddType application/x-httpd-php .php
Configuring PHP to use MySQL
Go into C:\php5.2.6 and copy the file called php.ini-recommended, paste it into the same folder and rename it to php.ini. So you have a duplicate of php.ini-recommended called php.ini.
Find and edit the following lines;
doc_root = "C:\Apache2.2\www" extension_dir = "C:\php5.2.6\ext"
uncomment this line (take the ‘;’ character out)
Now restart apache, everything should be working. You can check up on php by using the phpinfo() function. Just put the following line into a file eg phpinfo.php and place it in your htdocs folder:
<?php phpinfo(); ?>
If php is running, it will give you a page with lots of information. Look for the mysql section, it comes after PHP Credits, Configuration, PHPCore etc. If it isn’t there, that means PHP is running but MySQL isn’t playing ball.
Check all the edits you’ve made the the config files, make sure they all make sense, sometimes you put the wrong slashes in, or the wrong folder name and it’s very hard to spot.
If you get the following error message:
‘unable to load C:\php5.2.6\ext\php_mysql.dll’
This is the most frustrating part of getting mysql working. PHP won’t run the mysql extension and you have to do stupid things to get it to work!
Copy C:\php5.2.6\libmysql.dll to c:\windows\system32\ and restart apache
IF YOU ARE USING WINDOWS XP x64 and moving the file to system32 doesn’t work, move it to C:\WINDOWS.
These guys have a suggestion. When copying libmysql, andy23 says:
Copy file libmysql.dll in C:\php5.2.6 to C:\apache2.2\bin\ AND C:\windows\system32
Hopefully, this will have got your servers up and running. Go ahead and try out wordpress, joomla, osCommerce etc.
If you find you can’t login to the mysql server, check my mysql posts with instructions on how to setup mysql user accounts.
Thanks to all the people contributing their time to Open Source projects. And thanks to you for reading, comments are welcome.