403 Forbidden Laravel on shared hosting
Asked Answered
C

5

5

I have a shared hosting and I'm trying to make my laravel project works on it, I'm using voyager to the admin panel.

I put my app public folder inside the /public_html and the rest of the project on the same level of the /public_html, so it looks like this:

.bash_history
.bash_logout
.bash_profile
.bashrc
.cache
.cpanel
.htpasswds
logs
mail
app -> my project
public_ftp
public_html -> where my app public folder is
.ssh
tmp
etc
...

I have managed to work almost everything, but the admin panel is not working properly.

When I access www.example.com/admin it goes to www.example.com/admin/login, I put my credentials and submit the form, after it returns to the same page, then I checked the network tab on Chrome and it appears the following message:

Request URL: http://example.com/admin/login
Request Method: GET
Status Code: 403 Forbidden

Anybody knows how to fix it?

Thanks.

Chanachance answered 11/5, 2018 at 13:2 Comment(3)
is all permissions correct?Yarak
I set 775 to storage and vendors folder, is it correct?Chanachance
That's not how it should be. You entire Laravel project should reside in public_html including the public folder. Then you can write some .htaccess rule to point to your domain root public folder.Strom
A
9

If you get any issue like that, then add .htaccess file in root folder, and put below code in that, it will start working

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Assuage answered 20/10, 2021 at 17:1 Comment(4)
worked with me on namecheapBreadboard
what is namecheap ?Assuage
my host plane on this namecheap.comBreadboard
works for me for wave saas starter kitShun
P
0

Usually, you should copy your files of public folder to the public_html folder and put other folders outside of public_html because it is available to the whole world.

You should modify the public/index.php file will following details:

//line 24
require __DIR__.'/../app/vendor/autoload.php';

// line 38
$app = require_once __DIR__.'/../app/bootstrap/app.php';

Since you have public folder inside public_html folder, you should add one more (..)

//line 24
require __DIR__.'/../../app/vendor/autoload.php';

// line 38
$app = require_once __DIR__.'/../../app/bootstrap/app.php';

Domain or subdomain

Point your domain or subdomain to {{your_domain}}/public

eg: In your case, if you visit www.abc.com it should point to /public_html/public.
for other cases, it should point to /public_html

Note:

Don't forget to update your .env file

  1. set APP_ENV=production
  2. APP_DEBUG=false
  3. LOG_CHANNEL=daily // considered good practice
  4. Your database credentials
  5. And other necessary changes...

Permissions

Normally you don't need to change files and folder permission. If you need to then set Folders to 755 and files to 644

Never set permission to 777

Perrone answered 6/1, 2019 at 18:17 Comment(0)
D
0

For me, this was due to the .htaccess looking for a folder (that was forbidden) instead of using the Laravel route with the same name /admin.

See StackOverflow here : Laravel, Admin controllers - 403 Forbidden

Deft answered 19/4, 2020 at 14:38 Comment(0)
A
0
Options -MultiViews -Indexes
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]

# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Ardeha answered 16/5, 2022 at 12:24 Comment(0)
D
-2

Hi your storage folder must be set permission 777 chmod -R 777 OR sudo chown -R www-data:www-data /var/www (recomended)

Dukes answered 11/5, 2018 at 20:8 Comment(4)
-R 777 yes but www-data is okay )Dukes
Never set permission to 777Erminiaerminie
why ?, if it local machine.Dukes
And for your information my recommended way to solve this issue this sudo chown -R www-data:www-data /var/www (recomended) as I mention in my responseDukes

© 2022 - 2024 — McMap. All rights reserved.