我的 /home/user/projects 文件夹中有多个网站,我希望能够使用 Apache2 在浏览器上测试它们(它们有 PHP 文件和连接到数据库)。
我不想每次更改内容时都将它们复制到 var/www。我只想在浏览器中打开一个 URL,剩下的由 Apache 完成。通过编辑主机文件来分配假域名也很好,但我不知道如何实现。我试过这个solution但我无法访问这些文件。
更新 这是我到目前为止所做的:
首先,我配置主机文件。我用
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
, 激活主机。符号链接(symbolic link)已在/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 禁止错误 (You don't have permission to access / on this server
)。我用sudo chmod -R 755 /home/user/projects
更改了/home/user/projects 的权限, 它是可执行的,但结果相同。
最佳答案
对于警告,您应该只添加 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
)
关于linux - 在 Ubuntu Linux 上使用 Apache 在本地测试您的网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23371565/