Laravel remote server error 500, site doesn't works

8.5k views Asked by At

It's my first upload to a remote server of a Laravel site.

Local I have configured a vhost so my access to my site is like:

site.domain.com //it's pointing htdocs/laravel-proyect/public

I have uploaded my site to my remote server, then:

  • Change permisions on storage and all its directories
  • Change permisions to bootstrap
  • Change configuration of app.php

    'url' => 'http://site.domain.com',

  • Change configuration in database.app with new parameters (as well as in email.php)

  • Load all tables and data in the data base

Then I try to load my site and get a 500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

It works a little, I have this code in routes.php:

// Begins in the login view
Route::get('/', function()
{
    if (!Sentry::check()) {
        $data = array();
        if (Session::has('email')) {
            $data = array('email' => Session::get('email'));
        }

        return Redirect::route('login', $data);
    }
    else
        return Redirect::route('users');
});

/   ========================================
// LOGIN, LOGOUT AND ACTIVATION SECTION ==========
// // ============================================
// show the login page
Route::get(MyHelpers::textLang('login','routes'), array('as' => 'login', function()
{
    if (Sentry::check())return  Redirect::route('users');
    else {
        $rules = User::$rules_login;
        // show the login page (app/views/frontend/login.blade.php)
        return View::make('frontend.login', compact('rules'));
    }

So at first time mo url look like:

site.domain.com/entrar

'entrar', (login in spanish), y set by MyHelpers::textLang('login','routes'), access to my class MyHelpers and to lang files to translate 'login' in to 'entrar', but dont load the template.

Begins to :

  • Read documentation, making some changes: deleting Multiviews from .htaccess (deprecated), adding RewriteBase to .htaccess too.
  • Copy /public content to base dir and change paths in bootstrap/paths and in the index.php files.
  • Reinstall in two remote servers to verify is not my provider failing (same error). Talking to my provider, supouse there are no errors on the server.
  • I create a new htaccess in the base dir redirecting routes to /public.
  • Try with php 5.4, 5.5 and 5.6

Actually my .htaccess is:

RewriteEngine On

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

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

And I have no more ideas and cant find other solutions as related here.

Any idea? Please, I'm getting crazy, on wensday I have to beguin a new proyect and still working with this one.

Thanks

3

There are 3 answers

1
kikerrobles On BEST ANSWER

I have to add

RewriteBase /

to the .htaccess

12
Harish Kumar On

I have a demo laravel application on heroku Simple Blog.My .htaccess file is:

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

    RewriteEngine On

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

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

It seems that there is no issue with your .htaccess file. It may be problem with you code logic. If you are getting no error with same code on localhost, then check your config again. For laravel 4, there is already a similar issue on stackoverflow Laravel 4 Virtual Host and mod rewrite setup

Note that laravel 5 (if you are using it) takes input (database connection and other setting) from .env file.

If you are still getting error then try to send simple response on index page like:

Route::get('/','basic configurations are correct');

and then make it complex step by step. It will help you in finding error.

0
raeeschaudhary On

Answer from @kikerrobles really works.

your final .htaccess file should look like following

<IfModule mod_rewrite.c>

    <IfModule mod_negotiation.c>

        Options -MultiViews -Indexes

    </IfModule>

    RewriteEngine On

    RewriteBase /

    # 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>