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, one reader called Nurlan has found a 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 (make a copy before you change them)
- Some long lines of text may run off the page on this website, so you need to copy the whole line down correctly
Downloading & Installing
http://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 and extract it (I used the no-msi zip). You don’t want space characters in the path, so I suggest C:\php5.2.6.
http://www.mysql.com http://dev.mysql.com/downloads/gui-tools/5.0.htmlDownload MySQL 5.01. 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. 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)
PHPIniDir C:/php5.2.6/
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)
extension=php_mysql.dll
Troubleshooting
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 called something like 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.
andy23 http://my.opera.com/andy23/info/galoabk http://my.opera.com/galoabk/info/
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.
Tnx a lot bro 4 ur help….
Man, you have saved my day… I spent 4 days trying to make my php work with mysql and nothing worked… you can find out a lot of webpages and forums with people having this same problem, but no solution is given. Your solution fit exactly for me, I’ll go to some foruns and link to your page ok? Once again, thanks a lot!
Ari
Thanks for your comments!
I know exactly how you feel, and i’m glad this post has been useful.
Feel free to link or copy or whatever you want to do.
I’ve installed apache+php+mysql a few times, but remembering how to fix all the problems is hard! So I made this page, for my own reference as well as everyone else.
Thank You so much … I was having problems with the Apache 2.2.x and PHP5.2.x working together and your post fixed everything.
Thank you again.
Thank You!
When you use PHPIniDir directive in Apache config it’s important NOT to enclose php path in double quotes.
thanks alot for your article sir it helped me alot
i was getting trouble configuring it for sql :)
thanks alot :)
Hey cyleft…
i followed ur every step… but at last when i tried to run info.php () all apache gave me was index page (directory index)..
seems like php is not responding…. anyway i can fix this?…
my apache path is “H:\Program Files (x86)\Apache Software Foundation\Apache2.2”
my php path is “H:\php”
my mysql path is “H:\Program Files (x86)\MySQL\MySQL Server 5.0”
do you think this has anything to do with the paths having spaces?
Yes! Try using a path without spaces
my phpinfo.php did not work. I have tried all the suggestions but none of them helped. Including this one. But this site was very useful: http://foundationphp.com/tutorials/php_installer.php
very simple!
hi. just posting a quick reply to nurlan who, on 27 July 2008 GMT asked about php.ini-recommended. If you extracted php 5.2.6-win32-no-msi.zip, you should be able to find a file called ‘php.ini-recommended’ in the same folder where you find ‘php.exe’. you can copy this file, and rename it to ‘php.ini’, so if you make a mistake, you can start again from ‘php.ini-recommended’.
There is also another file in there that you can use called ‘php.ini-dist’. If you already have a file called php.ini, then you can edit that one instead.
Thanks for the link to foundationphp.com, that looks like a very useful tool, I’ll stick that link at the top of the post.
Good job man. I’ve been pulling out what little hair I had left until finding this solution.
Thanks bro ….
Just want to thank you for taking the time to write such a clear, concise and effective blog on configuring a WAMP environment. I have read 15 other articles or so and could not get apache to recognise the mysql extensions. this is all working for me now in one go after uninstalling and following your instructions one by one. Thanks again. Claire
thanks man, one of the most well written articles…
Hi,
andy23 http://my.opera.com/andy23/info/
galoabk http://my.opera.com/galoabk/info/
These guys have also found a solution to the mysql problem. When copying libmysql, andy23 says:
>> copy file libmysql.dll in C:\php5.2.6 to C:\apache2.2\bin\ AND C:\windows\system32
hope this helps
thank you for your help tried many different sites. your the best
Hi cyleft,
Thank you for your detailed information. I have tried several ways and all were vain attempts. Fortunately i came across Ur article, which helped me to connect to MySQL.
Though i see a mysql_error as Host ‘{ipaddress}’ is not allowed to connect to this MySQL server. I felt good that ur article helped me in connecting to mysql.
Thanks Much
Hello Kalyani. I think the error message ‘Host{ipaddress} is not allowed’ probably means that you are trying to login with a username that is only allowed to login from a certain IP addresses.
I have made a separate post which shows you how to add users with IP addresses here
Thank You, Thank You, Thank You.
am impressed!! Thanks!!!
Awesome Work!!
Maybe you could change the post title Installing Apache 2.2 PHP 5.2 MySQL 5 on Windows 32bit or x64 Cyleft’s Blog to something more generic for your content you write. I loved the blog post nevertheless.
Good idea!
Thanks for the effort, but none of this works. I am into my 3rd day trying to get this to work and may have no option but to use IIS.
Any othetr suggestions than what has been posted here.
Thanks
Sorry Beuford, you may want to get an experienced person to look at your setup. Hope IIS works for you, I think it’s easier to install at least!
Noroc Uite o intrebare rapida la voi. Recoamndati externalizarea de servicii IT ? Sau e mai indicat sa le rezolvam noi cu un inginer IT sau mai multi ?