linux环境下配置apache服务器,linuxapache


我在debian环境下搭建的apache服务器

软件源使用的阿里源

这时候打开命令行输入

sudo apt install apache2

然后安装成功,可以进入/etc/init.d查看系统服务

进入之后可以看到出现apache2说明安装成功了

那么如何开启apache服务呢?

任意路径下service apache2 [start|stop|status]即可启动|停止|查看状态

 apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2017-12-26 08:52:50 CST; 8min ago
  Process: 3733 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
 Main PID: 3737 (apache2)
    Tasks: 7 (limit: 4915)
   CGroup: /system.slice/apache2.service
           ├─3737 /usr/sbin/apache2 -k start
           ├─3738 /usr/sbin/apache2 -k start
           ├─3739 /usr/sbin/apache2 -k start
           ├─3740 /usr/sbin/apache2 -k start
           ├─3741 /usr/sbin/apache2 -k start
           ├─3742 /usr/sbin/apache2 -k start
           └─3743 /usr/sbin/apache2 -k start

12月 26 08:52:50 kali systemd[1]: Starting The Apache HTTP Server...
12月 26 08:52:50 kali apachectl[3733]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
12月 26 08:52:50 kali systemd[1]: Started The Apache HTTP Server.
这是成功启动后的服务器状态

服务器的根目录是/var/www/html

于是乎写一个shell方便下次使用

脚本判断apache是否启动,没有启动则启动,然后在资源管理器中打开html文件所在路径

#!/bin/bash

test=$(ps aux | grep apache2 | grep -v 'grep' | wc -l)
if [ $test -gt 0 ];then
	echo "$(date) httpd is running..."
else echo "$(date) httpd is not running...  starting ..."
	service apache2 start
fi

nautilus /var/www/html

echo 'run successfully...'
最终记得为这个bash文件添加可执行权限


相关内容

    暂无相关文章