注:所有非root用户,执行更高权限操作时命令前加sudo

1.安装apache2

apt-get install apache2

2.配置apache2

cd etc/apache2

vim apache2.conf

在末尾加入以下代码

ServerName localhost:80  
DirectoryIndex index.html index.htm index.php  
AddDefaultCharest GB2312 

ServerName localhost:80    防止开启apache2服务的时候会提示DNS出错。(必选)

DirectoryIndex index.html index.htm index.php       默认目录(可选)

AddDefaultCharset GB2312    设置默认字符集)(可选)

3.修改localhost默认目录

cd /etc/apache2/sites-available

vim 000-default.conf

修改DocumentRoot /var/www/html为自己的项目根目录

4.apache启动相关项

启动        /etc/init.d/apache2 start

重启        service apache2 restart

5.apache删除相关

1)删除apache

代码:

$ sudo apt-get --purge remove apache-common

$ sudo apt-get --purge remove apache

2)找到没有删除掉的配置文件,一并删除

代码:

$ sudo find /etc -name "*apache*" |xargs  rm -rf

$ sudo rm -rf /var/www

$sudo rm -rf /etc/libapache2-mod-jk

3)删除关联

#dpkg -l |grep apache2|awk '{print $2}'|xargs dpkg -P