Xampp - Ubuntu - 无法访问我的项目在lampp/htdocs中

25
我已经在Ubuntu 12.04上安装了xampp,并将我的项目放在文件夹/opt/lampp/htdocs/project_is_here中。
当我在浏览器中输入localhost/soap/php(soap/php位于我的htdocs文件夹中),也就是index.php所在的地方,会出现以下错误:
Access forbidden!

You don't have permission to access the requested directory. There is either no index document or the directory is read-protected.

If you think this is a server error, please contact the webmaster.

Error 403

localhost
Apache/2.4.3 (Unix) OpenSSL/1.0.1c PHP/5.4.7

有什么办法可以解决这个问题吗?我认为放置项目的位置是正确的,因为我尝试了其他地方,但都提示位置不存在,只有在这里才不会出现错误并得到所需结果。

你有什么建议吗?

5个回答

62
  1. 在Linux终端中导航到您的lampp目录。

 cd /opt/lampp
  • 在命令行中输入:

     sudo chmod 777 -R htdocs
    
  • 问题应该已经解决了。

    你刚才做的是:

    导航到包含受保护目录的目录。你的问题是它是一个被系统访问保护的文件夹。当你执行 chmod 777 -R htdocs 命令时,你将计算机上每个用户的权限设置为“允许读/写/执行”

    0-7 中的每个数字都设置了一个权限级别。这里有一篇链接更详细地解释了这个问题。

    http://www.pageresource.com/cgirec/chmod.htm

    '-R' 使命令递归,并将影响 htdocs 以及其所有子目录和所有子目录等。


    1
    你绝对不应该给你的网站根目录赋予777权限。 - Rohan Khude

    11

    我曾经遇到过相同的问题,这是我的解决方案:


    1.在终端中执行以下操作:

    cd /opt/lampp/etc/
    
    1. 如果您已经安装了Sublime Text,只需键入:

    subl httpd.conf

    3. 当配置文件在Sublime中打开后,您需要检查这三个块是否如下所示:

    <Directory />
        AllowOverride All
        Require all granted
    </Directory>
    

    ================================

    <Directory "/opt/lampp/htdocs">
     Options Indexes FollowSymLinks ExecCGI Includes
     AllowOverride All
     Require all granted
    </Directory>
    

    ================================

    User your username
    Group your group name
    
    例如:
    我的用户名是 mhmd,同时我的群组名称也是 mhmd。
    User mhmd
    Group mhmd
    

    我希望这能够帮到你。


    我的计算机名称是"c1",用户名是"u1"。我需要输入哪个组和用户名? - Arthur Alunts

    5

    可能的原因之一是您正在使用虚拟主机。

    在这种情况下,请在终端中使用以下命令:

    sudo nano /opt/lampp/etc/extra/httpd-vhosts.conf
    

    然后在文件末尾添加以下代码块。
    <VirtualHost *:80>
        DocumentRoot "/opt/lampp/htdocs"
        ServerName localhost
        ServerAlias localhost
        ErrorLog "logs/localhost-error_log"
        CustomLog "logs/localhost-access_log" common
    </VirtualHost>
    

    最后重新启动XAMPP。
    sudo /opt/lampp/lampp restart
    

    谢谢..@Hoang Trinh,你节省了我的时间。 - yogesh chatrola
    终于成功了。谢谢。这对我有用。我知道这与我使用虚拟主机有关,但没有想到要谷歌搜索([我的查询]与虚拟主机)。 - Ibrahim Mohamed

    1
    我已经授予了所有权限,但仍然收到错误消息。 前往 -> /etc/apache2/sites-available/000-default.conf 将DocumentRoot设置为/opt/lampp/htdocs
    对我来说全部解决了。 将“DocumentRoot”更改为您的项目所在的任何文件夹。

    -2

    这将会很有用。

      0 -> No permission
      1 -> Execute
      2 -> Write
      3 -> write and execute(2 +1)
      4 -> Read
      5 -> Read and execute
      6 -> Read and write
      7 -> read,write and execute
      Then What about three decimal 
    
      1st-digit Owner
    
      2nd- digit Group
    
      3rd- digit Others
    
    test@test:~$ sudo chown -R test:test /var/www/html/folder
    
    test@test:~$ sudo chmod -R 666  /var/www/html/folder //-system user 
    
    test@test:~$ sudo chmod -R 777  /var/www/html/folder // -browser with full
    

    这是什么777?--> 7:你,7:我们,7:他们。

    777和666是文件权限,777表示没有任何限制的权限。任何人都可以做任何事情。通常不是一个理想的设置。666表示所有用户都可以读写该文件。 - Rahul
    使用命令:sudo chmod -R +w /var/www/html/folder - Ronny Sherer

    网页内容由stack overflow 提供, 点击上面的
    可以查看英文原文,
    原文链接