0

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]

'''

a a
  • 1

2 Answers2

0

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>
Andrew
  • 1,745
  • 1
  • 21
  • 29
  • now i dont have any http status code but when i try to access my webpage its looks like i dont have any internet connection. it says "ERR_CONNECTION_REFUSED" and i don't use shared hosting i think thats the problem :( – a a Mar 03 '22 at 09:00
  • So you're using cPanel on a VPS or something? Are you getting any kind of http error code? Is your database connection perhaps not setup properly? – Andrew Mar 03 '22 at 14:45
0

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.

Senthil
  • 2,156
  • 1
  • 14
  • 19