linux - Apache无法启动

查看:171
本文介绍了linux - Apache无法启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

请问各位大神,我安装完Apache后,无法启动是怎么回事咩?

代码如下:

[root@bogon httpd-2.4.20]# systemctl start httpd.service
Failed to start httpd.service: Unit httpd.service failed to load: No such file or directory.

[root@bogon httpd-2.4.20]# systemctl status httpd
● httpd.service
   Loaded: not-found (Reason: No such file or directory)
   Active: inactive (dead)
   
[root@bogon httpd-2.4.20]# 

明明已经安装好了哦,怎么说没有目录呢?
我将Apache安装在了/usr/bin/apache里面 ㄟ( ▔, ▔ )ㄏ

解决方案

原来是需要将Apache注册到Linux服务里面啊!
注册Apache到Linux服务
在Linux下用源代码方式编译安装完Apache后,启动关闭Apache可以通过如下命令实现: 

/usr/local/apache/bin/apachectl  start | stop | restart

如果想将httpd列入系统自动启动的服务,可以直接将上述的apachectl文件拷贝到 /etc/rc.d/init.d 中,然后在相应的启动级别如3,5中加入链接即可。命令如下:

cp /usr/local/apache2/bin/apachectl  /etc/rc.d/init.d/httpd     # 复制到init.d 并重命名为httpd

ln -s /etc/rc.d/init.d/httpd  /etc/rc.d/rc3.d/S61httpd

链接文件的S61是启动时的序号。当init.d目录下有httpd脚本后,我们就可以通过service命令来启动关闭apache了。在任意路径下执行:

service httpd start | stop | restart

这时有个问题就是:虽然apache已经可以自动启动,但在linux的服务列表中却看不到它,要添加服务,一般通过chkconfig --add xxx来实现,但需要脚本中有相应的信息才行,否则chkconfig就会提示:xxx 服务不支持 chkconfig。所以我们首先编辑httpd脚本,在第2行(#!/bin/sh下面)添加如下注释信息(包括#):

# chkconfig: 35 61 61
# description: Apache

第一行的3个参数意义分别为:在哪些运行级别启动httpd(3,5);启动序号(S61);关闭序号(K61)。注意:第二行的描述必须要写!
保存后执行:

chkconfig --add httpd                    #所有开机模式下自启动,另外chkconfig httpd on 表示345模式下自启动

就将httpd添加入服务了。在rc3.d、rc5.d路径中将来就会出现S61httpd的链接,其他运行级别路径中会出现K61httpd的链接。

运行下面的命令查看服务,就可以看到httpd的服务了。
chkconfig --list

这篇关于linux - Apache无法启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆