Windows 下 PHP 环境搭建小结

机子上的 PHP 的版本太老了,所以就又重新搭建了相关的开发环境,使用了最新的 PHP 5.3.5,总结一下:

1,安装 XAMPP:

这种安装是最简单的了,直接访问官网:http://www.apachefriends.org/zh_cn/xampp.html

下载 * 适用于 Windows 的 XAMPP 即可,安装及配置方法写的一明二白;

2,分开安装 Apache,PHP,MySQL:

> Apache

官网:http://httpd.apache.org/

下载最新版:http://www.motorlogy.com/apachemirror//httpd/binaries/win32/httpd-2.2.17-win32-x86-openssl-0.9.8o.msi

即:httpd-2.2.17-win32-x86-openssl-0.9.8o.msi

点击安装:我选的是针对所有用户的安装,默认端口是 80 端口;

安装好后把 182 行的 ServerName 之前的 # 去掉,改为:

ServerName localhost:80

一般情况下,46 行的 Listen 80 ,监听 80 端口,和 ServerName 的端口一致;

可以使用自带的 Apache 服务监测工具 Monitor Apache Servers 来管理服务,也可以使用 cmd 命令来启动和停止服务:

net start apache2.2
net stop apache2.2

如果你的电脑里还装有老版本的 Apache 的话,Monitor Apache Servers 也会监测到它。

开启服务后,在浏览器中键入:localhost,如果显示“It Works!”的话 则安装成功。

> PHP

官网:http://windows.php.net/download/

在下载的时候注意看右方的 Which version do I choose?

If you are using PHP with Apache 1 or Apache2 from apache.org you need to use the VC6 versions of PHP

If you are using PHP with IIS you should use the VC9 versions of PHP

VC6 Versions are compiled with the legacy Visual Studio 6 compiler

VC9 Versions are compiled with the Visual Studio 2008 compiler and have improvements in performance and stability. The VC9 versions require you to have the Microsoft 2008 C++ Runtime (x86) or the Microsoft 2008 C++ Runtime (x64) installed

Do NOT use VC9 version with apache.org binaries

VC9 versions of Apache can be fetched at Apache Lounge. We use their binaries to build the Apache SAPIs.

它告诉你应该选择什么版本的 PHP,因为使用的是 Apache, 故选择:VC6 x86 Thread Safe

其实上方还有一个:VC6 x86 Non Thread Safe 版本,我们最好选择第一个版本(线程安全版本),网上的资料是:

    先从字面意思上理解,Thread Safe 是线程安全,执行时会进行线程(Thread)安全检查,以防止有新要求就启动新线程的 CGI 执行方式而耗尽系统资源。Non Thread Safe 是非线程安全,在执行时不进行线程(Thread)安全检查。
      再来看 PHP 的两种执行方式:ISAPI 和 FastCGI。
      ISAPI 执行方式是以 DLL 动态库的形式使用,可以在被用户请求后执行,在处理完一个用户请求后不会马上消失,所以需要进行线程安全检查,这样来提高程序的执行效率,所以如果是以 ISAPI 来执行 PHP,建议选择 Thread Safe 版本;
      而 FastCGI 执行方式是以单一线程来执行操作,所以不需要进行线程的安全检查,除去线程安全检查的防护反而可以提高执行效率,所以,如果是以 FastCGI 来执行 PHP,建议选择 Non Thread Safe 版本。
      官方并不建议你将Non Thread Safe 应用于生产环境,所以我们选择Thread Safe 版本的PHP来使用。

下载链接:http://windows.php.net/downloads/releases/php-5.3.5-Win32-VC6-x86.zip

即:php-5.3.5-Win32-VC6-x86.zip

解压到认为合适的文件夹里,之后就要配置 Apache 支持 PHP 了,看看我的文件结构:

文件结构

也可以作为预期的文件结构来整理,webRootDoc 作为根目录(需要配置 Apache 的 DocumentRoot 配置)。

解压之后开始配置 Apache 来支持 PHP;

> 配置 Apache 支持 PHP

打开 Apache 的配置文件 httpd.conf ,加入:

LoadModule php5_module D:/newVersionPhp/php-5.3.5/php5apache2_2.dll
AddType application/x-httpd-php .php3 .php
AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .po .py .pl .hu

# PHPIniDir
PHPIniDir "D:\newVersionPhp\php-5.3.5"

上面的 PHPIniDir 规定了php.ini 配置文件的搜索目录,这样就不用把 php.ini 放入 C:/windows 中了。

配置好了以后使用 phpinfo() 函数来检测是否安装成功。

> MySQL

官网:http://dev.mysql.com/downloads/

我下载的是:

MySQL Community Server(Current Generally Available Release: 5.5.9)MySQL Community Server is a freely downloadable version of the world's most popular open source database that is supported by an active community of open source developers and enthusiasts.DOWNLOAD

下载的话貌似需要免费注册一个帐号,注册吧!别犹豫!全名:Mysql-5.5.9.msi

提供了傻瓜式的安装。

之后启动服务和关闭服务类似于 Apache:

net start mysql
net stop mysql

> 配置 PHP 支持 MySQL

我们使用 $php_path 来表明你的 PHP 的安装目录:

1) 将 $php_path\libmysql.dll 拷入 windows 的 system32 目录中;

2) 将 $php_path\ext\php_mysql.dl l 拷到 $php_path\ 下;

3) 重命名:$php_path\php.ini-production 为 php.ini ,这样的话 php.ini 才投入使用。

4) 设置 php.ini 的 extension_dir :

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
; extension_dir = "ext"
extension_dir = "D:/newVersionPhp/php-5.3.5/ext"

5) 去掉 948 行之后每一行 extension 之前的分号。

> 测试 MySQL

可以写一个简单的脚本来测试是否已经配置好 PHP 和 MySQL:

<?php

$db_host     = 'localhost';
$db_database = 'test';
$db_username = 'root';
$db_password = '123';
$connection  = mysql_connect($db_host, $db_username, $db_password);
if (!$connection){
	die ("Could not connect to the database: <br />". mysql_error());
}
else{
	echo "connected successfully!";
}

?>

> 安装 PEAR 扩展

刚开始使用的可能是老版本的 go-pear.php 来安装的,安装一直出错,最后在一个论坛上找到了原因:

QUOTE(Ric @ Jan 26 2011, 08:41 AM) *

It looks as if go-pear.php v1.1.2 remains the latest version (as per Pear web-site).
However core and other elements have been updated while go-pear has been neglected.
Solution is to edit file:
UniServer\home\admin\www\plugins\pear\go_pear.php
Locate this section:

CODE

'PEAR.php'             => 'http://svn.php.net/viewvc/pear/pear-core/branches/PEAR_1_4/PEAR.php?view=co',
'Archive/Tar.php'      => 'http://svn.php.net/viewvc/pear/packages/Archive_Tar/tags/RELEASE_1_3_2/Archive/Tar.php?view=co',
'Console/Getopt.php'   => 'http://svn.php.net/viewvc/pear/pear-core/branches/PEAR_1_4/Console/Getopt.php?view=co',

Change as shown below:

CODE

'PEAR.php'             => 'http://svn.php.net/viewvc/pear/pear-core/branches/PEAR_1_6/PEAR.php?view=co',
'Archive/Tar.php'      => 'http://svn.php.net/viewvc/pear/packages/Archive_Tar/tags/RELEASE_1_3_3/Archive/Tar.php?view=co',
'Console/Getopt.php'   => 'http://svn.php.net/viewvc/pear/pear-core/branches/PEAR_1_6/Console/Getopt.php?view=co',

经过修改后的 go_pear.php 没有问题了,安装成功:

Starting installation ...
Loading zlib: ok

Bootstrapping Installer...................
Bootstrapping PEAR.php............(remote) ok
Bootstrapping Archive/Tar.php............(remote) ok
Bootstrapping Console/Getopt.php............(remote) ok

Extracting installer..................
Downloading package: PEAR.............ok
Downloading package: Structures_Graph....ok

Preparing installer..................
Updating channel "doc.php.net"
Update of Channel "doc.php.net" succeeded
Updating channel "pear.php.net"
Channel "pear.php.net" is up to date
Updating channel "pecl.php.net"
Update of Channel "pecl.php.net" succeeded

Installing selected packages..................
Downloading and installing package: PEAR.............ok
Installing bootstrap package: Structures_Graph.......ok
Downloading and installing package: Archive_Tar-stable.......ok
Downloading and installing package: Console_Getopt-stable.......ok
Downloading and installing package: PEAR_Frontend_Web-beta.......ok

Writing WebFrontend file ... ok

Installation Completed !
	Note: To use PEAR without any problems you need to add your
PEAR Installation path (D:\newVersionPhp\PEAR/PEAR)
to your include_path.

Using a .htaccess file or directly edit httpd.conf would be working solutions
for Apache running servers, too.

For more information about PEAR, see:
PEAR FAQ
PEAR Manual

Thanks for using go-pear!

文件下载链接:https://files.cnblogs.com/catprayer/go-pear_new.rar

直接解压放入根目录运行即可,按照提示来安装。

posted @ 2011-03-14 14:29  无墨来点睛  Views(4052)  Comments(0Edit  收藏  举报