[英]Xampp images not loading even after editing httpd.conf
所以我在 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”中的項目文件夾,我已經添加了該行“要求所有授予'以及我仍然沒有找到解決方案。
該代碼使用了我可以想出的圖像路徑的可能組合:
<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 的子文件夾中,路徑與'圖像1'。
我的 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 中的文件,以避免遇到我遇到的問題,並以艱難的方式學習。
在你的 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>
確保您在 /opt/lampp 下創建空白文件夾“logs”,以便它容納您的日志報告。
然后最后sudo chown -R www-data:www-data /opt/lampp
。
這是根據 Apache2.4+ 更新的
因此,在我的系統幾乎崩潰(純粹是我自己的錯誤)之后,在嘗試更改擁有文件的權限時,我意識到上述問題有一個簡單的解決方案。 您不需要更改整個文件夾“/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 中的“您的網站”文件夾,並使用上述命令的相同版本手動更改圖像文件的所有權,並使用 *.jpg 代替。
編輯:它似乎不起作用,但是現在我在將 phpmyadmin 連接到數據庫時遇到了問題,所以我還需要一段時間才能對其進行良好的測試。
解決方案:最終解決了這個問題
不要輕易使用“chown”或“chmod”命令。 我已經這樣做了,相信我,在那之后恢復到初始配置不是小菜一碟。 所以我已經遇到這個問題一段時間了,我終於找到了解決方案,盡管它只是作為最后的手段使用:
sudo chmod -R 777 /opt/lampp/htdocs/path/to/image/folder
這基本上為您提供了與該文件夾中存儲的所有圖像有關的所有權限。 干杯!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.