设为首页 收藏本站
查看: 780|回复: 0

How to install PHP 5.x on Windows Server 2003 with IIS 6

[复制链接]

尚未签到

发表于 2015-5-4 08:31:14 | 显示全部楼层 |阅读模式
How to install PHP 5.x on Windows Server 2003 with IIS 6

http://www.peterguy.com/php/install_IIS6.html
A detailed and hopefully helpful step-by-step guide, based on my experience.
Last updated 7:13 PM 2/24/2005
questions/props/corrections/etc... > Peter Guy (take out "TheGarbage" to email)
flames > /dev/null ;-)
0. Notes before we start
0.1 This guide does not cover the initial setup of IIS, or general configuration of Windows Server 2003.
It is assumed that you have already successfully installed and configured Windows Server 2003 and setup IIS 6.
0.2 This guide is divided into 5 main steps:
1. install PHP (the easiest step, like having a baby is to raising a child)
2. Configure PHP (lots of php.ini editing)
3. Configure IIS (lots of pointing and clicking in IIS Manager)
4. Test it! (checking to make sure PHP is working on your server)
5. Troubleshooting (let's hope you don't need this section :-P)
0.3 YYMV
If you have already done basic configuration ofIIS6 on Windows Server 2003, and have an otherwise functional setup,then exactly following these steps should give you a fully-functioninginstallation of PHP. However, since I cannot know the combination ofhardware and software you are running, or any of the environmentfactors within which you work, I cannot gaurantee that these steps willwork for you. They have worked for me and others who have followedthem.
0.4 No more Internet Guest Account permissions (almost)
I recently made some pretty radical changes tothis guide by removing all instructions that involved settingpermissions for the Internet user on files and folders. PHP is aserver-side processing language so the Internet user (IUSR_on most W2k3 servers) does not need permission to access any of thefiles or folders involved with PHP. I had been unthinkingly followingthe advice of others when I configured my system that way, and itwasn't until I had experimentally removed all those permissions andnoticed that everything still worked that I started thinking about it.

More recently, I added a special-case troubleshootingtip in the case of session files not being created. I don't really likeit because I don't understand why it should work, but it was thesolution for one person so it's in here until I can find a logicalsolution. As always, feedback is welcome!
1. Install PHP
1.1 Download and unzip the latest version of PHP (5.0.3 at this time) to C:\PHP
Download the latest zipped distribution, not the Windows installer, of PHP from http://php.net.
Unzip it somewhere on your hard drive.
You can pick any drive, and any folder, but the recommendation is toput all the PHP stuff in a folder just off of the root drive (avoidwhitespace), like C:\PHP, and this guide will follow thatrecommendation.

Download the "Collection of PECL modules for PHP 5.0.3" zip file andextract the contents of that file into C:\PHP\ext. It contains moreextensions.
1.2 Rename/copy php.ini-recommended to php.ini
In your PHP directory, you'll find a couple ofphp.ini-* files. They are pre-configured settings for a PHP installthat you can use as an initial setup. php.ini-recommended is the mostsecure, hence, the recommended one; just rename it to php.ini.
2. Configure PHP mainly editing php.ini
2.1 Uncomment cgi.force_redirect in php.ini and set equal to 0
*** This is a very important step, don't neglect it. ***
2.2 Install a browscap.ini file
You don't have to install a browscap file, it'sjust for those who want to use the browser identification features ofPHP, but it is recommended that you install it because it's prettywidely used by scripts.
It's fairly straightforward: download php_browscap.ini from http://www.garykeith.com/browsers/downloads.aspto the extras directory under your PHP install directory (C:\PHP\extras\browscap.ini, for example), and change the browscap variable in php.ini to be the full path to the file (browscap=C:\PHP\extras\browscap.ini).
2.3 Create a session state directory and point the session.save_path php.ini variable to it.
This is another optional but recommended step.  PHP does not need sessions, but it's something that will most likely be useful.
Create a session directory somewhere on the server. I createdC:\PHP\Sessions. This directory will hold many small files with sessionvariable information for PHP. They probably won't take up a whole lotof room, but if you need to keep your data off your system drive, thenyou can put the folder anywhere else.
Now change the value of the session.save_path variable in php.ini to be the full path to that directory (session.save_path=C:\PHP\Sessions).
2.4 Setup the PHP extensions.
If you want to install extensions (For information on extensions, visit http://ca3.php.net/manual/en/install.windows.extensions.php), then you need to go through a couple of steps.

You need to point PHP to the directory that holds the extensionlibraries, you need to rearrange the list of extensions so that they'llload w/out throwing errors, and you need to uncomment the desiredextensions.

  • Point PHP to the correct directory:
    Set extension_dir in php.ini to "C:\PHP\ext"
  • Massage the list of extensions so that most of them will load w/out throwing errors.
    The easiest thing to do is replace all the "extension=" lines inphp.ini with the following (be sure to scroll down so you geteverything):
    extension=php_mbstring.dllextension=php_bz2.dllextension=php_cpdf.dllextension=php_curl.dllextension=php_dba.dllextension=php_dbase.dllextension=php_dbx.dll;extension=php_exif.dllextension=php_fdf.dllextension=php_filepro.dllextension=php_gd2.dllextension=php_gettext.dll;extension=php_ifx.dllextension=php_iisfunc.dllextension=php_imap.dllextension=php_interbase.dllextension=php_java.dllextension=php_ldap.dll;extension=php_mcrypt.dllextension=php_mhash.dllextension=php_mime_magic.dllextension=php_ming.dllextension=php_mssql.dllextension=php_msql.dllextension=php_mysql.dllextension=php_mysqli.dll;extension=php_oci8.dllextension=php_openssl.dll;extension=php_oracle.dllextension=php_pdf.dllextension=php_pgsql.dllextension=php_shmop.dllextension=php_snmp.dllextension=php_sockets.dll;extension=php_sybase_ct.dllextension=php_tidy.dllextension=php_ffi.dllextension=php_xmlrpc.dllextension=php_xsl.dll;extension=php_yaz.dllextension=php_zip.dll
  • Uncomment the ones you want to use.
Some notes on using extensions:

  • I left uncommented all the ones that I got to work on my system with no additional software.
  • If you have not downloaded and extracted the "Collection of PECLmodules for PHP 5.0.3" archive, not all of the uncommented ones willwork.
  • Most of the ones that won't load rely on other software being present, like oracle, informix and sybase.
  • php_mcrypt.dll requires the mcrypt library, the source code for which can be found here
  • php_yaz.dll is a bit of a mystery to me. As far as I know, I have allthe right files in all the right places (it requires yaz.dll to be inthe PATH) and it still doesn't load. Not much help found via google,either. If you know why it won't load, let me know and I'll update thisguide.
  • Actually using php_openssl.dll requires you to follow the instructions in C:\PHP\extras\openssl\README-SSL.txt.
  • See the BIG FAT NOTE in section 4.2
  • The MySQL connector has to be mysqlifor MySQL 4.1.5 or later (extension=php_mysqli.dll). If you copied inthe list of extensions above, that line will be in there. If youdidn't, well, then it won't.
  • As a side note, phpBB2 does not currently work with MySQL 4.1.x or PHP 5.x.
I could continue for a few more pages commenting on extensions. If youhave some particular question, a little google-grease goes a long way.If you're here because of some google grease and don't see the answerto your question, shoot me an e-mail. The worst thing that could happenis that I'll ignore you, and you won't be any worse off than you arenow. :-)
2.5 Do one of two things:
       a. Copy all non-php dll filesfrom C:\PHP to C:\Windows\System32 (or somewhere else in the server'sPATH)
          - OR -
       b. Add "C:\PHP" to the server's PATH environment variable
(b) is the preferred method (ok, it's my preferred method, but since I'm writing this guide, it's the preferred method ;-) ) since it keeps the installation in one place, making upgrading or uninstalling easier.

  • right-click on My Computer, choose Properties
  • flip to the Advanced tab
  • click the Environment Variables button
  • Double-click the Path variable in the list of System variables.
  • Either add "C:\PHP;" to the beginning or ";C:\PHP" to the end (sans quotes, not both).
  • Re-boot the server for it to take effect.

2.6 Add to the registry HKEY_LOCAL_MACHINE\SOFTWARE\PHP\IniFilePath = C:\PHP
This is so that PHP can find its configurationfile. To make it easy on you, modify the following text so that"C:\\PHP" is the directory in which you've unzipped PHP, then copy thetext and paste into a new text file (anywhere; the Desktop is a goodplace to create it). Rename the file to inifilepath.reg, then double-click on it, click "Yes" to the confirmation dialog, and the value will be in place.  You can then delete inifilepath.reg.
Make sure all backslashes are escaped (ie. \\ instead of just \)
Windows Registry Editor Version 5.00[HKEY_LOCAL_MACHINE\SOFTWARE\PHP]"IniFilePath"="C:\\PHP"
3. Configure IIS
      For these steps, open IIS Manager
      (Start -> Control Panel ->Administrative Tools -> Internet Information Services (IIS)Manager).
3.1 Add and allow the PHP ISAPI Extension to IIS Web Service Extensions: C:\PHP\php5isapi.dll
When you open IIS Manager, it should connect to the local computer automatically.

  • Expand the local computer in the left pane
  • Click on "Web Service Extensions" in the left pane
  • In the right pane, click the blue underlined text, "Add a new Web service extension..."
  • Enter "PHP ISAPI Extension" as the "Extension name"
  • Click the "Add..." button and browse to the php5isapi.dll file in your PHP install directory
  • Check the "Set extension status to Allowed" checkbox and click "OK"
There are two ways to setup PHP for the web: ISAPI and CGI. ISAPI istypically more efficient and secure. If you want to add the CGIextension, in addition to or instead of the ISAPI, repeat the above,but enter "PHP CGI Extension" as the "Extension name", and enter thefull path to php-cgi.exe (it will be in your PHP install directory along with php5isapi.dll).
Note that I have seen the CGI module misbehave several different ways and recommend that you stick with the ISAPI module.
The following two steps are suggested to apply tothe "Web Sites" root folder in IIS Manager, but they can be applied toindividual sites, instead. When applying changes to "Web Sites", notethat a dialog might come up asking if you want to apply changes to alist of specific websites, too. The listed sites will be ones that haveoverridden any default values, so be careful about applying changes tothem. Especially be careful of applying changes to the MicrosoftSharePoint Administration site (thus speaks painful experience).
3.2 Add new extension (.php)

  • Expand the local computer in the left pane
  • Right-click on "Web Sites" in the left pane, then click "Properties" in the menu that pops up
  • Flip top the "Home Directory" tab
  • Click "Configuration"
  • Flip to the "Mappings" tab
  • Click "Add..."
  • Enter the full path to php5isapi.dll in the "Executable" textbox (Browse... to find it more easily if you need to)
  • Enter ".php" in the "Extension" textbox
  • Select radial button "Limit to", enter "GET,POST,HEAD"
  • Click "OK"  all the way out
This will apply to every website.
This sets up IIS to actually respond to requests for php files. Untilnow, IIS hadn't know what to do with php files, you just told it topass them through php5isapi.dll.

Replace php5isapi.dll with php-cgi.exe if you chose the CGI extension in the previous step.
Again noting that I don't recommend using the CGI module...
3.3 Turn on scripting permissions for your websites
Right-click on "Web Sites", goto Properties -> Home Directory.
Change the "Execute permissions" dropdown to "Scripts only".
3.4 Restart IIS or Reboot Server
Right-click the local computer in the left pane of IIS Manager, click on All Tasks -> Restart IIS... -> OK
- OR -
If you modified the server's PATH environment variable in 2.5b and haven't rebooted yet, reboot now.
4. Test your setup
4.1 Create a new file named test.php in one of the websites
Expand the "Web Sites" folder in the left paneof IIS Manager to see a list of existing websites. Right-click on awebsite -> Properties -> Home Directory -> Local Path willshow you where the website root directory is.
Contents of test.php:
PHP Test
If you did not setup session or browscap support as outlines in steps 2.2 and 2.3, then remove the sections that test them.
4.2 Point browser there to test.
*** BIG FAT NOTE: If you uncommentedextensions, be sure to test this while logged in to the server'sconsole. If some of the extensions throw errors when loading, an errordialog will pop up on the server console telling which one didn't work.You have to be able to click "OK" to the dialog for the page to finishloading. The dialog will pop up ONLY on the server's console; not evenTerminal Services will show it. Take note of the extension that didn'twork, click "OK", and then comment out the extension in php.ini untilyou can figure out how to get it to work.
IMPORTANT TIP: if you can't get physical access to the server, you can connect to the console via RDC.  Click on Start, then Run... and enter the following in the text box: "mstsc -v:servername /F -console" (sans quotes).  Replace servernamewith the name or IP address of your server. The login dialog will show,and once you login, you will be able to see the console messagedialogs. ***

After loading test.php, you should see some ugly-lookinginformation about your browser spewed across the top of the page (ifyou setup browscap support), followed by some nicely-formattedinformation about your PHP installation. Be sure to scroll all the waydown to the bottom to see that there were no errors. I noticed with myinstallation that if I used CGI, the last several modules wouldn't loadand a bunch of error messages would print at the bottom of the testpage.
Also go check your session directory (if you setup session support) fora 0-byte file. That's the file to hold session data for the session youstarted by using the command session_start().
5. Troubleshooting
5.1 It won't work!
If you setup IIS to use the ISAPI extension, then try this: right click on WebSites > Properties > ISAPI Filters > Add
filtername = PHP
executable = php5isapi.dll

It seems that since we've added an ISAPI extension, we would need toadd an ISAPI Filter, but I never had to. I added one to see whathappened, and couldn't tell if it made any difference in performance,or even if it was being used.
5.2 I get an error about browscap.ini
Make sure that the value of the browscap variable in php.ini is the full path to the browscap.ini file, not a relative path.
5.3 My browser just hangs when I try to open test.php
Did you uncomment any extensions in step 2.4?If an extension errors while loading, PHP throws up a dialog box to theconsole of the server displaying the name of the extension and theerror. In order for PHP to continue processing (e.g., in order for thepage to continue loading), you have to click the "OK" button on thedialog box.
I know, I know, pretty stoopid, but that's the way it is.
Go login to your server's console (not Terminal Services, the dialogdoesn't show up there) and click "OK" to the 50 million dialogs thathave popped up there (one for each time you frustratedly restarted IISand tried to load the page again).
Then go re-comment out the troublesome extension(s) and try it again, this time keeping an eye on the server console.
Make sure you have the extensions in the order specified in 2.4; that order has been tested to load all the uncommented extensions w/out complaining.
Make sure you have downloaded and installed the "Collection of PECL modules for PHP 5.0.3" as described in step 1.1
5.4 I'm getting 401 authorization required or 403 permission denied errors
A couple of things could be going on:

I've seen this happen when trying to use the CGI module (php-cgi.exe).  Don't use the CGI module.  Use the ISAPI module.
I have seen several problems with the CGI module, and do not recommend that you use it.

If your website is set up to run in a special Application Pool, our theuser of your default pool is a non-standard one, you may need to give adifferent user permission to the PHP files and folders.
1. In IIS Admin, go to Application Pools
2. Right click on the pool your site is running under and click properties.
3. Go to the Identity tab and see what user is selected.
4. Give that user permissions on your php files/directory:

  • Click on the "Add" button
  • Enter in the rather large text box the user name
  • Click on "Check Names" to have it find the user for you
  • If it can't find the username, a "Name Not Found" dialog box will display
  • In that case, "Cancel" the "Name Not Found" dialog
  • click the "Advanced" button
  • This will open another dialog, where you'll click on the "Find Now" button
  • scroll through the list of  "Search results" to find the user whose listed in the Application Pool

5.5 I loaded the test page,  everything looks good,  BUT, there's no 0-byte file in my sessions folder.
I heard of this happening once so far, and itwas fixed by granting the server's Internet Guest account permission toaccess the sessions folder. I don't see any logical reason to have togrant the Internet Guest account permission to a folder that PHP shouldbe accessing as the Network Service or some other more trusted user,but in this one case, that was the fix. Might work for you, too. InWindow's Explorer, right-click on the session folder, then click on"Properties" in the list that pops up. This will open a dialog box withseveral tabs. One of the tabs is named "Security". Click on it. Thistab shows a list of users who have permission to access the folder.

  • Click on the "Add" button
  • Enter in the rather large text box, "IUSR_" (Where  is the name of your server)
  • Click on "Check Names" to have it find the user for you
  • If it can't find the username, a "Name Not Found" dialog box will display
  • In that case, "Cancel" the "Name Not Found" dialog
  • click the "Advanced" button
  • This will open another dialog, where you'll click on the "Find Now" button
  • scroll through the list of  "Search results" to find the Internet Guest account (Probably displayed as IUSR_)
Ifyou can't find the Internet Guest account, then make sure IIS isinstalled and enabled, which is a whole 'nother subject. :-)

Once you find the Internet Guest Account, "OK" your way out of alldialogs. Before you "OK" your way out of the Properties dialog, checkthe "Allow" checkbox for "Modify". The default permissions are Read andExecute, and Read. You want the Internet guest account to be able tocreate and modify files in that folder, too.
If you can shed more light on this, please tell me. :-)
5.6 Do you have any pictures illustrating what I'm supposed to do?
Not yet, but you can check out http://www.visualwin.com/PHP/ for quite a few pictures detailing the process.
That is actually the website I used the most when figuring this all out.
I know, this isn't really a troubleshooting tip, but I don't have anywhere else to put it now.
Ref: http://www.peterguy.com/php/install_IIS6.html

IS+PHP+MySQL+Zend Optimizer+GD库+phpMyAdmin安装配置[完整修正实用版]
Ref:http://www.im286.com/viewthread.php?tid=878768&extra=&page=1

http://blog.yesky.com/349/iter/86849.shtml

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-63315-1-1.html 上篇帖子: windows server 2003优化 下篇帖子: Windows 2003 NTP 时间服务器设置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表