2

I'm trying to deploy a Laravel 5.6 application on a shared hosting package. This package uses DirectAdmin with PHP 7.2.

Because of other applications living in sub directories in the public_html directory, I'm forced to also host the application in a subdirectory.

After some doing some research to hosting a Laravel application in a subdirectory, my setup looks like this:

- domains
   - example.com
       - public_html
         - laravel
         - otherapp
         - other_site
       - laravel_code

The laravel folder inside the public_html folder has the same files as every public folder in a Laravel application. This means the files index.php, .htaccess, etc...

The laravel_code folder directory consists of the source code of my application. I know I had to refer my index.php to this folder. I done that like this:

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylor@laravel.com>
 */

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/

require __DIR__ . '/../../laravel_code/vendor/autoload.php';


/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__ . '/../../laravel_code/bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

My .htaccess file looks like this:

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

When trying to navigate to the domain, I only get an HTTP 500 error page, without any log files being generated in my storage/logsfolder.

I already tried clearing my cache and caching my config over again. I'm also sure my database credentials are working.

My .env file looks like this:

APP_NAME=WBS
APP_ENV=local
APP_KEY=base64:knjh2YEuePhEzBblBp5zLJQOQEwaiRBOSkmxz1gcYGw=
APP_DEBUG=true
APP_URL=http://www.example.com/laravel/

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=mydomain
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379


PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

The files also have the proper permissions, I gave all the files the 755 permission for testing.

What could cause this HTTP 500 error and how can I fix it?

Bas
  • 2,106
  • 5
  • 21
  • 59

5 Answers5

2

You can see in official documantation how is it working error handling

https://laravel.com/docs/5.7/errors

You can put on public/index.php this code and catch problem

try {
    $app->run();
} catch(\Exception $e) {
    echo "<pre>";
    echo $e;
    echo "</pre>";
}
Ismoil Shifoev
  • 5,512
  • 3
  • 24
  • 32
1

For errors you might want to look in Apache2/Nginx error logs if the laravel.log is empty.

You still might need to change the public path according to your file structure (taken from here). Add the following to public/index.php:

$app->bind('path.public', function() { return __DIR__; });

Also @Julius' answer is a solution to a common problem when deploying.

Mario Haubenwallner
  • 1,835
  • 1
  • 17
  • 21
  • Still no success. The only error I see, which is from 15 minutes ago, is this: `[Mon Nov 26 11:03:58.038804 2018] [core:error] [pid 2038141:tid 140217619216128] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://www.example.com/laravel/` – Bas Nov 26 '18 at 10:16
  • Then you have an endless-loop in your `.htaccess`-file. Have you changed it? – Mario Haubenwallner Nov 26 '18 at 10:18
  • Now when refreshing the page, the error message doesn't appear in the apache logs. – Bas Nov 26 '18 at 10:24
  • Mario, unfortunately still without succes when making the `public` folder there and changing the links. Still the same error. – Bas Nov 26 '18 at 10:31
0

For testing give storage/ files permissions 777.

chmod -R 777 storage/
Julius Žaromskis
  • 2,026
  • 2
  • 14
  • 20
0

I had the same problem. I used this trick to deploy laravel application on shared hosting. Reference Lik

In Laravel 5.6 create .htacess file in your root directory and placed the following code:

<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

Hope it will help you.

  • Thanks, where would I put this though? My `laravel` folder inside `public_html` has no `public/` folder – Bas Nov 26 '18 at 10:09
  • yes inside public_html. you don't have to separate laravel app folder. you don't have to separate public folder also. just deploy from local to the server directly. –  Nov 26 '18 at 10:15
  • check this [link](https://stackoverflow.com/questions/28364496/laravel-5-remove-public-from-url/48494280) –  Nov 26 '18 at 10:22
0

I have the same issue, after trying every solution from answers above, no one of them works. then i tryed to run the code inside Tinker, i found the problem was a infinity loop inside my code. so laravel error handler cannot be work or catch any error.

Mohamed Elbahja
  • 609
  • 1
  • 8
  • 9