TUTORIAL: How to install PHP and MySQL on IIS

  • one2one
  • Novice
  • Novice
  • one2one
  • Posts: 24
  • Loc: Lancaster, PA

Post 3+ Months Ago

nice tutorial.

I have an interesting problem and since you seem to have been really great in answering these fine people's questions, i thought I might pose it to you.

windows 2k3 standard server running iis = works fine
php is installed and working great.
mysql is installed on another server in the same domain and it is working great

i want to link the php install on the php machine to the mysql install ont he mysql machine.

i have the mysql.default_host = 192.168.1.141 (the server's ip on the network, i have also tried it's hostname) but when i open my test.php file to see what's installed and working in php, it does not list mysql at all.

ultimately i want to use phpmyadmin to manage the mysql install, but since my server running php can't see mysql, that isn't going to work yet.

so besides installing php on the mysql server, is there a way to get this setup to work?
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23458
  • Loc: Woodbridge VA

Post 3+ Months Ago

Never done that but just a hunch, you probably need to include the port msySQL is using, example 192.168.1.141:3306
  • one2one
  • Novice
  • Novice
  • one2one
  • Posts: 24
  • Loc: Lancaster, PA

Post 3+ Months Ago

tried that, no dice. hmmm... i might try installing php on the mysql server just to ensure that that local installation can find the mysql using localhost.

I am having a hard time finding any documentation on how to troubleshoot a remote mysql connection like this though online.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23458
  • Loc: Woodbridge VA

Post 3+ Months Ago

Looks like this is how.
http://www.cyberciti.biz/tips/how-do-i- ... erver.html

Although the instructions assume a linux install, it looks like it should be relatively similar for Windows. I'll see if I can find a Windows version.


This guy got it to work in Windows:

http://forums.techguy.org/development/6 ... ccess.html
  • one2one
  • Novice
  • Novice
  • one2one
  • Posts: 24
  • Loc: Lancaster, PA

Post 3+ Months Ago

thanks for the info, I tried what that guy said, but there's no change.

I am wondering if what I am trying to accomplish is even worth it...

I have a database server i wanted to use for all of my SQL and MySQL dbs and an IIS server that would run websites with various languages like asp, php, etc. I was hoping that the php would link to MySQL on the other server to keep things uniform like that so I wouldn't have to put the MySQL dbs on the IIS server.

does this sound like a waste of time to you?

I kind of find it odd that I can't just define that mysql is at that specific location and php wouldn't jsut communicate with it, but then again, i am not an expert so...
  • one2one
  • Novice
  • Novice
  • one2one
  • Posts: 24
  • Loc: Lancaster, PA

Post 3+ Months Ago

update: interesting twist to the issue. on a hunch i tried to telnet from the IIS server to the database server on port 3306. it doesn't allow it. so there may be hope yet and it may lie in permissions. I'll keep digging and let you know.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23458
  • Loc: Woodbridge VA

Post 3+ Months Ago

Check to make sure Window's firewall is NOT on. It will block it. I was reading a post yesterday with the same issue and all it was was the firewall. Once that was disabled everything worked peachy. (Sorry, had to leave quickly and didn't get to post or bookmark the page). If you use a 3rd party Firewall, make sure your Web Server is permitted.

Also if you use MySQL Administrator, log into it as root or an admin account and on the Startup section, General tab make sure "Disable Networking" is not checked. If it is, uncheck it and restart MySQL.
  • one2one
  • Novice
  • Novice
  • one2one
  • Posts: 24
  • Loc: Lancaster, PA

Post 3+ Months Ago

both servers are win2k3 standard, neither using any firewall. local router with firewlal on it allows all lan to lan traffic. i think i originally configed this instance of MySQL with remote connection disabled. i am attempting to remove it and readd it with remote connection enabled.
  • one2one
  • Novice
  • Novice
  • one2one
  • Posts: 24
  • Loc: Lancaster, PA

Post 3+ Months Ago

did that. now telnet works. it didn't automatically show up in my php file, but i'll try some things and see what i can come up with. i really think this is supposed to be able to work.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23458
  • Loc: Woodbridge VA

Post 3+ Months Ago

Yes it should work. I've just never done it so I'm guessing here.

In your php.config.ini how does this line read?

$cfg['Servers'][$i]['host'] = 'localhost';
  • one2one
  • Novice
  • Novice
  • one2one
  • Posts: 24
  • Loc: Lancaster, PA

Post 3+ Months Ago

$cfg['Servers'][$i]['host'] = '192.168.1.141';

that's the ip of the database server

to tell you the truth though i am not even looking at phpmyadmin because php doesn't list mysql or when you do a

<?php
phpinfo();
?>

i am assuming that this issue needs to be fixed first and then phpmyadmin will fall into line after that.

i just don't get what i am missing.

I have extension=php_mbstring.dll and extension=php_mysql.dll unquoted in php.ini

extension_dir = ".\ext"

mysql.default_host = 192.168.1.141

the path to the php directory is set in windows... I'm not sure what else can be edited.

I also went to mysql and ran a
GRANT ALL PRIVILEGES ON *.* TO USERNAME@IP IDENTIFIED BY "PASSWORD"; supplying my root username and password to it.

thoughts?
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23458
  • Loc: Woodbridge VA

Post 3+ Months Ago

probably won't make a difference, but try adding the default port 3306 here around line 690

; Default port number for mysql_connect(). If unset, mysql_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order). Win32 will only look
; at MYSQL_PORT.
mysql.default_port =


remember after making any changes to php.ini you should reboot. I've driven myself nuts over issues that I fixed but didn't realize I had until after I rebooted.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23458
  • Loc: Woodbridge VA

Post 3+ Months Ago

Also from http://php.ftp.cvut.cz/manual/en/ref.mysql.php Try this I found in one of the comments:

PHP Code: [ Select ]
<? php
 
Following PHP Script is useful to test PHP connection with MySQL.
 
*/
 
 
 
//$connect = mysql_connect("Your Host Name", "MySQL root directory", 'MySQL password, if any');
 
//$connect = mysql_connect("Host Name or Address - 127.0.0.1", "root", 'password');
 
$connect = mysql_connect("localhost", "root", 'password');
 
if ($connect){
 
echo "Congratulations!\n<br>";
 
echo "Successfully connected to MySQL database server.\n<br>";
 
}else{
 
$error = mysql_error();
 
echo "Could not connect to the database. Error = $error.\n<br>";
 
exit();
 
}
 
 
 
// Closing connection
 
$close = mysql_close($connect);
 
if ($close){
 
echo "\n<br>";
 
echo "Now closing the connection...\n<br>";
 
echo "MySQL connection closed successfully as well.\n<br>";
 
}else{
 
echo "There's a problem in closing MySQL connection.\n<br>";
 
}
 
exit();
 
?>
  1. <? php
  2.  
  3. Following PHP Script is useful to test PHP connection with MySQL.
  4.  
  5. */
  6.  
  7.  
  8.  
  9. //$connect = mysql_connect("Your Host Name", "MySQL root directory", 'MySQL password, if any');
  10.  
  11. //$connect = mysql_connect("Host Name or Address - 127.0.0.1", "root", 'password');
  12.  
  13. $connect = mysql_connect("localhost", "root", 'password');
  14.  
  15. if ($connect){
  16.  
  17. echo "Congratulations!\n<br>";
  18.  
  19. echo "Successfully connected to MySQL database server.\n<br>";
  20.  
  21. }else{
  22.  
  23. $error = mysql_error();
  24.  
  25. echo "Could not connect to the database. Error = $error.\n<br>";
  26.  
  27. exit();
  28.  
  29. }
  30.  
  31.  
  32.  
  33. // Closing connection
  34.  
  35. $close = mysql_close($connect);
  36.  
  37. if ($close){
  38.  
  39. echo "\n<br>";
  40.  
  41. echo "Now closing the connection...\n<br>";
  42.  
  43. echo "MySQL connection closed successfully as well.\n<br>";
  44.  
  45. }else{
  46.  
  47. echo "There's a problem in closing MySQL connection.\n<br>";
  48.  
  49. }
  50.  
  51. exit();
  52.  
  53. ?>
  • one2one
  • Novice
  • Novice
  • one2one
  • Posts: 24
  • Loc: Lancaster, PA

Post 3+ Months Ago

ATNO/TW wrote:
probably won't make a difference, but try adding the default port 3306 here around line 690

; Default port number for mysql_connect(). If unset, mysql_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order). Win32 will only look
; at MYSQL_PORT.
mysql.default_port =


remember after making any changes to php.ini you should reboot. I've driven myself nuts over issues that I fixed but didn't realize I had until after I rebooted.


tried both, no change.

tried the php connect script but for some reason it is erroring out with unexpected T_VARIABLE
  • one2one
  • Novice
  • Novice
  • one2one
  • Posts: 24
  • Loc: Lancaster, PA

Post 3+ Months Ago

wow...

i found the fix...

Add the following registry keys:

HKEY_LOCAL_MACHINE\SOFTWARE\PHP\5\IniFilePath -> c:\php5

that is... really... out there...

i'll see if i can get phpmyadmin working next.
  • one2one
  • Novice
  • Novice
  • one2one
  • Posts: 24
  • Loc: Lancaster, PA

Post 3+ Months Ago

phpmyadmin works great now.

awesome!

thanks alot for your help. I'll check out the rest of the forum and see whatelse is cooking around here :)
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23458
  • Loc: Woodbridge VA

Post 3+ Months Ago

Interesting solution. Where is your php.ini located? I just assumed it was in C:\Windows. Regardless Glad you got it.
  • one2one
  • Novice
  • Novice
  • one2one
  • Posts: 24
  • Loc: Lancaster, PA

Post 3+ Months Ago

D:\PHP5

i added that to the system variables path in windows... i thought that would be enough.. aparently the reg key is needed in my case.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23458
  • Loc: Woodbridge VA

Post 3+ Months Ago

good to know. I'm sure down the road someone else will be playing with the same thing and benefit from the solution. (probably me *lol). Thanks for letting us know how you did it. For the record for those reading in the future, if you use the Windows Installer, php.ini will be installed in C:\WINDOWS and the environment variable path set correctly for PHP. However a manual install won't do that, and you should copy php.ini and place it in the Windows directory.
  • communications_warren
  • Born
  • Born
  • communications_warren
  • Posts: 1

Post 3+ Months Ago

Hey ATNO/TW, thanks for the superb tutorial on installed PHP and MySQL on Windows Server 2003 with IIS. I'm new here and truly new to IIS. My situation is, I have PHP installed, it is running, I have MySQL installed (MySQL Admin reports that is it also running. My issue, I am not having any success at getting the two scripts to talk to each other.

I am installing Joomla 1.0.13 (Stable) on that particular server and this is the confirmation screen data:

PHP version >= 4.1.0 Yes
- zlib compression support Available
- XML support Available
- MySQL support Unavailable
configuration.php Writeable
Session save path Unwriteable
Not set

MySQL Support - unavailable, why? What is going on? I've checked, double check and did everything form the php.ini file to dragging the libmysql.dll to the C:\Windows\system32 directory. PHP is running fine, MySQL is 'supposedly' running fine. Can someone please help me figure this problem out before I lose my insanity.

(*Note: Session save path is not important, Joomla does that on my working linux server sometimes and works properly.)

On the good note, everything works perfectly with usbwebserver from http://www.usbwebserver.com

Any help would be appreciated. Thanks in advance and Happy Holidays!
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23458
  • Loc: Woodbridge VA

Post 3+ Months Ago

Thanks for the compliments on the tute. It's a little old and needs some updating. Hope to get to that soon.

Unfortunately, I've haven't installed Joomla on Windows yet, so not sure what kind of glitches might happen. I do have a friend that solely uses Joomla on IIS, though. If I catch him online I'll have him look at your post and see if he has any thoughts.

Might help to know which version of MySQL you installed.
  • x11
  • Born
  • Born
  • x11
  • Posts: 3

Post 3+ Months Ago

Hi, I've been searching online for the last few hours trying to find the best (and most recently active) thread on the topic of Windows + PHP + MySql + phpMyAdmin installation. And, I'm pleased to report that this is by far the best resource that I could google.

I'm hoping that you can help me understand the problem that I'm currently experiencing with my installation.

I am using:
  1. MySql 5.1.22-rc-win32
  2. PHP 5.2.5-win32-installer
  3. phpMyAdmin 2.11.4-rc1-english
  4. Windows 2003 Server
  5. IIS 6.0


I've tested a phpinfo.php file containing
PHP Code: [ Select ]
<?php phpinfo() ?>

and a test.php containing
PHP Code: [ Select ]
<?php
 
// Connecting, selecting database
 
$link = mysql_connect('localhost', 'root', '<password redacted>')
 
or die('Could not connect: ' . mysql_error());
 
echo 'Connected successfully';
 
mysql_select_db('mysql') or die('Could not select database');
 
 
 
// Performing SQL query
 
$query = 'SELECT * FROM user';
 
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
 
 
 
// Printing results in HTML
 
echo "<table>\n";
 
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
 
   echo "\t<tr>\n";
 
   foreach ($line as $col_value) {
 
      echo "\t\t<td>$col_value</td>\n";
 
   }
 
   echo "\t</tr>\n";
 
}
 
echo "</table>\n";
 
 
 
// Free resultset
 
mysql_free_result($result);
 
 
 
// Closing connection
 
mysql_close($link);
 
 
 
 
 
if ( !is_dir( session_save_path() ) ) {
 
   echo "'session.save_path' directory not set! Please set your session.save_path in your php.ini file.";
 
} else {
 
   echo "'session.save_path' is set. ";
 
   echo session_save_path();
 
}
 
 
 
?>
  1. <?php
  2.  
  3. // Connecting, selecting database
  4.  
  5. $link = mysql_connect('localhost', 'root', '<password redacted>')
  6.  
  7. or die('Could not connect: ' . mysql_error());
  8.  
  9. echo 'Connected successfully';
  10.  
  11. mysql_select_db('mysql') or die('Could not select database');
  12.  
  13.  
  14.  
  15. // Performing SQL query
  16.  
  17. $query = 'SELECT * FROM user';
  18.  
  19. $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  20.  
  21.  
  22.  
  23. // Printing results in HTML
  24.  
  25. echo "<table>\n";
  26.  
  27. while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
  28.  
  29.    echo "\t<tr>\n";
  30.  
  31.    foreach ($line as $col_value) {
  32.  
  33.       echo "\t\t<td>$col_value</td>\n";
  34.  
  35.    }
  36.  
  37.    echo "\t</tr>\n";
  38.  
  39. }
  40.  
  41. echo "</table>\n";
  42.  
  43.  
  44.  
  45. // Free resultset
  46.  
  47. mysql_free_result($result);
  48.  
  49.  
  50.  
  51. // Closing connection
  52.  
  53. mysql_close($link);
  54.  
  55.  
  56.  
  57.  
  58.  
  59. if ( !is_dir( session_save_path() ) ) {
  60.  
  61.    echo "'session.save_path' directory not set! Please set your session.save_path in your php.ini file.";
  62.  
  63. } else {
  64.  
  65.    echo "'session.save_path' is set. ";
  66.  
  67.    echo session_save_path();
  68.  
  69. }
  70.  
  71.  
  72.  
  73. ?>


The results are a succesful phpinfo output containing the following (most likely relevant) entries:
Quote:
header (not titled)
Loaded Configuration File C:\PHP\php.ini

configuration
extension_dir C:\PHP\ext

mysql
Client API version 5.0.45

session
Session Support enabled
Registered save handlers files user
Registered serializer handlers php php_binary wddx

session.save_path C:\PHP\sessions


The output of the test.php looks like this (modified to remove password output)
Quote:
Connected successfully
localhost root *<password redacted> Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y 0 0 0 0
'session.save_path' is set. C:\PHP\sessions


Yet when I visit my myphpadmin page, I get

Quote:
phpMyAdmin - Error
Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.


I have reviewed the suggestions in this thread and granted both the IUSR_<machinename> and NETWORK_SERVICE users full control of the C:\PHP\sessions directory.


I would greatly appreciate your assistance. Please help me figure out what I'm doing wrong.

Thank you

Edit: Before you ask, I have tried to turn on log files and have been unsuccessful. I'm entirely willing to try to turn log files on but I will need instructions.
  • x11
  • Born
  • Born
  • x11
  • Posts: 3

Post 3+ Months Ago

LOL :lol:

Well, I hate to remove my post as it might contain useful information for others who have similar problems... but after closing the web-browser and restarting it, I now get:

Quote:
Welcome to phpMyAdmin 2.11.4-rc1

Probably reason of this is that you did not create configuration file. You might want to use setup script to create one.

Error
MySQL said:

#1045 - Access denied for user 'root'@'localhost' (using password: NO)


phpMyAdmin was unable to read your configuration file!
This might happen if PHP finds a parse error in it or PHP cannot find the file.
Please call the configuration file directly using the link below and read the PHP error message(s) that you receive. In most cases a quote or a semicolon is missing somewhere.
If you receive a blank page, everything is fine.

./config.inc.php


I should be able to solve the remaining problems from here. I will report results briefly (I'm sure you'd like to know how it ends.)
  • x11
  • Born
  • Born
  • x11
  • Posts: 3

Post 3+ Months Ago

Ok, ran the ./phpmyadmin/scripts/setup.php script and generated my config, then opened a new browser window (lesson learned) and voila... since I chose HTTP auth_type, I get prompted for a username & password using the Microsoft CHAP window.

Enter the appropriate username/pass and I have a working phpmyadmin installation.

Hopefully this information is helpful to someone, and thank you for putting together a well documented installation process, it was very helpful

Regards. 8)
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23458
  • Loc: Woodbridge VA

Post 3+ Months Ago

Thanks for updating. I just saw your PM. Sorry I couldn't get to it sooner. And thanks for the compliment on the tute.
  • rayeniguard
  • Newbie
  • Newbie
  • rayeniguard
  • Posts: 7

Post 3+ Months Ago

Hello All:

Here's my scenario:

I have PHP, MYSQL running on Windows XP SP2, IIS V5.1.

Whenever I attempted to connect to mysql via php, I was getting a nasty fatal error referencing and undefined mysql_connect...

I managed to clear that up by creating an environmental variable PHPRC.

Now, whenever I test a connection to mysql, I get a blank browser page. Whenever, I attempt to insert data I get the HTML confirmation, but no entry has taken place.

I am at a lost. Has anyone experienced this before.

Thanks.
  • rayeniguard
  • Newbie
  • Newbie
  • rayeniguard
  • Posts: 7

Post 3+ Months Ago

Update:

phpMyAdmin works fine. However, I cannot connect to mysql via php. I still get a blank page.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23458
  • Loc: Woodbridge VA

Post 3+ Months Ago

There is probably something wrong with your connection string then. phpMyAdmin works on php and uses MySQL so it sounds like you are set up fine.

What's your connection string you're trying to use?
  • rayeniguard
  • Newbie
  • Newbie
  • rayeniguard
  • Posts: 7

Post 3+ Months Ago

ATNO/TW wrote:
There is probably something wrong with your connection string then. phpMyAdmin works on php and uses MySQL so it sounds like you are set up fine.

What's your connection string you're trying to use?


I snagged this off the net:

<?
error_reporting(E_ALL);
$connection = mysql_connect("localhost:3306", "root") or die ("Cannot make the connection");
$db = mysql_select_db("word", $connection) or die ("Cannot make the connection");
$mynums = array(3,5,10,20);
if(in_array($_POST['select'],$mynums)) {
$sql = "SELECT * FROM Random ORDER BY RAND() LIMIT {$_POST['select']}";
}
$result=mysql_query($sql);
echo ($result);
?>
  • rayeniguard
  • Newbie
  • Newbie
  • rayeniguard
  • Posts: 7

Post 3+ Months Ago

This test script actually worked:

<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

So, it must be the connection string.

Post Information

  • Total Posts in this topic: 142 posts
  • Users browsing this forum: No registered users and 27 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.