IIS, PHP, MySQL and Windows Server 2003
Posted by walsh_r on 16 Oct 2007 at 03:21 pm | Tagged as: Databases, Web Design
The creation of a database driven website is very simple in concept; add content to the database, and display the content on pages. The work going on behind the scenes to make this concept function, is not always so simple. There are numerous methods and products that can be used to accomplish different parts of this task, but getting them all to work nicely together can deliver headaches to anyone.
One popular combination often chosen by developers is the use of the PHP scripting language, and MySQL database. Both products are free, open source, cross platform, and have a large base of corporate and personal users.
Getting PHP and MySQL to work nicely with Windows Server 2003 and IIS can be troublesome, mostly due to the many different versions of PHP and MySQL, and the frequency that each product is updated (don’t get me wrong, free updates to products are great, once they are configured and working as expected). After experiencing some problems related to versions myself, I decided to write this tutorial on how to configure an operational MySQL database capable of interacting with PHP, IIS 6.0 on Windows Server 2003.
Required:
Background:
- IIS 6.0 previously installed on a Windows 2003 Server.
PHP Installation
- Create a folder on your root (C:) and name it PHP. (C:\PHP)
- Unzip the contents of the PHP 5.2.3 ZIP file to the PHP folder created in step 1.
- Open the IIS MMC snap-in.
- In the properties of the website you wish to use PHP with (most likely the default website), go to the Home Directory tab, and select Configuration.
- Under Application Configuration, check to see if .php is in the list. If it is, you will need to click edit and modify the Executable to C:\php\php5isapi.dll. If it is missing from the list, click add, and use C:\php\php5isapi.dll as the Executable and .php as the extension.
- Copy php.ini-recommended from C:\PHP to C:\Windows and rename to php.ini .
- Reboot.
To test the PHP installation, create a new file in notepad that contains the code below. Save the file as test.php in the root directory of your website.
<?PHP
phpinfo();
?>
Open a web browser from your web server and test http://127.0.0.1/test.php . If PHP is installed correctly, you will get a listing of the PHP configuration.
MySQL Installation
- Install MySQL 5.0
- Install the GUI tools for MySQL 5.0
- Run the MySQL Server Instance Config Wizard from the Start menu.
- Detailed Configuration
- Developer Machine
- Non-Transactional Database Only
- Decision Support (DSS)/OLAP
- Check Enable TCPIP Networking
- Port 3306
- Standard Character Set
- Install as a Windows Service
- Assign a root password (remember this password!!)
*Remember the password that you assign to the root account! Document the password in a secure, reliable location.
- Launch the MySQL Administrator Program (the GUI tools installed earlier)
- Server host: localhost
- username: root
- password: use the password assigned above.
- If the tool connects and lists information about your MySQL server, then MySQL has been configured correctly.
To finish things off, we need to configure PHP to load some MySQL extensions. This will enable the web server, PHP, and MySQL to work together while server content to web pages from the MySQL database.
- Copy C:\PHP\libmysql.dll to C:\windows\system32\ .
- Open C:\Windows\PHP.ini in Notepad.
- Search the INI file for the following lines, and edit them to read as follows. If there is a semi-colon in front of the line, remove it.
- extension_dir=”c:\php\ext\”
- extension=php_mysql.dll
- extension=php_mysqli.dll
- Reboot.
To test the configuration, create a new file in notepad that contains the code below. Save the file as mysqltest.php in the root directory of your website. Edit the code to replace the root password with the one previously assigned.
<?PHP
//(”server name”,”username”,”password”)
$rst = @mysql_connect(”localhost”,”root”,”insert_password_here”);
if (!$rst){
echo( “<p>Unable to connect to database manager.</p>”);
die(’Could not connect: ‘ . mysql_error());
exit();
} else {
echo(”<p>Successfully Connected to MySQL Database Manager!</p>”);
}
if (! @mysql_select_db(”mysql”) ){
echo( “<p>Unable to connect database…</p>”);
exit();
} else {
echo(”<p>Successfully Connected to Database ‘MYSQL’!</p>”);
}
?>
Open a web browser from your web server and test http://127.0.0.1/mysqltest.php . If everything is configured correctly, your web browser will display Successfully Connected to MySQL Database Manager and Successfully Connected to Database ‘MYSQL’.
The Web Server is now ready to serve PHP web pages and communicate with a MySQL database.
Thanks, Just setup Server 2003 for a company. Just coded a PHP Invoice system for them also.
This will be great, THANKS!
i have done whatever u told me,still i m getting problem of “undefined function mysql_connect()”,pls help me
[...] Este blog é o culminar de um projecto pessoal, instalar um servidor e meter a correr no IIS6 php e mysql, para quem não saiba estas duas extensões não estão disponíveis na instalação por defeito. Neste projecto está também incluido um servidor de mail, mail enable standard, e um sistema de backup diário a todos os computadores da rede em questão. Caso alguém tenho interesse em saber com o é que isto se faz, pode recorrer ao seguinte tutorial. [...]
I used your tutorial and it seems to work rather excellent, no error messages or so. But, always a but in here, I get the PHP to work perfectly, only there’s no way on earth I get the sql-related code to display in the browser. If anyone of you also experienced that the logon to the mysql program works great, but the PHP does no return succes- nor failurecode.. Extremely strange. I’ll keep on trying, ’cause I really need this to work!
Happy for any answers to aid me!
Hi Pierre W.
Are you talking about the code in mysqltest.php, the file you created in the root directory of your website?
THe error when installing Mysql 5 says..Cannot creat windows service for mysql..error 0. when we execute the program.
what could be the problem?
rinzi
Solution #1
[From MySQL Docs]
Error: Cannot create Windows service for MySql. Error: 0
This error is encountered when you re-install or upgrade MySQL without first stopping and removing the existing MySQL service and install MySQL using the MySQL Configuration Wizard. This happens because when the Configuration Wizard tries to install the service it finds an existing service with the same name.
One solution to this problem is to choose a service name other than mysql when using the configuration wizard. This will allow the new service to be installed correctly, but leaves the outdated service in place. While this is harmless it is best to remove old services that are no longer in use.
To permanently remove the old mysql service, execute the following command as a user with administrative privileges, on the command-line:
C:\>sc delete mysql
[SC] DeleteService SUCCESS
Take a look at http://dev.mysql.com/doc/mysql/en/windows-troubleshooting.html
Solution #2
Rumor has it that this error can also occur when you have installed MySQL in the C:/Program Files/ directory. The space in “Program Files” is the issue if this is the problem. Try installing to c:\MySQL as a 2nd try to resolve the issue (however, I would expect the first solution to work nicely for you).
i have done whatever u told me,still i m getting problem of “undefined function mysql_connect()”,pls help me
i have two problems.
1)when i am testing php it shows nothing for output.
2)when i am testing mysqltest.php it shows
“Unable to connect to database manager.
”); die(’Could not connect: ‘ . mysql_error()); exit(); } else { echo(”
Successfully Connected to MySQL Database Manager!
”); } if (! @mysql_select_db(”mysql”) ){ echo( “
Unable to connect database…
”); exit(); } else { echo(”
Successfully Connected to Database ‘MYSQL’!
”); } ?>”
Hi,
Followed everything but getting a blank page.
The PHP code works fine, all the code before the mysql connect statment gets executed but when I use a mysql connect statment it dies, nothing executes after that.
mysql is installed properly I can connect to it. I tried to run “php index.php” on the command prompt(index.php is my file) and it gave me the expected output. But the browser dies when I write mysql connect statment, once it fired internal server error, is there a problem with IIS??
Thanks.
Is no one responding to the errors posted above? i need to install php and mysql onto a windows server 2003 system with IIS6. If this doesnt work, i would like to know. I guess i will search somewhere else.
I have tried without success to connect to mysql using php it always result in blank page can anybody tell solution to this
good site zxiclr
i configured as you said in ur manual. but i received the error mysql cannot link to the database.
This site also shows cannot create tcp/ip socket error 10040
I’m also getting a blank page on the mysqltest.php page.
I have done the same steps , it was working in XP . but i try it in windows server 2003 , it does not work.. is there any work arund still i have to do ?
Hi! I was surfing and found your blog post… nice! I love your blog.
Cheers! Sandra. R.
Without signaling, she cut across two lanes, and I had to swerve onto the left shoulder to avoid being hit. ,
Sign: tpmnp Hello!!! xgxes and 6392knsyrcmfvg and 2047 : Hi! I was surfing and found your blog post! nice! I just came across your blog and wanted to say that Ive really enjoyed it.
mysqltest.php it always result in blank page can anybody tell solution to this
высчитать пол ребенка по крови
Выяснить пол малыша
I noticed your site when I was looking for something entirely different, but this page was one of the first sites listed in Google, your site must be amazingly popular! Keep up the good work!
И здесь тоже не нашел ответа. (
Great post!
Those of you getting a blank page – you probably cut and pasted the code into a notepad file? I was getting the same thing, then I went through and replaced ALL the quotation marks with shift-2 (”). There is a visual difference so presumably a different character.
However I am getting the “FATAL ERROR: Call to undefined function mysql_connect()” message. I can see that PHP is not picking up the mysql extensions (from phpinfo()) and I’m at a loss as to how to fix it.
I will know, I thank for the information.
I am final, I am sorry, but, in my opinion, there is other way of the decision of a question.
I can not participate now in discussion – it is very occupied. I will return – I will necessarily express the opinion on this question.
Excuse for that I interfere … To me this situation is familiar. Let’s discuss. Write here or in PM.
I think, that you are mistaken. I suggest it to discuss. Write to me in PM, we will talk.
For everyone who is having trouble with a blank page when trying to connect to browse the mysqltest.php page, ensure all the quotation marks you see in the notepad document are either single quotes (’) or double quotes (”) by manually replacing them on your keyboard.
You are not seeing any errors on the page because PHP by default is configured not to show errors on the screen.
If you look for and change the following settings in the c:\windows\php.ini you will see the errors being generated.
display_errors = Off – This is the default setting and is why you get a blank page. Change the Off to On, save the INI file, and restart the IIS service (no need to restart the entire machine) you will be able to start troubleshooting your PHP file.
If anyone needs assistance, please feel free to email me: agoulart@undeadgaming.net
Andrew
Hello! present: Again, this dress is paired with a black shoe, the most relatable option. But don’t fall into rut, either, particularly at this level of designer clothes, Eckenswiller says. “These are about aspirational pieces. Don’t be afraid of being bold.” – Boss Selection Menswear (2003) , BLUMARINE De Puta Madre 69 , Lanvin Fendi Score or Juicy Couture “None of this,” she says, pointing to the vast office and commotion of people, “would happen if it was done on a hanger.” Hugo Boss AG is a German fashion and lifestyle house based in Metzingen that specializes in high-end mens- and womenswear. It is named after its founder, Hugo Ferdinand Boss (1885–1948). , Smiley World Sweaters Skirts and Philipp Plein Accessories Faith Galliano , Belts Even though the dress is flat-out wearable, it can be a little “too uptown” for some women, Eckenswiller says. The addition of a black Valentino coat with a laser-cut lace bottom gives it edge without going over the top. In terms of design, the clothing from this line does not feature Giorgio Armani’s signature simplicity and often has larger logos than the clothing in any of his other collections. The colors used for Armani Jeans are more diverse than those found in his higher end lines or Armani Exchange, which feature monochromatic color schemes and focus on cut and material over color. . of the good viewing…!!!
I recently came across your blog and have been reading along. I thought I would leave my first comment. I dont know what to say except that I have enjoyed reading.
Sign: zdbrw Hello!!! hrgxq and 739csmqqtghus and 9632 : I love your site.
Love design!!! I just came across your blog and wanted to say that Ive really enjoyed browsing your blog posts.