centos中apache使用教程

一、安装Apache服务

1 检查是否安装了Apache服务器软件

rpm -qa | grep -i httpd

 2 查看apache2的命令

 httpd -V

3  停止和重启apache

其中HTTPD_ROOT和SERVER_CONFIG_FILE  就可以确定httpd.conf的路径了

假设当前Linux用户的apahce安装目录为/usr/local/apache2,那么在命令行终端中使用以下命令启动,

3 

1. 启动apahce的命令:
/usr/local/apache2/bin/apachectl start apache
2.  停止apache的命令:
/usr/local/apache2/bin/apachectl stop  
3.  重启apache的命令:
/usr/local/apache2/bin/apachectl restart 
要在重启 Apache 服务器时不中断当前的连接,则应运行:
/usr/local/sbin/apachectl graceful

如果当前用户的apache已经安装为linux的服务的话,可以使用以下命令进行以上操作。
1. 启动apache
service httpd start 
2. 停止服务apache
service httpd stop 
3. 重新启动apache
service httpd restart

 二、配置Apache服务 

1、Apache服务常见配置文件介绍

文件名称

作用

/etc/httpd

服务目录

/etc/httpd/conf/httpd.conf

主配置文件

/var/www/html 

网站数据目录

/var/log/httpd/access_log

访问日志

/var/log/httpd/error_log

错误日志

/etc/httpd/conf.d

附加模块配置文件

/etc/httpd/modules

模块文件路径链接

/etc/httpd/bin/

二进制命令

/etc/httpd/logs

默认日志文件位置


 


以下总结在配置及启动apache2时出现报错的处理方法

一、启动apache遇到错误:httpd: Could not reliably determine the server's fully qualified domain name

[root@server httpd-2.2.4]# /usr/local/apache/bin/apachectl start
 
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
 
1)进入apache的安装目录:(视个人安装情况而不同) [root@server ~]#
 

cd /usr/local/apache/conf


2)编辑httpd.conf文件,搜索"#ServerName",添加ServerName localhost:80
[root@server conf]# ls

ls


extra  httpd.conf  magic  mime.types  original
[root@server conf]# vi httpd.conf

vi httpd.conf


#ServerName www.example.com:80
ServerName localhost:80
3)再重新启动apache 即可。
[root@server ~]# /usr/local/apache/bin/apachectl restart

/usr/local/apache/bin/apachectl restart

二、重启报错apache2 address already in use:make_sock:could not bind to address [::]:80

此错误为端口被占用,只有进入root用户,才可以查看所有端口被占用的情况。

$su

#netstat -lnp | grep 80

tcp 0      x x.x.x.x:8084        ...   listen   1167/mono

tcp 0      x x.x.x.x:80          ...   listen   1194/inetd

udp 0      x x.x.x.x:2080        ...   listen   14427/drcomauthsvr

查看知道是Inetd占用了80端口

#kill 1194

#exit //退出root用户

$sudo apapche2ctl -k start

启动成功!

三、在安装完apache2之后的默认index.html网页里面输入文字显示乱码,修改AddDefaultCharset 也没有用,即使在网页头部添加meta,指定charset=GB2312|GBK也没有用

注意,亲,此处因为默认文档的字号为h1,大号字体,中文无法显示,此处修改为小号字体即可,本人修改为h5,乱码消失,正常显示中文!

四、在网页运行html文件调用cgi程序时,提示找不到cgi程序以及找到程序后得不到想要的结果。

首先查看apache2配置文件,在/etc/apache2/site-enables查看系统默认的cgi-bin目录,可以在这个里面根据需要来修改默认cgi-bin目录。apt安装完后默认的cgi-bin目录是在/usr/lib/cgi-bin/

具体是修改ScriptAlias参数,如果你不知道你的类似site-enables的目录在哪,毕竟各个版本有些不一样,可以直接搜索ScriptAlisa这个参数,因为不管哪个版本,这个参数基本没改动。
--------------------- 
作者:sam喵喵 
来源:CSDN 
原文:https://blog.csdn.net/zhaomininternational/article/details/42293511?utm_source=copy 
版权声明:本文为博主原创文章,转载请附上博文链接!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值