Apache之Windows下环境配置总结

一、安装

 

官网下载windows版 http://httpd.apache.org/

 

httpd-2.4.12-x64-vc11-r2.zip

 

解压到D盘:D:\httpd-2.4.12-x64-vc11-r2

 

进入目录bin下,然后按住shift+右键,选择在此处打开命令窗口 输入命令 httpd.exe -k install 安装apache。

 

httpd.exe -k start|stop|restart 分别表示启动、停止、重启

 

如果希望在任何目录下都可以运行httpd 指令,则在环境变量path增加apache中bin目录所在路径即可

 

进入conf目录修改httpd.conf

 

Define SRVROOT "/Apache24"

ServerRoot "${SRVROOT}"

改成

Define SRVROOT "D:/httpd-2.4.12-x64-vc11-r2/Apache24"

ServerRoot "${SRVROOT}"

 

#Listen 12.34.56.78:80

Listen 80

改成

#Listen 12.34.56.78:80

Listen 80

Listen 8081

 

bin下的ApacheMonitor.exe可用来管理apache服务

重启Apache服务 访问 http://localhost:80或8081,能正常显示则表示安装成功

 

启动时若提示端口被占用,可在开始-运行-cmd,输入:netstat –ano可以查看所有进程

列出当前所有运行进程:tasklist

结束某个进程:Tskill pid号

也可找到pid,在任务管理器服务那关闭

 

若服务无法正常安装,首先确定软件32位和64位是否和自己的系统匹配

其次,看电脑有没有安装软件相应的运行包,比如你下载的是VC9版本,那么你需要先安装Microsoft Visual C++ 2008 Redistributable ,同理VC11版本你需要安装Microsoft Visual C++ 2012 Update 4 Redistributable Package (X86 & x64)

在ApacheHaus网站的最底部提供了相应的Visual Studio Redistributable Packages下载链接

 

二、配置虚拟目录

 

在F:/znsphpsite/blog 下新建index.html

修改配置文件

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

#配置虚拟目录
<IfModule dir_module>
    #定义主页
    DirectoryIndex index.html index.htm index.php
    #定义虚拟目录名称,并指定具体目录
    Alias /myblog "F:/znsphpsite/blog"
    <Directory "F:/znsphpsite/blog">
    #访问权限设置
    Options Indexes FollowSymLinks  
    AllowOverride None
    Require all granted
    </Directory>	
</IfModule>

老版的allow from all=新版require all granted,老版deny from all=新版 require all denied

 

访问测试 http://localhost:8081/myblog/

 

三、配置虚拟主机

 

在http.conf去掉#号开启

Include conf/extra/httpd-vhosts.conf

 

在httpd-vhosts.conf加入代码

<VirtualHost *:80 >
    ServerAdmin test@qq.com
    DocumentRoot "F:/znsphpsite/bbs"
    ServerName bbs.zengnansheng.cn
    ErrorLog "logs/bbs.zengnansheng.cn-error_log"
    CustomLog "logs/bbs.zengnansheng.cn-access_log" common
</VirtualHost>

修改C:\Windows\System32\drivers\etc\hosts文件,增加如下代码

 

127.0.0.1       bbs.zengnansheng.cn

 

此时访问效果 会提示没有权限

 

为了解决403 forbidden 需添加如下代码

<Directory "F:/znsphpsite">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Require all granted
</Directory>

然后再访问即可

 

 

配置多站点只需要增加virtualhost

<Directory "F:/znsphpsite">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Require all granted
</Directory>
<VirtualHost *:80 >
    ServerAdmin test@qq.com
    DocumentRoot "F:/znsphpsite/bbs"
    ServerName bbs.zengnansheng.cn
    DirectoryIndex index.php
    ErrorLog "logs/bbs.zengnansheng.cn-error_log"
    CustomLog "logs/bbs.zengnansheng.cn-access_log" common
</VirtualHost>
<VirtualHost *:80 >
    ServerAdmin test@qq.com
    DocumentRoot "F:/znsphpsite/blog"
    ServerName blog.zengnansheng.cn
    DirectoryIndex index.php
    ErrorLog "logs/blog.zengnansheng.cn-error_log"
    CustomLog "logs/blog.zengnansheng.cn-access_log" common
</VirtualHost>

 

转载于:https://www.cnblogs.com/zengnansheng/p/10385973.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值