linuxapache开机启动命令

fiy 其他 183

回复

共3条回复 我来回复
  • worktile的头像
    worktile
    Worktile官方账号
    评论

    在Linux系统中,要设置Apache在开机时自动启动,需要执行以下步骤:

    1. 打开终端窗口,以管理员身份登录或切换到超级用户模式(root)。

    2. 输入以下命令来编辑Apache的启动脚本文件:
    “`bash
    vi /etc/init.d/apache
    “`

    3. 在编辑器中,输入以下内容:
    “`bash
    #!/bin/bash
    #
    # apache This shell script takes care of starting and stopping
    # Apache HTTP Server
    #
    # chkconfig: – 85 15
    # description: Apache is a World Wide Web server. It is used to serve \
    # HTML files and CGI.
    # processname: httpd
    # config: /etc/httpd/conf/httpd.conf
    # config: /etc/sysconfig/httpd
    # pidfile: /var/run/httpd/httpd.pid

    # Source function library.
    . /etc/rc.d/init.d/functions

    # See how we were called.
    case “$1” in
    start)
    echo -n “Starting httpd: ”
    daemon /usr/sbin/httpd
    echo
    touch /var/lock/subsys/httpd
    ;;
    stop)
    echo -n “Shutdown httpd: ”
    killproc httpd
    echo
    rm -f /var/lock/subsys/httpd
    ;;
    status)
    status httpd
    ;;
    restart)
    echo -n “Restarting httpd: ”
    killproc httpd -HUP
    echo
    ;;
    *)
    echo “Usage: $0 {start|stop|status|restart}”
    exit 1
    esac

    exit 0
    “`

    4. 使用以下命令保存并退出编辑器:
    按 `Esc` 键,然后输入 `:wq`,按回车键。

    5. 使用以下命令将文件的所有者更改为root,并赋予可执行权限:
    “`bash
    chmod 755 /etc/init.d/apache
    chown root:root /etc/init.d/apache
    “`

    6. 最后,使用以下命令将apache服务添加到系统服务列表中:
    “`bash
    chkconfig –add apache
    chkconfig apache on
    “`

    现在,当您的Linux系统启动时,Apache将自动启动。您可以使用以下命令来手动控制Apache服务:
    – 启动Apache服务:`service apache start`
    – 停止Apache服务:`service apache stop`
    – 查看Apache服务状态:`service apache status`
    – 重启Apache服务:`service apache restart`

    请注意,以上命令需要以root用户或具有sudo权限的用户身份执行。

    2年前 0条评论
  • 不及物动词的头像
    不及物动词
    这个人很懒,什么都没有留下~
    评论

    在Linux系统中,可以使用systemd作为服务管理器来控制Apache在开机时自动启动。下面是在不同Linux发行版中启动Apache的命令示例:

    1. Ubuntu和Debian:
    – 检查Apache是否已经被systemd启用:`systemctl is-enabled apache2`
    – 启用Apache自动启动:`sudo systemctl enable apache2`
    – 手动启动Apache:`sudo systemctl start apache2`
    – 停止Apache:`sudo systemctl stop apache2`
    – 重启Apache:`sudo systemctl restart apache2`

    2. CentOS和Red Hat:
    – 检查Apache是否已经被systemd启用:`systemctl is-enabled httpd`
    – 启用Apache自动启动:`sudo systemctl enable httpd`
    – 手动启动Apache:`sudo systemctl start httpd`
    – 停止Apache:`sudo systemctl stop httpd`
    – 重启Apache:`sudo systemctl restart httpd`

    3. Fedora:
    – 检查Apache是否已经被systemd启用:`systemctl is-enabled httpd`
    – 启用Apache自动启动:`sudo systemctl enable httpd`
    – 手动启动Apache:`sudo systemctl start httpd`
    – 停止Apache:`sudo systemctl stop httpd`
    – 重启Apache:`sudo systemctl restart httpd`

    需要注意的是,在某些发行版中,Apache的服务名称可能是`apache2`,而不是`httpd`,因此请根据实际情况进行相应的调整。

    此外,还可以使用`chkconfig`命令来启用和禁用Apache服务。但是,新版本的Linux发行版更倾向于使用systemd进行服务管理。

    2年前 0条评论
  • fiy的头像
    fiy
    Worktile&PingCode市场小伙伴
    评论

    在Linux系统中,Apache是一种常见的Web服务器软件。要在Linux启动时自动启动Apache,可以使用以下方法:

    1. 使用系统的init.d服务脚本:
    a. 打开终端,使用root权限登录系统。
    b. 导航到/etc/init.d目录下:
    “`
    cd /etc/init.d
    “`
    c. 创建一个名为apache的启动脚本:
    “`
    sudo nano apache
    “`
    d. 在打开的编辑器中,输入以下内容:
    “`
    #!/bin/sh
    ### BEGIN INIT INFO
    # Provides: apache
    # Required-Start: $remote_fs $syslog
    # Required-Stop: $remote_fs $syslog
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: Start Apache web server
    ### END INIT INFO

    # Start apache
    /etc/init.d/apache2 start
    exit 0
    “`
    e. 保存并关闭文件。
    f. 授权启动脚本并添加到启动项中:
    “`
    sudo chmod +x apache
    sudo update-rc.d apache defaults
    “`
    g. 重新启动系统:
    “`
    sudo reboot
    “`
    此时,Apache应该会自动启动。

    2. 使用systemctl命令:
    a. 打开终端,使用root权限登录系统。
    b. 使用以下命令启动Apache服务并设置为开机自启动:
    “`
    sudo systemctl start apache2
    sudo systemctl enable apache2
    “`
    c. 重新启动系统:
    “`
    sudo reboot
    “`
    Apache应该会自动启动。

    3. 使用rc.d和chkconfig命令:
    a. 打开终端,使用root权限登录系统。
    b. 使用以下命令启动Apache服务并设置为开机自启动:
    “`
    sudo /etc/init.d/apache2 start
    sudo chkconfig apache2 on
    “`
    c. 重新启动系统:
    “`
    sudo reboot
    “`
    Apache应该会自动启动。

    以上是在常见的Linux系统上启动Apache的方法。根据您所使用的具体Linux发行版和版本,可能会略有不同。请注意在执行命令时谨慎,并确保在对系统进行任何更改之前备份重要数据。

    2年前 0条评论
注册PingCode 在线客服
站长微信
站长微信
电话联系

400-800-1024

工作日9:30-21:00在线

分享本页
返回顶部