0

I have seen this answer in many posts but they have not helped me at all. I followed the regular steps to create the laravel project like this:

  1. I cloned from my repository.
  2. I ran composer update.
  3. I added 777 permissions to storage and bootstrap folders.
  4. I have a .env file.
  5. I verfied the .htacces and it's ok.

It is working in locahost, but when I try to replicate it in Hostinger it does not work, it displays the 500 server error. So I wonder what is the problem?

I checked the logs by the way and they were empty. I put the laravel project debugger to true too.

the website url is xellin.com

The debug:

Debug

The logs folder:

logs folder

Thanks.

Emkrypted
  • 59
  • 9
  • Question: after the fourth point (.env)... have you added an app key? It would follow to add an application key with php artisan key:generate (this is part of new clone process). – paulmartimx Jun 27 '20 at 17:39
  • Hi @paulmartimx yes I did it, I ran the comand php key generate to see if it could be and I got same result. – Emkrypted Jun 27 '20 at 17:41
  • Check your error log & let us know here. You can check on your server error log or on your laravel log – STA Jun 27 '20 at 17:44
  • Did you check the Laravel log and or the server error logs? A 500 is a general public error designed to protect the world from seeing the actual error. The actual error will be recorded in one of the logs. If you can for a brief moment you change debug=true in your .env very quickly to see what the actual error is. This is risky though because it exposed data to the public even for a brief second. – jeremykenedy Jun 27 '20 at 17:44
  • Hi @STA this server does not have Cpanel :/ – Emkrypted Jun 27 '20 at 17:45
  • Hi @jeremykenedy I went to storage/logs but the folder is empty... and I put the laravel as debugger true in .env and config file too – Emkrypted Jun 27 '20 at 17:46
  • @Emkrypted ... one thing I know for sure: If the error was not registered in Laravel logs, then the Laravel running lifecycle never happened. Meaning that this is problem is related to the initial interaction between PHP and Server itself (php / apache / nginx) ... and the only way to know what's happening in that situation is to inspect APACHE / NGINX error logs... not laravel's – paulmartimx Jun 27 '20 at 17:55
  • @STA I had done that I got same result – Emkrypted Jun 27 '20 at 17:55
  • Clear your config `php artisan config:clear` – STA Jun 27 '20 at 17:56
  • @STA I just did in this moment and I watched the website with the tor browser to skip the cache and cookie stuffs and same issue :/ and I got same error. – Emkrypted Jun 27 '20 at 17:58
  • Guys... you need to point out that Laravel is not running yet a this point. All the symptoms says it is a underlying server / php error... see my answer below for more detailed explanation. – paulmartimx Jun 27 '20 at 18:12
  • Possible version mismatch. Tell us your laravel version and check the php version on your server and let us know here. – STA Jun 27 '20 at 18:14
  • 1
    @STA Yes, it is very possible. If it is Laravel 7, you need PHP 7.3 at minimum – paulmartimx Jun 27 '20 at 18:17
  • @paulmartimx if php version mitmatch then the laravel cant run so logs remain empty. – STA Jun 27 '20 at 18:43
  • @paulmartimx he was right, it was not laravel problem, it was a apache problem: SoftException in Application.cpp:404: Mismatch between target UID (1000) and UID (0) of file "/home/xellin/public_html/index.php" – Emkrypted Jun 28 '20 at 04:43

3 Answers3

1

I think this is a good opportunity to point out how PHP / Laravel / Underlying Server interacts one to each other.

First:

  1. The HTTP server inspects Document Root and .htaccess to get instructions.
  2. If the file is .php (like Laravel), then it CALLS to the php handler.
  3. The php handler could be a FPM version or a Fast CGI version.

-> If an error ocurrs parsing the .htaccess or with the initial interaction between Http Server and PHP... Laravel never runs for real. All ends in a PHP error log

To find out what's wrong, you need to inspect what PHP / Http Server said about the error in their respective logs.

In short words: at this point is not a Laravel error, but a server/php one.

Second:

If Apache/PHP runs well, then PHP executes the Laravel Applicacion Lifecycle... if Laravel encounters a problem, then you will see the usual output error of Laravel Error Handler.

I think this is a must to know to work with web apps in general, because many times developers miss to catch if the problem was with Laravel, or with PHP / Server itself.

As a side note, that's why it is important to know how to choose propper hosting service for Laravel.

Thanks for reading.

paulmartimx
  • 226
  • 2
  • 5
0

You can try to clear cache Like as php artisan optimize Or You can manually delete cache files which is located in bootstrap folder and inside bootstrap folder you can see cache folder inside cache folder delete all files except git ignore file your issue fix If you show again this error on live serve then tou can update your composer and then run php artisan optimize

0

at first, if you give any of your folders 777 permissions, you are allowing ANYONE to read, write and execute any file in that directory.... what this means is you have given ANYONE (any hacker or malicious person in the entire world) permission to upload ANY file, virus or any other file, and THEN execute that file...so please be careful because IF YOU ARE SETTING YOUR FOLDER PERMISSIONS TO 777 YOU HAVE OPENED YOUR SERVER TO ANYONE THAT CAN FIND THAT DIRECTORY. please read the full explanation from here

the second here is the detailed steps I used to deploy my projects to the server:

  1. run npm run production then update your github repo.
  2. clone the project from GITHUB to server - clone to an outside folder (not public_html folder)
  3. run cd <cloned folder name>
  4. run composer install
  5. run npm install
  6. copy and configure .env file to cloned folder( be sure name is .env not env).
  7. copy all content of cloned_project_folder_name/public to public_html folder
  8. in index.php inside public_html folder edit as below
$app = require_once __DIR__.'/../cloned_project_folder_name/bootstrap/app.php';
require __DIR__.'/../cloned_project_folder_name/vendor/autoload.php';
  1. set your .htaccess properly.
  2. change permission to 755 to index.php and all file in public_html folder
  3. run composer install --optimize-autoloader --no-dev
  4. run php artisan config:cache
  5. run php artisan route:cache

I think I state it all, hope that will help

IBRAHIM EZZAT
  • 964
  • 9
  • 22