4

I am trying to deploy my laravel 5.1 application on shared hosting cpanel. But I am getting 404 error.

404

Not Found

The resource requested could not be found on this server!

To upload the project, I make a clone of project directory and uploaded it on cpanel via their FileManger. Then move the Public folder items into Public_Html.

My .htaccess file content is shown below:

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

    RewriteEngine On
       RewriteBase /

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

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

I also changed the following lines in index.php:

require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';

to

require __DIR__.'/../objecsys/bootstrap/autoload.php';
$app = require_once __DIR__.'/../objecsys/bootstrap/app.php';

What could be wrong with this deployment approach?

Hassan Saqib
  • 2,597
  • 7
  • 28
  • 51

3 Answers3

20

this is htaccess issue

get one .htaccess file in root folder of your web-project.

And put the following code inside it,

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

    RewriteEngine On

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

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

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

refresh the page and check it out

my problem is solved

when i upload the laravel project into the server my application just open the default route

but all of my other web route in laravel has error

the error is :404

laravel : 404 Not Found The resource requested could not be found on this server!

saber tabatabaee yazdi
  • 4,404
  • 3
  • 42
  • 58
  • 3
    this should be the accepted answer. thankyou man u saved my 2 hours time. love u. no homo. – panji gemilang Oct 21 '20 at 07:03
  • 1
    @saber tabatabaee yazdi I have the same problem bro. The only difference is that I am using laravel 8, and inside my public_html folder, I have another folder where I put my index.php. Can you please help me about this ? This is the link https://stackoverflow.com/questions/66647560/error-404-after-migrating-laravel-8-to-a-shared-host. Thank you. – Hope Mar 16 '21 at 00:41
  • you save my live, this answer is the best solution – GigaTera Mar 28 '23 at 14:24
7

Deploying Laravel app in cPanel is quite simple(if you are deploying on add-on domain).

In cPanel, go on add-on domains and then create a new add-on domain.

By default cPanel generates document root for you in this manner:

public_html/mydomain.com

Change it to:

public_html/mydomain.com/MyLaravelApp/public

Now upload your Laravel project under public_html/mydomain.com directory.

It should look like this.

enter image description here

If you have already an add-on domain. Go to Modify add-on domain (just below Create an Addon Domain)

Click edit icon in document root column and change your domain's document root.

enter image description here

Rajender Joshi
  • 4,155
  • 1
  • 23
  • 39
0

try setting empty APP_URL in your .env

APP_URL=http://
Yevgeniy Afanasyev
  • 37,872
  • 26
  • 173
  • 191