Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 659
Fabrizio Fenoglio Avatar asked Feb 01 '14 13:02

Fabrizio Fenoglio


3 Answers

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/
like image 77
Rijndael Avatar answered Nov 13 '22 04:11

Rijndael


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.

like image 34
iavery Avatar answered Nov 13 '22 04:11

iavery


try this inside the folder:

chcon -R -t httpd_sys_content_t *
like image 5
Mahdi Avatar answered Nov 13 '22 05:11

Mahdi