我的 / home / user / projects 文件夹中有各种网站,我希望能够使用 Apache2 在浏览器上测试它们(他们有PHP文件和连接到数据库)。
每次更改内容时,我都不想将它们复制到 var / www 。我只想在浏览器中打开一个URL,Apache应该完成其余的工作。通过编辑hosts文件来分配假域也很棒,但我不知道如何实现它。我试过这个solution,但我无法访问这些文件。
更新 这就是我现在所做的:
首先,我配置hosts文件。我使用sudo
打开 etc / hosts 文件并添加以下行:127.0.0.2 projects
。现在我应该能够从浏览器访问http://projects
其次,Apache虚拟目录。在etc / apache2 / sites-available文件夹中,我创建了一个名为projects的新文件并添加以下代码(在 / home / user / projects 里面我有 index.html 文件):
<VirtualHost *:80>
ServerName com
DocumentRoot /home/user/projects
</VirtualHost>
我保存并执行了sudo a2ensite projects
,以激活主机。已在/etc/apache2/sites-enabled
使用sudo service apache2 restart
重启Apache后进行测试。我只收到两次警告:
Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
现在我在浏览器中输入http://projects
,但会显示 403 Forbidden error (You don't have permission to access / on this server
)。我用sudo chmod -R 755 /home/user/projects
更改了/ home / user / projects的权限,它可执行但结果相同。
答案 0 :(得分:0)
对于警告,您只需在全局配置文件中添加ServerName
。
<VirtualHost 127.0.0.2:80>
ServerName com
DocumentRoot /home/user/projects
</VirtualHost>
对于错误,您应该更改网站文件夹的所有者,如下所示:chown user_apache.group_apache /home/user/projects -R
(例如在ubuntu / debian chown www-data.www-data /home/user/projects -R
中)