ubuntu-安装Apache2

ubuntu-安装Apache2

参考: Ubuntu 18.04下使用Apache搭建一个web服务器 - https://blog.csdn.net/weixin_39212776/article/details/81192847


安装步骤

  1. 安装

    1
    sudo apt install apache2 -y
  2. 查看服务状态

    1
    service apache2 status
  3. 一些操作Apache的常用命令

    1
    2
    3
    /etc/init.d/apache2 start    //启动Apache服务
    /etc/init.d/apache2 stop //停止Apache服务
    /etc/init.d/apache2 restart //重启Apache服务

修改指向目录

改根目录

/etc/apache2/sites-available 中修改 000-default.conf 中的DocumentRoot /var/www/ 修改为想要的目录 . (最好把你的目录移到 /var/www 目录之下, 不然访问时报错: You don't have permission to access / on this server)

1
2
3
4
> vi /etc/apache2/sites-available/000-default.conf
ServerName www.aaa.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/myweb

重启服务器:

1
/etc/init.d/apache2 restart