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

[经验分享] Windows 下 PHP 环境搭建小结

[复制链接]

尚未签到

发表于 2015-8-28 13:08:46 | 显示全部楼层 |阅读模式
  机子上的 PHP 的版本太老了,所以就又重新搭建了相关的开发环境,使用了最新的 PHP 5.3.5,总结一下:
  1,安装 XAMPP:
  这种安装是最简单的了,直接访问官网:http://www.apachefriends.org/zh_cn/xampp.html
  下载 DSC0000.jpg 适用于 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 (&quot;Could not connect to the database: <br />&quot;. mysql_error());
}
else{
echo &quot;connected successfully!&quot;;
}
?>
  > 安装 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 &quot;doc.php.net&quot;
Update of Channel &quot;doc.php.net&quot; succeeded
Updating channel &quot;pear.php.net&quot;
Channel &quot;pear.php.net&quot; is up to date
Updating channel &quot;pecl.php.net&quot;
Update of Channel &quot;pecl.php.net&quot; 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!
  文件下载链接:http://files.cnblogs.com/catprayer/go-pear_new.rar
  直接解压放入根目录运行即可,按照提示来安装。

运维网声明 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-105565-1-1.html 上篇帖子: PHP总的画图功能----绘制字符之中文的绘制~~ 下篇帖子: PHP & Memcached 实例
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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