Issue
So I'm using Xampp on Linux to test some web pages and I'm facing an issue with loading images from the local file system onto the server
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
Now so far I've seen a lot of similar questions and I've edited the httpd.conf file accordingly as well as the directory to 'Project1_July2015' which is my folder for the project inside 'htdocs' I've added the line 'Require all granted' as well and I still haven't found a solution to this.
The code uses ever possible combination of an image path I could come up with:
<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">
So as you can see, I have 'image1' stored in the JPEG format in the folder /opt/lampp/htdocs/MyProject_2015 while 'image2'(also JPEG) is stored in a sub-folder in /img in the same path as 'image1'.
My httpd.conf file path is /opt/lampp/apache2/conf and its contents now resemble :
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>
Is it the path to my directory that I'm messing up, the path to my image that is incorrect, or some other issue with my code?
This is how the error_log looks for the last couple of entries :
[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/
This is all the entries in error_log since I restarted xampp in case that helps:
[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 and editing the httpd.conf file to reflect
<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
instantly brought up the following errors on the page. It's not loading anymore :
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
IMPORTANT : So far what I didn't realize and wasn't brought to my notice either is that there are two httpd.conf files. One is in opt/lampp/apache2 /conf while the other one is in /opt/lampp/etc. When it is suggested you edit the httpd.conf file please consider the one in /opt/lampp/etc to avoid facing issues that I faced and learnt about the hard way.
Solution
So after nearly crashing my system (purely my own mistakes), while trying to change permissions for owning the files I realized there's a simple solution to the above issue. You don't need to change ownership of the entire folder '/opt/lampp' as that may or may not cause issues (it did, for me), all you need is :
$ cd /opt/lampp/htdocs
$ whoami
This enables you to find out the owner of the folder htdocs which should be you but if it isn't simply run the command :
$ sudo chown -R www-data(rootusername):www-data(rootusername) *
Since you've already navigated to htdocs you can use ' * ' ; however, if you haven't, I'd recommend you use :
$ sudo chown -R www-data(rootusername):www-data(rootusername) /opt/lampp/htdocs
After a fresh install so far this is what worked out for me. I've lost my databases with the uninstallation so it'll be a while before I can corroborate whether the images part works or not but as for setting permissions so far this is what definitely allowed access instead of the usual 'Acces denied' message in case of different ownership of htdocs.
If even after this the images fail to load citing 'Access denied', then I suggest you navigate to the 'yourwebsite' folder in htdocs and manually change ownership for image files using the same version of the above command with *.jpg instead.
Edit: It doesn't seem to work, but now I've got issues with connecting phpmyadmin to the databases so it'll be a while before I can test it well.
SOLUTION : FINALLY SOLVED THE ISSUE
DO NOT use the 'chown' or 'chmod' command lightly. I've done that and trust me it is not a piece of cake to revert to the initial configuration after that. So I've had this problem for a while now and I finally figured out a solution to it although it's only to be used as a last resort:
sudo chmod -R 777 /opt/lampp/htdocs/path/to/image/folder
this basically gives you all permissions pertaining to all the images stored in that folder. Cheers!
Answered By - Swapneel Mehta Answer Checked By - Candace Johnson (WPSolving Volunteer)