Windows下Apache与PHP的安装与配置

下载Apache

  Apache的官网(http://httpd.apache.org)

  1.把解压后的Apache拷贝到要安装的目标位置。建议拷贝到C盘根目录下,因为这是其默认设置。

  2.我选择的是拷贝到C盘根目录,这样就需要对Apache配置文件C:httpdconfhttpd.conf进行修改,打开该文件,将c:/Apache24全部替换成C:/httpd

  3.运行cmd,进入httpd下的bin目录,为了检查httpd.conf有无问题,我们输入httpd.exe -t,如果正常的话只会显示一行Syntax OK,如果有错的话则会告诉我们是哪儿错了。
  C:httpdin>httpd.exe -t
  AH00558: httpd.exe: Could not reliably determine the server's fully qualified do main name, using fe80::29b5:91f1:1dba:81be. Set the 'ServerName' directive globally to suppress this message
  Syntax OK
  我这里得到的错误信息是说ServerName有问题。在httpd.conf中找到ServerName,原来是该设置默认是注释掉的,去掉前面的#号,保存文件。重新执行httpd.exe -t,测试通过。

  4.在控制台中运行httpd.exe -k install将Apache安装成windows服务,这样Apache以后将自动运行。
    D:Apache24in>httpd.exe -k install
    Installing the Apache2.4 service
    The Apache2.4 service is successfully installed.
    Testing httpd.conf....
    Errors reported here must be corrected before the service can be started.

  5.运行httpd.exe -k start启动服务,如果没有错误提示,在浏览器中输入http://127.0.0.1或者http://localhost将显示

下载php

  6. 将PHP解压后拷贝到安装位置,我这里选择的是C:/php。然后将php.ini-development复制并重命名为php.ini,如果是部署,则复制php.ini-production。

  7. 编辑Apache的httpd.conf

  查找LoadModule,在其后面增加下面配置,如果你的PHP在C盘的话,请将D:换成C:,另外注意路径使用/。
  LoadModule php7_module C:/php/php7apache2_4.dll
  PHPIniDir C:/php

  查找AddType,加入如下配置:
  AddType application/x-httpd-php .php
  查找DirectoryIndex,加入index.php,如果希望index.php优先于index.html,则将其放在前面。
  <IfModule dir_module>
    DirectoryIndex index.html index.php
  </IfModule>

  8.保存配置,在命令行中运行httpd.exe -t检查配置,如果没有问题,则运行httpd.exe -k restart重启Apache服务。

  9.在Apache24htdocs目录下新建一个phpinfo.php文件

** 如果有什么问题 请评论中回复,我会即使回复.谢谢。。。。

原文地址:https://www.cnblogs.com/xuchuanbing/p/xupp.html