Forbidden You don't have permission to access on this server. Centos 6 / Laravel 4
Asked Answered
U

5

12

i got a problem after i finish to set up LAMP and installed my laravel 4 application. Everything seem went well, when i go on my ip address url, it show me the first page of my application correctly, but all the rest of the page throw me an 404 error The requested URL was not found on this server.

So I added to my httpd.conf (under the virtual host of my project) - AllowOverride All Order allow,deny

<VirtualHost *:80>
        ServerName VPS-IP-ADDRESS
        DocumentRoot /var/www/html/nextmatch/public_html/public/

       <Directory /var/www/html/nextmatch/public_html/public/>
         AllowOverride all
         Order allow,deny
          <IfModule mod_rewrite.c>
          Options -MultiViews
          RewriteEngine On
          RewriteCond %{REQUEST_FILENAME} !-f
         RewriteRule ^ index.php [L]
       </IfModule>
</Directory>
</VirtualHost>

And now when i try to navigate instead the 404 error i got Forbidden You don't have permission to access this server. I set up with chmod 775 -R path/laravel/ and the folder storage with 777 but still i got the same error any suggest please? I cannot figure out to this problem i'm getting crazy! Thank you for any help.

United answered 1/2, 2014 at 13:56 Comment(3)
Make sure the owner of the folder is that of the webserver user. ls -l will reveal who the files belong to.Haber
what do you mean for webserver user? i have root access on my vps but i created another user called nextmatch (Name of the project) and that user is owner.United
Answered your query below.Haber
H
13

The webserver starts as a daemon (service) under a particular user. That user is defined in httpd.conf. By default that user will be apache. Don't confuse the apache user with the httpd process. The latter is a webserver daemon and the former is the user under which it is going to run. If the folder you created belongs to root or a user other than the one defined in httpd.conf then apache won't be able to access it. The way to identify this problem is to go to the folder and do ls -l. If the user define in httpd.conf is apache then in order for it to access the folder, you should see:

drwxr-xr-x.  2 apache apache    4096 Jan  8  2013 public_folder

Note, it says 'apache apache', meaning it belongs to the apache user and group. If you created it via root then you will probably see:

drwxr-xr-x.  2 root root    4096 Jan  8  2013 public_folder

The apache user cannot access the folder defined by root. To solve this problem run the command:

chown -R apache:apache myfolder

The -R option is recursive, so it will update ownership for ALL folders and files within that folder to the apache user.

If your ownership if fine, then trying 'temporarily' turning off selinux. On centos you do:

setenforce 0

Which will turn off selinux till the next restart. Ideally, you will want to leave selinux on for additional security and set a valid context for your apache files and folders.

If turning off selinux does work, then you probably have the wrong security context for your files and folders. run the following command to restore your security contexts:

restorecon -R -v /var/www/
Haber answered 1/2, 2014 at 22:42 Comment(2)
I turned off selinux and it works, but I guess is not a good idea... How can I set selinux to give acces to this folder?Exhume
Updated answer. Essentially, use the restorecon command to restore the correct selinux contexts for the files and foldersHaber
V
8

If you're using CentOS it could be an issue with selinux. Check to see if selinux is enabled with 'sestatus'. If it is enabled, you can check to see if that is the issue (temporarily) using 'sudo setenforce 0'. If apache can serve the site, then you just need to change the context of the files recursively using 'sudo chcon -R -t httpd_sys_content_t' (you can check the existing context using 'ls -Z'.

Selinux may not be the issue, but it's worth checking on.

Venipuncture answered 1/2, 2014 at 20:31 Comment(0)
S
5

try this inside the folder:

chcon -R -t httpd_sys_content_t *
Sloop answered 18/2, 2015 at 17:21 Comment(0)
B
2
chcon -R -t httpd_sys_content_t *

did the trick for me.

Briquet answered 27/4, 2015 at 11:43 Comment(0)
U
0

from php5.conf in /etc/apache2/mods-available

# Running PHP scripts in user directories is disabled by default
# 
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
#<IfModule mod_userdir.c>
#    <Directory /home/*/public_html>
#        php_admin_value engine Off
#    </Directory>
#</IfModule>
Unmanned answered 10/12, 2014 at 2:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.