使用Debian本地时使用VirtualHost的笔记

每次都丧失了记忆和物理备忘录,所以只能依靠这个备忘录。

杂乱地

    1. 将conf文件写入/etc/apache2/sites-available中

 

    1. 执行a2ensite命令

 

    1. 在/etc/hosts中添加ServerName

 

    1. 重启apache

 

    修复文件的权限

具體來說。

当访问 http://local.test 时,希望能够运行 /var/www/test/public_html/index.php。

“可用的网站配置文件”

创建名为local.test.conf的文件,并按照以下方式进行编写。

<VirtualHost *:80>
    ServerName local.test

    DocumentRoot /var/www/test/public_html/

    <Directory /var/www/test/public_html/>
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

启用网站

我要输入下面的命令。

sudo a2ensite local.test.conf

请确认/etc/apache2/sites-enabled目录下是否存在local.test.conf文件。

/etc/hosts文件

将 “local.test” 添加到 /etc/hosts 文件的开头。

127.0.0.1       localhost local.test

如果没有这个就没有Apache会去网络上找local.test的地址。

重启Apache

我要输入下面的命令。

sudo /etc/init.d/apache2 restart

权限


mkdir /var/www/test/public_html -p
echo "nya-n!" > /var/www/test/public_html/index.php

sudo chown www-data:www-data /var/www/test/public_html/ -R
sudo chmod 764 /var/www/test/public_html/ -R

结束

访问 http://local.test,如果看到” nya-n! “这个字样就表示成功了。