Windows下Apache服务器搭建

Windows下Apache服务器搭建

远航
2022-04-20 / 0 评论 / 87 阅读 / 正在检测是否收录...
一、软件下载

下载WINDOWS下的最新ZIP压缩包,推介下载网址http://www.apachelounge.com/download/

32位:http://www.apachelounge.com/download/VC15/binaries/httpd-2.4.29-Win32-VC15.zip

64位:http://www.apachelounge.com/download/VC15/binaries/httpd-2.4.29-Win64-VC15.zip

为了让Apache服务器发挥更好的性能,请根据自己的系统选择下载,如您不清楚自己的系统是64位还是32位,请下载32版本
我下载的是64位版本,下文以64位做讲解

二、解压文件

爱解压到哪解压到哪

Read me.txt会告诉我们如何使用,我就是根据里面的说明配置的,其中Apache文件夹就是我们要用到的服务器程序

三、修改配置文件

我直接将解压后的Apache24文件夹剪切到D:盘根目录,

我的目录是:D:\Apache24

文本编辑器打开Apache24\conf\httpd.conf 体检Notepad++,vscode,IDE

注意:对于最新版本2.4.39以上,只需要修改 该配置文件中第37行中SRVROOT的定义,如Apach24解压的目录即可飞机到第四部

Define SRVROOT "c:/httpd-2.4.39-win64-VC15/Apache24"

  1. 修改第37行ServerRoot "c:/Apache24" 改为 ServerRoot "d:/Apache24"
  2. 修改第60行修改端口 Listen 80
  3. 修改第246行DocumentRoot "c:/Apache24/htdocs" 改为 DocumentRoot "d:/Apache24/htdocs"
  4. 修改第247行<Directory "c:/Apache24/htdocs"> 改为 <Directory "d:/Apache24/htdocs">
  5. 修改第363行ScriptAlias /cgi-bin/ "c:/Apache24/cgi-bin/" 改为 ScriptAlias /cgi-bin/ "d:/Apache24/cgi-bin/"
  6. 修改第379行<Directory "c:/Apache24/cgi-bin"> 改为 <Directory "d:/Apache24/cgi-bin">
  7. 修改第510行去掉# Include conf/extra/httpd-vhosts.conf
  8. 修改第183行去掉# LoadModule vhost_alias_module modules/mod_vhost_alias.so
  9. 修改第251行找到以下部分代码(配置是否开启目录服务等等)

    DocumentRoot "${SRVROOT}/htdocs"
    <Directory "${SRVROOT}/htdocs">
     #
     # Possible values for the Options directive are "None", "All",
     # or any combination of:
     #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
     #
     # Note that "MultiViews" must be named *explicitly* --- "Options All"
     # doesn't give it to you.
     #
     # The Options directive is both complicated and important.  Please see
     # http://httpd.apache.org/docs/2.4/mod/core.html#options
     # for more information.
     #开启目录浏览
     Options Indexes FollowSymLinks
    
     #
     # AllowOverride controls what directives may be placed in .htaccess files.
     # It can be "All", "None", or any combination of the keywords:
     #   AllowOverride FileInfo AuthConfig Limit
     #
     AllowOverride None
    
     #
     # Controls who can get stuff from this server.
     #
     Require all granted
    </Directory>
  10. 接下来打开 httpd-vhosts.conf 文件。并针对性的对其进行修改

    <VirtualHost *:80>
     ServerAdmin 出问题后通知的邮件地址@qq.com
     DocumentRoot "${SRVROOT}/docs/dummy-host.example.com" # 网站根目录
     ServerName dummy-host.example.com # 一个域名或者ip可带端口号
     ServerAlias www.dummy-host.example.com#多个ip或者域名
     ErrorLog "logs/dummy-host.example.com-error.log"
     CustomLog "logs/dummy-host.example.com-access.log" common
    </VirtualHost>
四、运行服务器

进入Apache24\bin\ 目录下,如图所示

方法一:双击httpd.exe程序

此时会弹出一个窗口,当窗口打开时,服务器就是开启了

当将窗口关闭时,服务器也就关闭了

方法二:双击ApacheMonitor.exe

在任务栏会出现如下图标,右击小图标会显示“Open Apatch Monitor” ,点击打开Apache监视器

打开后界面如下图,点击Start即可启动服务器,如需停止服务器,点击Stop.

方法三:CMD命令行启动

httpd.exe

方法四:开机自动运行

// 添加开机启动
httpd.exe -k install // 执行命令后有的系统需要进入服务手动启动一次,比如win7
// 卸载开机启动
httpd.exe -k uninstall
五、测试Apache服务器是否成功搭建

在浏览器地址栏输入您本机的IP地址并回车即可

如网页显示 It works! 证明安装成功。

六、放入我们自己的文件并尝试下载

将Apache24\htdocs文件夹下面的 index.html 文件删除,我们刚才看到的 It works! 页面就是这个文件的作用,然后将我们的文件及文件夹放到 Apache24\htdocs 下面,浏览器就可以下载了。

2

评论

博主关闭了当前页面的评论