【问题标题】:Test your site locally with Apache on Ubuntu Linux在 Ubuntu Linux 上使用 Apache 在本地测试您的站点
【发布时间】:2014-06-15 19:09:49
【问题描述】:

我的 /home/user/projects 文件夹中有各种网站,我希望能够使用 Apache2 在浏览器上测试它们(它们有 PHP 文件和连接到数据库)。

我不想每次更改某些内容时都将它们复制到 var/www。我只想在浏览器中打开一个 URL,其余的应该由 Apache 完成。通过编辑主机文件来分配假域也很好,但我不知道如何实现它。我试过这个solution,但我无法访问这些文件。

更新 这是我到目前为止所做的:

  1. 首先,我配置了 hosts 文件。我使用sudo 打开etc/hosts 文件并添加以下行:127.0.0.2 projects。现在我应该可以从浏览器访问http://projects

  2. 其次,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中创建

  3. 测试,在使用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的权限,它是可执行的,但结果相同。

【问题讨论】:

    标签: linux apache virtualhost http-status-code-403


    【解决方案1】:

    对于警告,您只需在全局配置文件中添加 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)

    【讨论】:

      猜你喜欢
      • 2018-04-03
      • 2018-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-22
      • 2012-03-24
      • 2011-01-14
      相关资源
      最近更新 更多