所以我在Linux上使用Xampp来测试一些网页,我遇到了将图像从本地文件系统加载到服务器上的问题
Access forbidden!
You don't have permission to access the requested object. It is either read-protected or not readable by the server.
If you think this is a server error, please contact the webmaster.
Error 403
到目前为止,我已经看到了很多类似的问题,我已经相应地编辑了httpd.conf文件以及'Project1_July2015'的目录,这是'htdocs'中项目的文件夹 我已经添加了“Require all granted”这一行,但我还没有找到解决方案。
代码使用了我可以提出的图像路径的可能组合:
<img src="image1">
<img src="image1.jpg">
<a href="image1.jpg">image1</a>
<?php
$link1="img/1/image2";
$name="/image2";
$link="img";
?>
<img src="<?php echo $link;echo $name;?>">
<img src="<?php echo $link1;?>">
<img src="/opt/lampp/htdocs/Project1_July2015/image2">
正如您所看到的,我将'image1'以JPEG格式存储在文件夹/ opt / lampp / htdocs / MyProject_2015中,而'image2'(也是JPEG)存储在/ img中的子文件夹中与'image1'相同的路径。
我的httpd.conf文件路径是/ opt / lampp / apache2 / conf,其内容现在类似于:
Alias /bitnami/ "/opt/lampp/apache2/htdocs/"
Alias /bitnami "/opt/lampp/apache2/htdocs"
<Directory "/opt/lampp/htdocs/">
Require all granted
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
它是我的目录的路径,我搞砸了,我的图像的路径是不正确的,还是我的代码的其他问题?
这是error_log查找最后几个条目的方式:
[Sun Oct 25 15:40:51.917516 2015] [core:error] [pid 4946] (13)Permission denied: [client 127.0.0.1:55332] AH00132: file permissions deny server access: /opt/lampp/htdocs/Project1_July2015/img/image1.jpg, referer: http://localhost/Project1_July2015/img/
这是error_log中的所有条目,因为我重新启动xampp以防有:
[Sun Oct 25 16:04:39.411323 2015] [mpm_prefork:notice] [pid 4540] AH00169: caught SIGTERM, shutting down
[Sun Oct 25 16:04:46.002063 2015] [ssl:warn] [pid 5513] AH01906: www.example.com:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Sun Oct 25 16:04:46.002277 2015] [ssl:warn] [pid 5513] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sun Oct 25 16:04:46.002695 2015] [suexec:notice] [pid 5513] AH01232: suEXEC mechanism enabled (wrapper: /opt/lampp/bin/suexec)
[Sun Oct 25 16:04:46.056649 2015] [auth_digest:notice] [pid 5514] AH01757: generating secret for digest authentication ...
[Sun Oct 25 16:04:47.002128 2015] [ssl:warn] [pid 5514] AH01906: www.example.com:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Sun Oct 25 16:04:47.002251 2015] [ssl:warn] [pid 5514] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sun Oct 25 16:04:47.002607 2015] [lbmethod_heartbeat:notice] [pid 5514] AH02282: No slotmem from mod_heartmonitor
[Sun Oct 25 16:04:47.016544 2015] [mpm_prefork:notice] [pid 5514] AH00163: Apache/2.4.12 (Unix) OpenSSL/1.0.1m PHP/5.6.8 mod_perl/2.0.8-dev Perl/v5.16.3 configured -- resuming normal operations
[Sun Oct 25 16:04:47.016596 2015] [core:notice] [pid 5514] AH00094: Command line: '/opt/lampp/bin/httpd -E /opt/lampp/logs/error_log -D SSL -D PHP'
[Sun Oct 25 16:04:53.915959 2015] [core:error] [pid 5916] (13)Permission denied: [client 127.0.0.1:55552] AH00132: file permissions deny server access: /opt/lampp/htdocs/Project1_July2015/img/image1.jpg, referer: http://localhost/Project1_July2015/img/
sudo chown -R www-data:www-data / opt / lampp并编辑httpd.conf文件以反映
<VirtualHost *:80>
ServerName myhost
ServerAlias myhost.mydomain.com
DocumentRoot /opt/lampp/htdocs
<Directory "/opt/lampp/htdocs">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride None
Require all granted
</Directory>
LogLevel error
ErrorLog /opt/lampp/logs/default-http-error.log
CustomLog /opt/lampp/logs/default-http-access.log combined
立即在页面上显示以下错误。它不再加载了:
Warning: session_start(): open(/opt/lampp/temp//sess_3kkj6u86hfagsndsp4hdkljct1, O_RDWR) failed: Permission denied (13) in /opt/lampp/htdocs/Project1_July2015/verify_blacklisted.php on line 2
New session start successful
3kkj6u86hfagsndsp4hdkljct1
127.0.0.1
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1017 Can't find file: './user_list/login_attempts.frm' (errno: 13 - Permission denied)' in /opt/lampp/htdocs/Project1_July2015/verify_blacklisted.php:16 Stack trace: #0 /opt/lampp/htdocs/Project1_July2015/verify_blacklisted.php(16): PDOStatement->execute() #1 /opt/lampp/htdocs/Project1_July2015/index.php(2): include('/opt/lampp/htdo...') #2 {main} thrown in /opt/lampp/htdocs/Project1_July2015/verify_blacklisted.php on line 16
Warning: Unknown: open(/opt/lampp/temp//sess_3kkj6u86hfagsndsp4hdkljct1, O_RDWR) failed: Permission denied (13) in Unknown on line 0
Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/opt/lampp/temp/) in Unknown on line 0
重要提示:到目前为止,我没有意识到并且没有引起我注意的是,有两个httpd.conf文件。一个在opt / lampp / apache2 / conf中,而另一个在/ opt / lampp / etc中。 如果建议您编辑httpd.conf文件,请考虑/ opt / lampp / etc中的文件,以避免面对我遇到的问题并了解困难的方法。
答案 0 :(得分:0)
在你的apache2.conf中,这些行应该在那里:
<Directory "/">
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory "/usr/share">
AllowOverride None
Require all granted
</Directory>
<Directory "/opt/lampp">
AllowOverride All
Require all granted
</Directory>
以及你的httpd.conf或其中的任何一个:
<VirtualHost *:80>
ServerName myhost
ServerAlias myhost.mydomain.com
DocumentRoot /opt/lampp/htdocs
<Directory "/opt/lampp/htdocs">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride None
Require all granted
</Directory>
LogLevel error
ErrorLog /opt/lampp/logs/default-http-error.log
CustomLog /opt/lampp/logs/default-http-access.log combined
</VirtualHost>
确保创建空白文件夹&#34; logs&#34;在/ opt / lampp下,它可以存储您的日志报告。
然后终于sudo chown -R www-data:www-data /opt/lampp
。
根据Apache2.4 +
更新答案 1 :(得分:0)
因此,在几乎崩溃我的系统(纯粹是我自己的错误)之后,在尝试更改拥有文件的权限时,我意识到有一个简单的解决方案来解决上述问题。您不需要更改整个文件夹'/ opt / lampp'的所有权,因为这可能会或可能不会导致问题(对我而言),您只需要:
$ cd /opt/lampp/htdocs
$ whoami
这使您能够找到应该是您的文件夹htdocs的所有者,但如果不是简单地运行命令:
$ sudo chown -R www-data(rootusername):www-data(rootusername) *
由于你已经导航到htdocs,你可以使用'*';但是,如果你没有,我建议你使用:
$ sudo chown -R www-data(rootusername):www-data(rootusername) /opt/lampp/htdocs
到目前为止全新安装后,这对我来说是有用的。我已经丢失了卸载数据库,所以在我确认图像部分是否有效之前还需要一段时间,但至于设置权限到目前为止,这肯定是允许访问而不是通常的“被拒绝”消息htdocs拥有不同所有权的案例。
如果在此之后图片无法加载引用“拒绝访问”,那么我建议你导航到htdocs中的'yourwebsite'文件夹,并使用* .jpg的上述命令的相同版本手动更改图像文件的所有权代替。
编辑:它似乎不起作用,但现在我遇到了将phpmyadmin连接到数据库的问题,所以在我测试它之前还需要一段时间。
解决方案:最终解决了问题
请勿轻易使用'chown'或'chmod'命令。我已经这样做了,相信我在此之后恢复到初始配置并不是一块蛋糕。所以我已经有这个问题了一段时间了,我终于想出了一个解决方案,虽然它只是作为最后的手段:
sudo chmod -R 777 /opt/lampp/htdocs/path/to/image/folder
这基本上为您提供了与该文件夹中存储的所有图像相关的所有权限。干杯!