Home > Software engineering >  Laravel CPanel upload throws 403
Laravel CPanel upload throws 403

Time:03-03

I cannot start my laravel project on cpanel server. Asked domain provider website to add the pyp version that my laravel project use but still have that problem. I need to solve this is 4 hours please help.

Here is my .htaccess

'''

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]

'''

CodePudding user response:

If you're using cPanel on shared hosting, try the following assuming the root of your project is public_html (you can adjust the path if your project is in another directory within public_html):

  1. Set the document root to the root of the project ie. /public_html
  2. Create an .htaccess file in the root of the project that looks like:
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

This will direct requests to the public folder.

  1. Create another .htaccess file in the public directory that looks like:
<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]

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

CodePudding user response:

Are you getting the issue while accessing the web ?

Step 1: just upload your all source code on the server (make sure database & .env set well) i) make zip and extract it ii) deploy code using git or take a clone from a repository and install all dependencies

Step 2: Make a .htaccess file on the project root directory and copy below code and paste it into this file.

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w $) [NC]
RewriteRule ^(.*)$ public/$1 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php

I get this answer from this video so please say thanks to him https://www.youtube.com/watch?v=6Qbd9HTh7AE

Ref: How do I upload a laravel project on cPanel shared hosting?

or Try with a default Laravel and then upload your code or create laravel project via Cpanel UI and try. Later replace with your custom code. Capture the key and .env files before replacing.

  • Related