Windows Server 2003下配置PHP 5.0与MySQL 5.0服务器
经过一小时的研究与设置,成功实现了最新的 PHP 5.0 + MYSQL 5.0 + WIN2003 环境组合。鉴于新版本与旧版本存在诸多差异,特撰写此教程以分享经验。实际过程中查阅了大量官方文档,才解决了许多棘手问题。
=========================
所需相关软件均可在 WWW.SKYCN.NET 网站下载获取。
主要涉及软件包括:MYSQL 5.0 FOR WINDOWS、PHP 5.0 FOR WINDOWS、PHPMYADMIN 以及 WINDOWS SERVER 2003。
=========================
首先进行 MYSQL 的安装。原本预期新版安装界面会有所创新,但依旧沿用经典的海豚图标。相比 4.0 版本,5.0 因体积庞大导致安装时间较长。
建议将 MYSQL 安装在独立的 NTFS 分区上,例如服务器的 F 盘,专门用于存放服务器软件。安装路径设定为:F:\MYSQL\。
随后进入 F:\MYSQL\BIN\ 目录,双击运行 winmysqladmin.exe。首次启动需输入超级用户及密码,默认输入 root 和密码 root。若为对外服务器,务必设置高强度密码,如 Wjwsfjn29szjwh~mysql(寓意:我叫魏舒芬,今年29岁至今未婚)。
至此,MYSQL 安装工作完成。如有不明之处,可参考深空同学的相关文章。
=========================
接下来安装 PHP 5.0。该过程无需传统安装程序,只需解压文件至指定路径,推荐放置于:F:\PHP\。
此处进入关键配置步骤。首先复制 PHP 目录下的 Php.ini-dist 文件到 C:\Windows\ 目录,并将文件名重命名为 Php.ini。
执行命令:COPY F:\PHP\Php.ini-dist C:\Windows\ 及 Ren Php.ini-dist Php.ini。
对于 WINDOWS 2000 系统,目标路径为 C:\WINNT\;而对于 WIN9X / 2003 系统,则为 C:\Windows\。
接着,将 PHP 目录下 DLLS 文件夹中的所有文件复制到 SYSTEM32 目录中。
执行命令:COPY F:\PHP\dlls\*.* C:\Windows\System32\。
同样,WINDOWS 2000 的目标路径是 C:\WINNT\System32\,而 WIN9X / 2003 则是 C:\Windows\System32\。
继续操作,将 PHP 目录下的 php4ts.dll 文件复制到 System32 目录中。
执行命令:COPY F:\PHP\php4ts.dll C:\Windows\System32\。
=========================
上述复制工作全部结束后,开始修改 C:\Windows\Php.ini 配置文件。
请注意,PHP 5.0 版本的修改与 4.0 并不完全相同,需特别注意以下变更点。
查找 extension_dir 字符串,将其修改为你 PHP 目录中 extensions 的实际路径。
; Directory in which the loadable extensions (modules) reside. extension_dir = F:\PHP\extensions
参考相关官方技术资料。
Edit your php.ini file:
You will need to change the 'extension_dir' setting to point to your php-install-dir, or where you have placed your 'php_*.dll' files. ex: c:\php
If you are using OmniHTTPd, do not follow the next step. Set the 'doc_root' to point to your webservers document_root. ex: c:\apache\htdocs or c:\webroot
Choose which extensions you would like to load when PHP starts, noting that several extensions are already built into the Windows release, see the section about Windows extensions for details of the built-in extensions. You can uncomment the: 'extension=php_*.dll' lines in php.ini to load these extensions.
Note that on a new installation it is advisable to first get PHP working and tested without any extensions before enabling them in php.ini.
On PWS and IIS, you can set the browscap.ini to point to: 'c:\windows\system\inetsrv\browscap.ini' on Windows 9x/Me and 'c:\winnt\system32\inetsrv\browscap.ini' on NT/2000/XP Server.
More information on the capabilities of browscap can be found here:
www.php.net/manual/en/function.get-browser.php
Note that the mibs directory supplied with the Windows distribution contains support files for SNMP. This directory should be moved to DRIVE:\usr\mibs (DRIVE being the drive where PHP is installed.)
与 PHP 4.0 不同之处在于,还需修改 Php.ini 文件中的以下内容:查找 cgi.force_redirect 字符串,其默认值为 1,需将其改为 0 并删除前面的分号。
即修改为:
; cgi.force_redirect is necessary to provide security running PHP as a CGI under ; most web servers. Left undefined, PHP turns this on by default. You can ; turn it off here AT YOUR OWN RISK ; **You CAN safely turn this off for IIS, in fact, you MUST.** cgi.force_redirect = 0
务必进行上述修改,否则 PHP 5.0 将无法正常运行,并会出现如下错误提示。
Security Alert! The PHP CGI cannot be accessed directly.
参考相关官方技术资料。
!NOTE!: Since 4.1.2, the php.ini setting cgi.force_redirect defaults to '1' which effectively prevents the cgi from working within IIS. You need to set up at least a minimal php.ini file with the following directive:
cgi.force_redirect = 0
If it doesn't work immidiately, make sure you have the php.ini file in the right place (%SYSTEMROOT%\php.ini).
接下来修改 Php.ini 文件中关于 MYSQL 5.0 的连接设置。
找到 [MySQL] 字段内的内容,并按如下方式修改。
mysql.default_port = 3306 // 这里是MYSQL的端口.
mysql.default_host = localhost // 这里是本地主机.
mysql.default_user = root // 这里是用户
mysql.default_password = Wjwsfjn29szjwh~mysql // 这里是密码
完成以上修改即可实现 Php 与 MYSQL 的关联。最后一步是启动 PHP 对 MYSQL 模块的支持。
查找 extension=php_mysql.dll 字符串,删除其前面的分号。
extension=php_mysql.dll
请注意,若不启用 PHP 对 MYSQL 模块的支持,PHPMYADMIN 将无法正常工作,并会提示错误信息。
cannot load MySQL extension, please check PHP Configuration 无法装入 MySQL 扩展,请检查 PHP 的配置。
参考相关官方技术资料。
To connect to a MySQL server, PHP needs a set of MySQL functions called "MySQL extension". This extension may be part of the PHP distribution (compiled-in), otherwise it needs to be loaded dynamically. Its name is probably mysql.so or php_mysql.dll. phpMyAdmin tried to load the extension but failed.
=========================
至此配置应无大问题。具备一定配置基础的用户应能完全理解。本人在实际操作中也遇到诸多问题,最终均通过耐心查阅官方文档得以解决。