apache-service的使用

apache service目录设置

设置Apache HTTP Server的文件根目录(DocumentRoot)
     安装Apache 时,系统会给定一个缺省的文件根目录
     如果你觉得这个网页存在这个缺省目录不方便,需要另外设个Apache 文件根目录
     你可以修改Apache的配置文件httpd.conf里有关根目录的设置。

Apache HTTP Server的缺省文件根目录(DocumentRoot)是:
      DocumentRoot "C:Program FilesApache Software FoundationApache2.2htdocs" 

修改Apache 文件根目录(DocumentRoot)的操作如下:
   1> 为了避免修改失误,请先备份你的Apach配置文件httpd.conf,该配置文件的路径是
   2> 打开http.conf文件找到DocumentRoot为开头的那一行,将
               DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs" 
               改成新的 DocumentRoot 路径,比如你新的路径为 C:htdocs,就改成 
               DocumentRoot "C:/htdocs" 
   3> 然后找到httpd.conf 文件中的如下内容:
               # This should be changed to whatever you set DocumentRoot to.
               <Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"> 
               将 Diectory 中的路径改成你新设的文件根目录,比如: 
               <Directory "C:/htdocs"> 
   4>保存配置文件httpd.conf ,重启Apache Service

apache server 修改端口

 找到Listener 80 (--->修改为自己的端口即可)

常见的错误

 当修改Apache的配置后,重启启动往往会出现the requested operation has failed报错问题,初学Apache搭建,遇到了这种问题很是困扰。
 原因一:Apache服务器端口冲突
    解决方法一:打开cmd命令行,用”netstat -aon | findstr “80”“命令查看端口占用程序的PID,然后再用”tasklist | findstr “PID”“查看被哪个进程占用了。然后kill掉此进程。 
    解决方法二:更改Apache的端口号。在httpd.conf文件中,找到”Listen 80”属性,将80改为其他未被占用的端口。
原因二:更改Apache服务器默认存储的文件路径
    Apache服务器的核心配置文件是httpd.conf,默认路径为“Apache安装路径conf”,打开该文件,定为到DocumentRoot。
    该路径用于指定网络路径,存放主页配置的目录,如:DocumentRoot “D:/Webpage”,句末不能加“/”。
    同时定位到Directory行,此处为服务器的虚拟路径,要与DocumentRoot配置相同,如:<”Directory “D:/Webpage”>
原因三:httpd.conf配置错误
    如果apache的配置文件httpd.conf错误,可以使用命令行启动apache,并带上参数,apache会提示哪句有误,然后可以针对性的解决问题。 
    解决方法:打开cmd,到apache安装路径in下,执行“httpd.exe -w -n “Apache2.2” -k start”,其中Apache2.2位安装Apache服务器的目录名。
原文地址:https://www.cnblogs.com/ssgao/p/8805812.html