Debian&Ubuntu安装apache2

Debian&Ubuntu安装apache2

先更新一下

apt-get update

查看可安装软件列表(后面加上grep,可以使用正则)

apt-cache search apach |grep apache2

安装apache2

apt-get install apache2

安装完成,查看一下页面

Debian&Ubuntu安装apache2


此时,如果你打算关闭一下apache,执行

apache2 –k stop

却是不行了,会报一连串的错误

[email protected]:~# apache2 -k restart

[Mon May 08 23:01:12.725179 2017][core:warn] [pid 2898] AH00111: Config variable ${APACHE_LOCK_DIR} is notdefined

[Mon May 08 23:01:12.725330 2017][core:warn] [pid 2898] AH00111: Config variable ${APACHE_PID_FILE} is notdefined

[Mon May 08 23:01:12.725442 2017] [core:warn][pid 2898] AH00111: Config variable ${APACHE_RUN_USER} is not defined

[Mon May 08 23:01:12.725530 2017][core:warn] [pid 2898] AH00111: Config variable ${APACHE_RUN_GROUP} is notdefined

[Mon May 08 23:01:12.725622 2017][core:warn] [pid 2898] AH00111: Config variable ${APACHE_LOG_DIR} is notdefined

[Mon May 08 23:01:12.728170 2017][core:warn] [pid 2898:tid 140415845017472] AH00111: Config variable${APACHE_LOG_DIR} is not defined

[Mon May 08 23:01:12.728362 2017][core:warn] [pid 2898:tid 140415845017472] AH00111: Config variable${APACHE_LOG_DIR} is not defined

[Mon May 08 23:01:12.728431 2017][core:warn] [pid 2898:tid 140415845017472] AH00111: Config variable${APACHE_LOG_DIR} is not defined

AH00526: Syntax error on line 74 of/etc/apache2/apache2.conf:

Invalid Mutex directory in argumentfile:${APACHE_LOCK_DIR}

 

解决方式一(最直接,最常用):

使用以下命令(当然,也可以用他来start,restart等等)

/etc/init.d/apache2 stop

 

解决方式二:

运行以下命令(每次重新登录,都要执行一次,烦得很):

source /etc/apache2/envvars


你就可以正常使用以下命令

apache2 –k start|stop|restart

 

方式三

可以使用apachectl命令

apachectl start

如果有安装systemctl命令,你也可以使用以下命令

systemctl start apache2.service

不加service也可以

systemctl start apache2

 

备注apachectl命令是apache2.4之后才有的,可以让用户更加方便的使用apache

所以说,最好使用apachectl命令