Linux下启动和停止apache服务,linuxapache


文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

本文使用的Linux系统为CentOS 7,下面将介绍apache服务的启动、关闭与设置。apache在CentOS 7中一般是默认安装的,而且服务名字为httpd

1. 安装apache及查看相关配置

# apache安装命令

$ sudo yum install httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Package httpd-2.4.6-45.el7.centos.4.x86_64 already installed and latest version
Nothing to do


# 查看apache文件的位置

$ sudo find / -name httpd
/run/httpd
/etc/logrotate.d/httpd
/etc/sysconfig/httpd
/etc/httpd
/var/log/httpd
/var/cache/httpd
/usr/sbin/httpd
/usr/lib64/httpd
/usr/share/httpd
/usr/include/httpd
/usr/libexec/initscripts/legacy-actions/httpd

Apache配置文件位于/etc/httpd/conf,主要的配置文件是/etc/httpd/conf/httpd.conf, apache相关的配置信息都可以在这个文件中看到。

2. apache服务的启动与关闭

# 启动服务
$ sudo systemctl start httpd.service

# 查看服务
$ ps aux | grep httpd
root     *  0.3  0.0 220444  4956 ?        Ss   15:46   0:00 /usr/sbin/httpd -DFOREGROUND
apache   *  0.0  0.0 220444  2492 ?        S    15:46   0:00 /usr/sbin/httpd -DFOREGROUND
apache   *  0.0  0.0 220444  2488 ?        S    15:46   0:00 /usr/sbin/httpd -DFOREGROUND
apache   *  0.0  0.0 220444  2488 ?        S    15:46   0:00 /usr/sbin/httpd -DFOREGROUND
apache   *  0.0  0.0 220444  2488 ?        S    15:46   0:00 /usr/sbin/httpd -DFOREGROUND
apache   *  0.0  0.0 220444  2488 ?        S    15:46   0:00 /usr/sbin/httpd -DFOREGROUND

# 停止服务
$ sudo systemctl stop httpd.service

# 重启服务
$ sudo systemctl restart httpd.service

启动服务后,可以在外网通过服务器的IP地址访问。可以看到如下界面:

3. 配置自己可以在外部访问的内容

可以在/var/www/html下创建一个软链接,链接到你想要在外部访问的内容,同时要修改要访问目录的权限。

$ sudo ln -s your_path/images /var/www/html
$ sudo chmod 755 images

注:需要确保images的所有父目录都有权限,同时images的路径应该是全路径。

   
0
0
查看评论

相关内容