Windows下搭建PHP运行环境
一、准备必要的文件
apache http服务器:http://www.apachelounge.com/ 最新版需要VC11支持 VC11 vcredist_x64/86.exe
php处理引擎:http://windows.php.net/
mysql数据库服务器:http://www.mysql.com/ 需要.net4.0支持
数据库管理Web应用程序phpmyadmin:http://www.phpmyadmin.net
二、配置PHP运行环境
安装Apache服务器:解压apache安装包里面的"apache24"文件夹到"C:\",修改配置文件“C:\Apache24\conf\httpd.conf”,用记事本打开httpd.conf找到ServerName,把ServerName启用(前面的#去掉),把“www.example.com:80”改成"localhost:80";找到IfModule dir_mod,到DirectoryIndex后面添加index.php index.html default.php default.html。
CMD命令行下输入以下命令启用apache,用浏览器打开localhost如果浏览器显示It works!则apache服务器运行正常。 C:\Users\Administrator>cd c:\apache24\bin C:\Apache24\bin>httpd.exe C:\Apache24\bin>httpd.exe -k install ·················把apache安装成系统服务 Installing the Apache2.4 service The Apache2.4 service is successfully installed.······安装apache为系统服务成功 Testing httpd.conf.... Errors reported here must be corrected before the service can be started. C:\Apache24\bin>
把apache安装成系统服务后可以通过“C:\Apache24\bin\ApacheMonitor.exe”管理apache服务。
安装php处理引擎:解压php安装包到“C:\php”,复制粘贴“C:\php\php.ini-development”配置文件并重命名为“php.ini”,打开“C:\Apache24\conf\httpd.conf”配置文件并到末尾添加以下内容:
LoadModule php5_module "c:/php/php5apache2_4.dll"············加载php5动态链接库 AddHandler application/x-httpd-php .php .phtml···············让apache服务器解析.php和.phtml文件 PHPIniDir "c:/php"···········································指定了php.ini所在的目录
到“C:\Apache24\htdocs”下新建一个文本文档输入以下内容保存为"test.php",打开apache服务然后用浏览器打开localhost\test.php显示“hello world!”,则表示apache服务器和php解析引擎已经相互认识了,apache服务器能正常解析.php文件。
<?php echo "hello world!"; ?>
安装MySQL数据库:直接打开MySQL数据库.msi安装文件下一步下一步选择“only Server”,设置Root密码完成安装即可。
CMD命令行下输入以下命令验证MySQL数据库是否安装成功 C:\Users\Administrator>cd C:\Program Files\MySQL\MySQL Server 5.6\bin C:\Program Files\MySQL\MySQL Server 5.6\bin>mysql -u root -p Enter password: ******** Welcome to the MySQL monitor. Commands end with ; or \g.························证明MySQL安装成功 Your MySQL connection id is 4 Server version: 5.6.21-log MySQL Community Server (GPL) Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
安装数据库管理软件phpmyadmin:解压数据包里面的文件到“C:\Apache24\htdocs\phpMyAdmin”,打开php.ini配置文件找到extension_dir把前面的分号去掉路径改成绝对地址(extension_dir = "c:\php\ext");找到Dynamic Extensions启用以下扩展:
extension=php_bz2.dll extension=php_curl.dll extension=php_gd2.dll extension=php_imap.dll extension=php_mbstring.dll extension=php_mysql.dll extension=php_mysqli.dll extension=php_pdo_mysql.dll
配置upload_tmp_dir目录upload_tmp_dir = "c:\php\tmp",然后到c:\php下建立tmp目录。重启apache服务,浏览器打开http://localhost/phpmyadmin可正常显示数据库管理软件phpmyadmin登录页面,是用数据库root用户可以登录并管理数据库。