Home > Blockchain >  i get access forbidden from Apache (httpd) in fedora 34, Laravel, SELinux
i get access forbidden from Apache (httpd) in fedora 34, Laravel, SELinux

Time:09-17

I have configured httpd in my fedora and I checked everything is true but i get

access forbidden

I have tested everything about .htaccess but still getting access forbidden. also, my laravel folder permissions are correct. I tested a sample project while installing httpd it worked perfectly with no 'access forbidden' message.


this is my httpd config

<VirtualHost *:80>
    ServerName  test.com
    ServerAlias www.test.com
    DocumentRoot /home/myuser/gitlab/register/public
    <Directory /home/myuser/gitlab/register/public>
         DirectoryIndex index.php
         AllowOverride All
         Require all granted
         Order allow,deny
         Allow from all
    </Directory>
</VirtualHost>

this is my htaccess in laravel public folder

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (. )/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

CodePudding user response:

your probably creating the issue by mixing old Apache syntax with new Apache syntax, modern versions of Apache should be something like this...

<VirtualHost *:80>
    ServerName  test.com
    ServerAlias www.test.com
    DocumentRoot /home/myuser/gitlab/register/public
    <Directory /home/myuser/gitlab/register/public>
         DirectoryIndex index.php
         AllowOverride All
         Require all granted
         # Order allow,deny
         # Allow from all
    </Directory>
</VirtualHost>

CodePudding user response:

I found the problem.

it is because of the

SELinux

ubuntu does not uses SELinux by default but RedHat distributions use it by default. SELinux prevents apache to access the home directory for the sake of security so if you disable or put it to Permissive mode, apache can access your home directory to load the web project. if you do not want to disable SELinux so the correct location for web applications is in /var/www/ folder so if we change httpd config to

<VirtualHost *:80>
    ServerName  test.com
    ServerAlias www.test.com
    DocumentRoot /var/www/gitlab/register/public
    <Directory /var/www/gitlab/register/public>
         DirectoryIndex index.php
         AllowOverride All
         Require all granted
         Order allow,deny
         Allow from all
    </Directory>
</VirtualHost>

it works fine

  • Related