windows 安装php_如何在Windows上安装PHP

windows 安装php

We’ve previously shown you how to get a working local installation of Apache on your Windows PC. In this article, we’ll show how to install PHP on Windows. This tutorial’s instructions refer to PHP 5 and Apache 2.2.

我们之前已经向您展示了如何在Windows PC上本地安装Apache 。 在本文中,我们将展示如何在Windows上安装PHP。 本教程的说明参考PHP 5和Apache 2.2。

为什么要使用PHP? (Why PHP?)

PHP remains the most widespread and popular server-side programming language on the web. It is installed by most web hosts, has a simple learning curve, close ties with the MySQL database, and an excellent collection of libraries to cut your development time. PHP may not be perfect, but it should certainly be considered for your next web application. Both Yahoo and Facebook use it with great success.

PHP仍然是Web上最广泛和最受欢迎的服务器端编程语言。 它是由大多数Web主机安装的,具有简单的学习曲线,与MySQL数据库的紧密联系以及可缩短开发时间的出色的库集合。 PHP可能并不完美,但是您的下一个Web应用程序肯定会考虑使用PHP。 雅虎和Facebook都成功使用了它。

为什么要在本地安装PHP? (Why Install PHP Locally?)

Installing PHP on your development PC allows you to safely create and test a web application without affecting the data or systems on your live website. This article describes PHP installation as a module within the Windows version of Apache 2.2. Mac and Linux users will probably have it installed already.

在开发PC上安装PHP可使您安全地创建和测试Web应用程序,而不会影响实时网站上的数据或系统。 本文将PHP安装描述为Windows版本的Apache 2.2中的一个模块。 Mac和Linux用户可能已经安装了它。

多合一套餐 (All-in-One packages)

There are some excellent all-in-one Windows distributions that contain Apache, PHP, MySQL and other applications in a single installation file, e.g. XAMPP (including a Mac version), WampServer and Web.Developer. There is nothing wrong with using these packages, although manually installing Apache and PHP will help you learn more about the system and its configuration options.

有一些出色的多合一Windows发行版,它们在单个安装文件中包含Apache,PHP,MySQL和其他应用程序,例如XAMPP (包括Mac版本 ), WampServerWeb.Developer 。 尽管手动安装Apache和PHP将帮助您了解有关系统及其配置选项的更多信息,但使用这些软件包没有什么错。

PHP安装程序 (The PHP Installer)

Although an installer is available from php.net, I would recommend the manual installation if you already have a web server configured and running.

尽管可以从php.net获得安装程序,但如果您已经配置并运行了Web服务器,我还是建议您手动安装。

手动安装 (Manual Installation)

Manual installation offers several benefits:

手动安装具有以下优点:

  • backing up, reinstalling, or moving the web server can be achieved in seconds (see 8 Tips for Surviving PC Failure) and

    可以在几秒钟内完成备份,重新安装或移动Web服务器的操作(请参阅PC失败后的8条提示 ),并且

  • you have more control over PHP and Apache configuration.

    您可以更好地控制PHP和Apache配置。

步骤1:下载档案 (Step 1: Download the files)

Download the latest PHP 5 ZIP package from www.php.net/downloads.php

www.php.net/downloads.php下载最新PHP 5 ZIP软件包

As always, virus scan the file and check its MD5 checksum using a tool such as fsum.

与往常一样,病毒扫描文件并使用诸如fsum之类的工具检查其MD5校验和。

步骤2:解压缩文件 (Step 2: Extract the files)

We will install the PHP files to C:\php, so create that folder and extract the contents of the ZIP file into it.

我们将PHP文件安装到C:\php ,因此创建该文件夹并将ZIP文件的内容提取到其中。

PHP can be installed anywhere on your system, but you will need to change the paths referenced in the following steps.

PHP可以安装在系统上的任何位置,但是您需要更改以下步骤中引用的路径。

步骤3:配置php.ini (Step 3: Configure php.ini)

Copy C:\php\php.ini-development to C:\php\php.ini. There are several lines you will need to change in a text editor (use search to find the current setting). Where applicable, you will need to remove the leading semicolon to uncomment these setting.

C:\php\php.ini-development复制到C:\php\php.ini 。 您需要在文本编辑器中更改几行(使用搜索查找当前设置)。 如果适用,您将需要删除前导分号以取消注释这些设置。

Define the extension directory:

定义扩展目录:

extension_dir = "C:/php/ext"

Enable extensions. This will depend on the libraries you want to use, but the following extensions should be suitable for the majority of applications:

启用扩展。 这将取决于您要使用的库,但是以下扩展名应该适合大多数应用程序:

extension=curl
extension=gd2
extension=mbstring
extension=mysql
extension=pdo_mysql
extension=xmlrpc

If you want to send emails using the PHP mail() function, enter the details of an SMTP server (your ISP’s server should be suitable):

如果要使用PHP mail()函数发送电子邮件,请输入SMTP服务器的详细信息(您的ISP的服务器应该合适):

[mail function]
; For Win32 only.
SMTP = mail.myisp.com
smtp_port = 25

; For Win32 only.
sendmail_from = my@emailaddress.com

步骤4:将C:\php添加到路径环境变量 (Step 4: Add C:\php to the path environment variable)

To ensure Windows can find PHP, you need to change the path environment variable. Open Settings, type ‘environment variables’ into the search field and open the result. Select the “Advanced” tab, and click the “Environment Variables” button.

为了确保Windows可以找到PHP,您需要更改path环境变量。 打开设置,在搜索字段中输入“环境变量”,然后打开结果。 选择“高级”选项卡,然后单击“环境变量”按钮。

Scroll down the System variables list and click on “Path” followed by the “Edit” button. Click “Edit text” and add ;C:\php to the end of the Variable value line (remember the semicolon).

向下滚动系统变量列表,然后单击“路径”,然后单击“编辑”按钮。 单击“编辑文本”,然后在变量值行的末尾添加;C:\php (记住分号)。

PHP path environment variable

Now click OK until you’re out. You might need to reboot at this stage.

现在,单击“确定”,直到出门为止。 您可能需要在此阶段重新启动。

步骤5:将PHP配置为Apache模块 (Step 5: Configure PHP as an Apache module)

Ensure Apache is not running (use net stop Apache2.2 from the command line) and open its confhttpd.conf configuration file in an editor. The following lines should be changed:

确保Apache未运行(从命令行使用net stop Apache2.2 ),然后在编辑器中打开其confhttpd.conf配置文件。 以下行应更改:

On line 239, add index.php as a default file name:

在第239行上,将index.php添加为默认文件名:

DirectoryIndex index.php index.html

At the bottom of the file, add the following lines (change the PHP file locations if necessary):

在文件的底部,添加以下行(如有必要,更改PHP文件的位置):

# PHP5 module
LoadModule php5_module "c:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "C:/php"

Save the configuration file and test it from the command line (Start > Run > cmd):

保存配置文件并从命令行对其进行测试(“开始”>“运行”>“ cmd”):

cd Apache2bin 
httpd -t

步骤6:测试PHP文件 (Step 6: Test a PHP file)

Create a file named index.php in Apache’s web page root (either htdocs or D:WebPages) and add this code:

在Apache的网页根目录(htdocs或D:WebPages)中创建一个名为index.php的文件,并添加以下代码:

<?php phpinfo(); ?>

Ensure Apache has started successfully, open a web browser and enter the address http://localhost/. If all goes well, a “PHP version” page should appear showing all the configuration settings.

确保Apache已成功启动,打开Web浏览器并输入地址http:// localhost / 。 如果一切顺利,将出现“ PHP版本”页面,显示所有配置设置。

See also:

也可以看看:

Best of luck!

祝你好运!

翻译自: https://www.sitepoint.com/how-to-install-php-on-windows/

windows 安装php

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值