1.
首先确认是否已经安装了apache
dpkg --get-selections|grep apache
如果已经安装,则出现
apache2 install等等
2.
安装apache:
首先更新源列表 apt-get update
安装sudo apt-get install apache2
查看apache版本 apachectl -v
安装结束后:
产生的启动和停止文件是:/etc/init.d/apache2
启动:sudo apache2ctl -k start
停止:sudo apache2ctl -k stop
重新启动:sudo apache2ctl -k restart
产生的启动和停止文件是:/etc/init.d/apache2
启动:sudo apache2ctl -k start
停止:sudo apache2ctl -k stop
重新启动:sudo apache2ctl -k restart
为了方便识别ServerName,修改httpd.conf, 增加以下内容:
ServerName 127.0.0.1:80
配置文件保存在:/etc/apache2ServerName 127.0.0.1:80
注:
普通的apache发行版本配置文件是:
httpd.conf
Ubuntu发行版本的主配置文件是:
apache2.conf
在apache2.conf引用到了以下文件:
# 包含动态模块的配置:
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf
# 包含用户自己的配置:
Include /etc/apache2/httpd.conf
# 包含端口监听的配置:
Include /etc/apache2/ports.conf
# 包含一般性的配置语句片断:
Include /etc/apache2/conf.d/
# 包含虚拟主机的配置指令:
Include /etc/apache2/sites-enabled/
3.
httpd.conf
Ubuntu发行版本的主配置文件是:
apache2.conf
在apache2.conf引用到了以下文件:
# 包含动态模块的配置:
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf
# 包含用户自己的配置:
Include /etc/apache2/httpd.conf
# 包含端口监听的配置:
Include /etc/apache2/ports.conf
# 包含一般性的配置语句片断:
Include /etc/apache2/conf.d/
# 包含虚拟主机的配置指令:
Include /etc/apache2/sites-enabled/
3.
保证apache启动
sudo /etc/init.d/apache2 restart
4.
设置默认根主目录
/etc/apache2/sites-available/default
可以看到默认端口为80,默认文档主目录为/var/www
ServerAdmin指定管理员邮箱
Alias /doc/ "/usr/share/doc/" 创建虚拟目录
apache的相关日志在/var/log/apache2/
5.
可以将/var/www主目录权限赋给www-data
chown -R www-data:www-data /var/www
6.
开放80端口
ufw allow 80
查看 ufw status
7.
如果要想卸载apache,可以使用下面命令
apt-get remove apache*
如果要关闭某个端口ufw delete allow 80