1. Why Windows Server 2003 and IIS?
The optimal environment for running PHP + MySQL application is a Linux server running Apache Web Server. It requires minimal setup and assures the best performance and reliability. However, what if .NET applications are required to run on the same server? I guess the only option is to install PHP + MySQL on a windows server (Why not .NET on Linux? No, the other way has been tried, but it did not work well).
On a windows server, Apache Web Server is still the best choice to run PHP + MySQL combo, but unfortunately Apache and IIS cannot share the same port, which means only one of them will run on port 80 (even you bind 100 IP addresses on the same server). Therefore, if you want to run both PHP and .NET applications on the same server, your best bet will be IIS + PHP + MySQL.
2. Sample environment
(1) Windows Server 2003 SP2 + IIS 6.0
(2) PHP 5.2.4
(3) MySQL 5.1.22
3. Download Files
(1) PHP: http://www.php.net/downloads.php
There are several PHP packages for Windows. Make sure you download “Zip Package”. DO NOT DOWNLOAD “installer”! Too many people have problems with “installer” version and that package messes up too much.
(2) MySQL: http://dev.mysql.com/downloads/
As the time I wrote this guide, MySQL 6.0 is out as a public preview. I did not use it because there is no manual. I recommend to use a stable release for production servers.
4. Install MySQL
(1) Most tutorials online installs as the order: MySQL -> Apache -> PHP because you can test MySQL alone, and when you install PHP you can directly modify php.ini for MySQL (otherwise, you have to modify php.ini again after you install MySQL).
(2) I downloaded installer version of MySQL. Just run setup.exe and it will do all the work for you. I am lazy to write detail installation process because I have not had any problem. Everything was straight forward. If you had run in a problem, check official documentation:
http://dev.mysql.com/doc/refman/5.1/en/installing.html
(3) Test MySQL server in command-line:
a) Start -> Run -> cmd
b) mysql -u root -p
c) input your password
d) if it connects to the server successfully, you are in good shape. type “show databases;” to display all default databases. If you see the list, you are ready to move on.
5. Install PHP
(1) Unzip all the files to “C:\php” (I unzipped to “C:\Program Files\PHP” but I have seen people having problem with file path that contains “space”, so most tutorial uses “C:\php”.
(2) create a folder you want to run PHP applications, e.g. C:\inetpub\phproot. Most tutorial uses “wwwroot” which is the default IIS web directory, but I think it makes sense to use a different directory since I don’t want my application mess up with all asp files.
(3) Modify php.ini
php.ini is the most important configuration file. I will revisit this file later in this guide when I talk about setting up email and file upload. For now, we need to modify:
a) “doc_root”: set this as “c:\inetpub\phproot”;
b) “extension_dir”: set this as “c:\php\ext”;
c) uncomment lines with mysql extensions (e.g. remove “;” before “extension=php_mysql.dll”);
d) change default exection timeout, e.g. “max_execution_time = 3600″ (Note: this is very important! I have rarely seen tutorial mentioning this parameter, but the default is 30 seconds. If you did not increase this number you will get way too many 500 error and take you forever to figure out “what’s wrong with my code?” (there is nothing wrong with your code, but the server will return an error after 30 seconds).
(4) Setup IIS (using “IIS Services Manager”):
a) expand “Web Service Extensions”;
b) Action -> add a new service extension;
c) enter “PHP” as name and click “Add…”, and select “c:\php\php5isapi.dll”. (Note: many earlier tutorials recommend to use CGI mode because ISAPI is not stable for PHP. I believe things have been improved dramatically now and most new tutorials prefer ISAPI to CGI);
d) Create a new website. Set “c:\inetpub\phproot” as home directory;
e) In the same “Home Directory” tab, click “Configuration…”;
f) In the new dialog window, click “Add…”;
g) Set “c:\php\php5isapi.dll” as executable and “.php” as extension. Make sure “Script engine” option is checked.
h) Now restart your IIS Server (open “Services” in Control Panel, and restart “World Wide Web Publishing Service”)
(5) Run a test script for php setting:
Create a new file in “c:\inetpub\phproot” and name it “test.php”. Open it with notepad and type:
-
< ?php
-
?>
Run this script, e.g. type “http://localhost/test.php” in a web browser. If you see the script display a whole page of server configuration like this one, that means your server is supporting PHP now. Scroll down a little bit in the page, and make sure it has sections for “mysql” (In the sample I provided above, it has a section for mysql).
Note: If you did not get the expected result unfortunately, there are many good posts on troubleshooting. Troubleshooting is beyond the scope of my guide.
============================================
Now you got a good server running PHP + MySQL under IIS, and most tutorial will stop here. However, it is far from over for a production server! In my case, the application I run requires:
(1) backward compatibility of old instruction sepraration;
(2) sending email using mail();
(3) users can upload files.
If you just follow my guide above, non of these features will function properly!
(1) Proper instruction separation for PHP should use “< ?php" as open tag and "?>” as close tag. However, many legacy code has other format, e.g. “< ?" to open and "?>” to close. The best practice is to modify the code for standard format! Nonetheless, PHP can still support “< ?" opening by set "short_open_tag=1" in php.ini.
(2) PHP supports file upload from client to server, but PHP file upload feature is not enabled under IIS by default.
You need setup two folders on your server. One is the folder where you want the upload files to store, and the other one is the folder for temporary upload files (PHP handles upload in two separate steps: it first uploads the file to the temp folder, and then use “move_uploaded_file()” function to move from temp folder to final destination. For a good example, check official doc http://ca3.php.net/features.file-upload).
Here is an example on setup procedures:
a) create two folders “c:\inetpub\phproot\uploads” and “c:\inetpub\phproot\upload_temp”;
b) In “IIS Service Manager”, right click on the folder and click “Properties”. In “Directory” tab, make sure you enable “write” permission for both folders;
c) Open php.ini, uncomment and edit this line: upload_tmp_dir = “C:\inetpub\phproot\upload_temp\”;
d) restart the service and file upload feature should be enabled.
(3) If you google “php mail IIS”, you find many many posts from people who have trouble to make mail() function work. I have talked about this issue in another guide I wrote.
Source: chenty
Buy:Prevacid.Human Growth Hormone.Accutane.Zyban.Lumigan.100% Pure Okinawan Coral Calcium.Petcam (Metacam) Oral Suspension.Mega Hoodia.Actos.Nexium.Prednisolone.Arimidex.Retin-A.Zovirax.Valtrex.Synthroid….
Trackback by DWAYNE — July 4, 2010 @ 4:07 am