php Ubuntu/Apache2/禁止/权限错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8558706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ubuntu/Apache2/ Forbidden/Permission error
提问by Shtrees
I have Ubuntu 11.10 with Lamp installed
我有安装了 Lamp 的 Ubuntu 11.10
There is some files that i can't access to from my web directory "/var/www"
有些文件我无法从我的 Web 目录“/var/www”访问
http://localhost/banner/banner.htmlI am getting an error :
http://localhost/banner/banner.html我收到一个错误:
Forbidden You don't have permission to access /banner/banner.html on this server. Apache/2.2.20 (Ubuntu) Server at localhost Port 80
Forbidden 您无权访问此服务器上的 /banner/banner.html。本地主机端口 80 上的 Apache/2.2.20 (Ubuntu) 服务器
I can access /var/www/index.php normally as i can browse /var/www/banner normally too from my browser
我可以正常访问 /var/www/index.php 因为我也可以从我的浏览器正常浏览 /var/www/banner
This is a small peace of :
这是一个小小的和平:
a1a4a@A1A4a:~$ ls -l /var/www
total 7088
-rwxrwxrwx 1 root root 916 2011-11-25 20:49 access-controlled.php
-rw-r--r-- 1 root root 22163 2011-12-16 22:28 account_info.php
-rw-r--r-- 1 root root 22126 2011-12-16 22:27 account_info.php~
-rw-r--r-- 1 root root 16585 2011-12-16 21:32 acount_info.php
-rw-r--r-- 1 root root 0 2011-12-16 21:28 acount_info.php~
drwxrwxrwx 5 root root 4096 2011-12-09 23:03 banner
drwxrwxrwx 2 root root 4096 2011-12-09 23:03 css
And
和
a1a4a@A1A4a:~$ ls -l /var/www/banner
total 20
-rw--w---- 1 root root 2564 2011-11-25 20:51 banner.html
drwx-w---- 4 root root 4096 2011-12-09 23:03 examples
drwx-w---- 2 root root 4096 2011-12-09 23:03 lib
drwx-w---- 4 root root 4096 2011-12-09 23:03 skins
-rw--w---- 1 root root 1431 2011-11-25 20:51 style.css
This is my config :
这是我的配置:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
My "nano /etc/apache2/apache2.conf" is set as default ...
我的“nano /etc/apache2/apache2.conf”被设置为默认值...
How can i make all my /var/www files (folders and sub-folders and files ) accessible from my browser as if i was on a windows machine using Wamp ...
我怎样才能让我的所有 /var/www 文件(文件夹和子文件夹和文件)从我的浏览器访问,就像我在使用 Wamp 的 Windows 机器上一样......
P.S: I will host the website on a Windows machine i am using ubuntu just for coding.
PS:我将在 Windows 机器上托管网站,我使用 ubuntu 只是为了编码。
回答by evildead
the user running the apache deamon, on ubuntu thats www-data (like in most debian based systems), needs at least read permissions for the files.
But as you posted only owner root
and group root
has read rights.
运行 apache 守护进程的用户,在 ubuntu 那是 www-data(就像在大多数基于 debian 的系统中一样),至少需要文件的读取权限。但是正如您发布的那样,只有所有者root
和组root
具有读取权限。
Actually owner root
has rw
group root
has r
.
其实楼主root
有rw
群root
有r
。
So the user actually running the webserver (www-data) falls to the others permissions, which have none.
因此,实际运行网络服务器(www-data)的用户属于其他人的权限,而这些权限没有。
Either do a chmod -R o+r /var/www/banner/*
or a chown -R www-data /var/www/banner
to fix that.
要么做 achmod -R o+r /var/www/banner/*
要么 achown -R www-data /var/www/banner
来解决这个问题。
回答by gabe
I always forget that while the sub-directories and files need the read permission, the sub-directories also need execute permission.
我总是忘记,虽然子目录和文件需要读取权限,但子目录也需要执行权限。
chmod a+x banner
This tends to come up when I've saved a web page in the 'Webpage, Complete' format with Chrome or Firefox and am then trying to serve it under localhost, which I often do when building mockups for clients.
当我使用 Chrome 或 Firefox 以“网页,完整”格式保存网页,然后尝试在 localhost 下提供它时,往往会出现这种情况,我在为客户端构建模型时经常这样做。
回答by Timur
May be it is an issue with your banner.html
permissions - apache`s user has no permissions even to read it.
可能是您的banner.html
权限问题- apache 的用户甚至没有权限阅读它。