Laravel 5.6 HTTP 500 error without any logging - php

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?

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>";
}

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.

For testing give storage/ files permissions 777.
chmod -R 777 storage/

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.

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.

Related

Laravel 9 project through "page is not working, http 500 error on Hostinger."

I created a project on laravel 9 and uploaded it on hostinger server on subdomain .
the root of my file is : public_html/gymsoftware.folder of laravel project
i have moved all file from public folder to gymsoftware, updated index.php and configure .env file
**index.php file **
<?php
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Check If The Application Is Under Maintenance
|--------------------------------------------------------------------------
|
| If the application is in maintenance / demo mode via the "down" command
| we will load this file so that any pre-rendered content can be shown
| instead of starting the framework, which could cause an exception.
|
*/
if (file_exists($maintenance = __DIR__.'/storage/framework/maintenance.php')) {
require $maintenance;
}
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| this application. We just need to utilize it! We'll simply require it
| into the script here so we don't need to manually load our classes.
|
*/
require __DIR__.'/vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request using
| the application's HTTP kernel. Then, we will send the response back
| to this client's browser, allowing them to enjoy our application.
|
*/
$app = require_once __DIR__.'/bootstrap/app.php';
$kernel = $app->make(Kernel::class);
$response = $kernel->handle(
$request = Request::capture()
)->send();
$kernel->terminate($request, $response);
**.htaccess file **
<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>
error
error on subdomain
i already updated index file , env file and reuploading.

how to remove (public) path from URL in laravel8 c-panel?

I tried a lot of solutions to remove (public) path from URL but doesn't work, I've laravel8 project and when visit the root path like this (domainName/) it shows:
Note: these folders in (root) that show in the image, some of them, I already removed it like (node_module, .haccess), I don't know why still shows the old data or the deleted folders?!
when visit the project with (public path) like this (domainName/public/)), the project works fine.
I tried a lot of solution like create new (.htaccess) and edit it, but all solutions doesn't work and get the same picture below.
Root/server.php:
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* #package Laravel
* #author Taylor Otwell <taylor#laravel.com>
*/
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
return false;
}
require_once __DIR__.'/public/index.php';
public/index.php:
<?php
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Check If The Application Is Under Maintenance
|--------------------------------------------------------------------------
|
| If the application is in maintenance / demo mode via the "down" command
| we will load this file so that any pre-rendered content can be shown
| instead of starting the framework, which could cause an exception.
|
*/
if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) {
require $maintenance;
}
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| this application. We just need to utilize it! We'll simply require it
| into the script here so we don't need to manually load our classes.
|
*/
require __DIR__.'/../vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request using
| the application's HTTP kernel. Then, we will send the response back
| to this client's browser, allowing them to enjoy our application.
|
*/
$app = require_once __DIR__.'/../bootstrap/app.php';
$kernel = $app->make(Kernel::class);
$response = $kernel->handle(
$request = Request::capture()
)->send();
$kernel->terminate($request, $response);
public/.haccess:
<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]
any help please?
Just add new file .htaccess to the main folder and add this code inside :
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Change the URL to your website URL

Laravel 5.8 Fresh Deployment Not Working In Hostinger Shared Hosting

I tried to deploy a fresh laravel application. I installed a laravel 5.8 and upload to github repository.
The repository or project folder is working since I tried to run php artisan serve and it successfully shows the laravel home screen page.
I tried to connect in my shared hosting using ssh.
Here's the steps that I've done:
Access thru ssh
create a project folder mkdir my-assignment-calculator then cd my-assignment-calculator
Clone project repository. git clone **repo_url**
Navigate the project folder, cd my-assignment-calculator
Copy .env file, cp .env-example .env
Install composer packages. composer install
Then copy all files in Public folder to public_html folder
Go to public_html then update index.php, nano index.php
In index.php, I update these two lines, the vendor/autoload.php and the bootstrap/app.php
Here's the sample code for #9:
require __DIR__.'/../my-assignment-calculator/my-assignment-calculator/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__.'/../my-assignment-calculator/my-assignment-calculator/bootstrap/app.php';
Here's the structure of my project folder
-public_html
-domains
--my_assignment_calculator
--my_assignment_calculator
---laravel files
The current output is only white screen. I tried to check the developers tools or devtools, there's no error. It's just a white background. It's the same as before.
I tried to check .htaccess file and I didn't touch this file. Here is the .htaccess:
<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]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
So what is the expected output
Should display laravel welcome or home screen page
laravel folder is in root then all your public folder files transfer it into public_html then go to your index file in your public_html configure by adding laravel directory like this:
require __DIR__.'/../laravel/vendor/autoload.php';
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';

Laravel 5 shared hosting deployment issues

I am trying to deploy laravel 5.2 on shared hosting.
I installed the laravel core app folder a level above the public_html folder (/../public_html or /home/username ).
I extracted the files in the laravel core public folder (public) and pointed the index.php file to the laravel core app folder a root above (/../laravel-app/bootstrap/autoload.php and /../laravel-app/bootstrap/app.php).
The website homepage is working but pages links are returning a 404 and it isnt pulling in any css or js.
Any ideas on how I can fix this?
Points to note:
I am on php ver 5.6
I changed the file permission in laravel-app/storage to a 777
I deleted the .htaccess fil in the public_html folder
Server is apache
Buddy just follow this tutorial, I tried it and it's working just fine!
https://medium.com/laravel-news/the-simple-guide-to-deploy-laravel-5-application-on-shared-hosting-1a8d0aee923e#.5lywcjmnn
Btw, you don't even need the last part after this sentence
If you don’t have composer installed already on your server, you can easily grab it to the project directory then.
In my case I did the following:
placing laravel project outside of public_html as lara folder
then I had this htaccess in it:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
and inside public_html I had .htacess with:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^awesome
RewriteRule ^(.*)$ awesome/$1 [L]
Where awesome is the directory that contains htacess (listed down) and index.php, favicon and robots.txt:
<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>
final change is in index.php:
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* #package Laravel
* #author Taylor Otwell <taylorotwell#gmail.com>
*/
/*
|--------------------------------------------------------------------------
| 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 nice to relax.
|
*/
/* die(__DIR__); /home/{YOURHOST}/public_html/awesome */
require __DIR__.'/../../lara/bootstrap/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__.'/../../lara/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);

Deploy Laravel to domain subfolder

Intro
I am struggling to deploy a Laravel project to a domain subfolder... Here's the complete "story":
My teacher has control of the machine at: http://ilp.fe.up.pt/
He created a user for me called mitocondrias so I could use it via ssh like:
ssh mitocondrias#ilp.fe.up.pt
He also set the usual public_html folder to be called html only.
So, to sum up, if I create a simple hello world index.html at /home/mitocondrias/html/ I can successfully see it at http://ilp.fe.up.pt/mitocondrias/
What I did
Now, regarding the Laravel deploy, here is what I did:
I cloned my Laravel project called CoExpr to my user home: /home/mitocondrias/coexpr
I deleted the html folder and created a symlink to /home/mitocondrias/coexpr/public called html with the following command:
mitocondrias#ilp:~$ ln -s ~/coexpr/public/ html
So, here is the final tree structure:
ilp.fe.up.pt/ (the root of my teacher web hosting)
|
|-- mitocondrias/ (my user home, aka /home/mitocondrias)
| |
| |-- coexpr/ (the Laravel project)
| | |
| | |-- [...]
| | |-- public/
| | |-- [...]
| |
| |-- html/ (this is actually not a folder,
| | but a symlink to /home/mitocondrias/coexpr/public/)
I also ran the following commands to set the correct Laravel permissions:
chmod -R 755 coexpr/
chmod -R o+w storage
The problem
After all this, I can successfully see the landing page at: http://ilp.fe.up.pt/mitocondrias/ (the equivalent of localhost:8000 if I were serving the app with php artisan serve)
But when I try to use other routes, like: http://ilp.fe.up.pt/mitocondrias/explorer (the equivalent to localhost:8000/explorer) I get:
404 Not Found
The requested URL /home/mitocondrias/html/index.php was not found on this server.
What did I do wrong..?
Extra info
In case this is relevant, the .htaccess in /home/mitocondrias/coexpr/public/ is as it was generated upon the Laravel project creation with composer - I did not touch 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>
And because of the symlink, this is also the .htaccess at /home/mitocondrias/html/.
End
So, that's it... Aff, this was a long post... Thanks in advance!
This related question provides a debugging hint: Check if the route works with /index.php/, to see if the problem is related to .htaccess.
Loading http://ilp.fe.up.pt/mitocondrias/index.php/explorer works!
So for some reason your .htaccess is not working.
Maybe simply enabling it will fix your problem, as stated in this answer to another related question.

Categories