ubuntu php环境 vhost配置


  1. 查看apche是否开启了alias_module

    $ apache2ctl -M | sort
    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
    access_compat_module (shared)
    alias_module (shared)
    ...

    如果没有开启,则可以使用$ sudo a2enmod vhost_alias进行开启.

  2. 修改 host

    $ sudo gedit /etc/hosts
    $ sudo /etc/init.d/networking restart
  3. 添加vhost
    sites-available 目录下,创建vhost文件

    $ cd  /etc/apache2/sites-available/
    /etc/apache2/sites-available$ sudo gedit itaken.conf
  4. 生效配置

    $ sudo a2ensite itaken.conf
    To activate the new configuration, you need to run:
    systemctl reload apache2
  5. 重启apache2

    $ sudo service apache2 reload

    也可以使用$ sudo /etc/init.d/apache2 restart 命令进行apache的重启.


在重启 apache2 的时候, 报错:

$ sudo /etc/init.d/apache2 restart                                        1 ↵
[....] Restarting apache2 (via systemctl): apache2.serviceJob for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.
 failed!

$ systemctl status apache2.service                                                                                        1 ↵
 ● apache2.service - The Apache HTTP Server
    Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
   Drop-In: /lib/systemd/system/apache2.service.d
            └─apache2-systemd.conf
    Active: failed (Result: exit-code) since Wed 2017-05-03 11:10:30 CST; 14s ago
   Process: 12963 ExecStop=/usr/sbin/apachectl stop (code=exited, status=1/FAILURE)
   Process: 12939 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=1/FAILURE)
   Process: 15526 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)
  Main PID: 1222 (code=exited, status=0/SUCCESS)

 5月 03 11:10:30 itaken systemd[1]: Starting The Apache HTTP Server...
 5月 03 11:10:30 itaken apachectl[15526]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using ...
 5月 03 11:10:30 itaken apachectl[15526]: (2)No such file or directory: AH02291: Cannot access directory '/etc/apache2/logs/' for error ...
 5月 03 11:10:30 itaken apachectl[15526]: AH00014: Configuration check failed
 5月 03 11:10:30 itaken apachectl[15526]: Action 'start' failed.
 5月 03 11:10:30 itaken apachectl[15526]: The Apache error log may have more information.
 5月 03 11:10:30 itaken systemd[1]: apache2.service: Control process exited, code=exited status=1
 5月 03 11:10:30 itaken systemd[1]: Failed to start The Apache HTTP Server.
 5月 03 11:10:30 itaken systemd[1]: apache2.service: Unit entered failed state.
 5月 03 11:10:30 itaken systemd[1]: apache2.service: Failed with result 'exit-code'.

发现是没有 logs 日志目录, 添加日志目录, 重启apache成功.

$ cd /etc/apache2/
$ sudo mkdir logs
$ sudo chmod 777 logs/

$ sudo /etc/init.d/apache2 start
[ ok ] Starting apache2 (via systemctl): apache2.service.

参考文档


Author: Itaken
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source Itaken !
  TOC目录