Laravel 5.7 giving error 500 on localhost - laravel-5

I have recently installed laravel 5.7 on my machine but its giving me a 500 error but at tje same time i have anothe laravel 5.6 app which is working on the same server. What could be the problem. I am working on a windows machine

Did you see at your server logs to see what the error 500 actually is?
1) Go to your Laravel logs (app/storage/logs) and see if the error is contained in there.
2)Yo can just debugging add a die('hi') command at the start of your routes file and then find out where is the error
3) I added the following to the public/index.php on my cause it helped me
try {
$app->run();
} catch(\Exception $e) {
echo "<pre>";
echo $e;
echo "</pre>";
}

Related

Route:list works in local machine but gives error on server in laravel

I was updating my server code and everything worked well, even the migration and seeding.
but when I tried login URL it gave me 404 error so I checked and in that process ran then PHP artisan route: list command in the terminal.
and got the error as below:
PHP artisan route: list
Illuminate\Contracts\Container\BindingResolutionException : Target class [App\Http\Controllers\Api\V1\UserController] does not exist.
at /var/www/html/x/vendor/laravel/framework/src/Illuminate/Container/Container.php:805
801|
802| try {
803| $reflector = new ReflectionClass($concrete);
804| } catch (ReflectionException $e) {
> 805| throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
806| }
807|
808| // If the type is not instantiable, the developer is attempting to resolve
809| // an abstract type such as an Interface or Abstract Class and there is
Exception trace:
1 Illuminate\Foundation\Console\RouteListCommand::Illuminate\Foundation\Console\{closure}()
[internal]:0
2 ReflectionException::("Class App\Http\Controllers\Api\V1\UserController does not exist")
/var/www/html/x/vendor/laravel/framework/src/Illuminate/Container/Container.php:803
Please use the argument -v to see more details.
it says the given controller cannot be found. I have personally checked the folder and it exists. the permissions are correct and also if I run the same command in the local machine, I do get the route list on the same code.
have tried composer dump-autoload and composer update still no use of that as the error exists. so what's the real issue here. how to solve this issue?
ok found the real issue. it was as below.
App\Http\Controllers\Api\V1\UserController
WAS CHANGED TO
App\Http\Controllers\API\V1\UserController
I thought only windows are not case sensitive to the Caps and small character. As using Mac, I was never able to find it.
Just occurred to check the route list as it might be the case sensitivity, and it was. My bad :/

laravel 4.2 logs on command prompt and not in laravel.log

I am using laravel 4.2, whenever i use Log::info() or Log::Error(). The expected logs doesn't store in laravel.log instead it outputs on command prompt from where it is served. can any one suggest me how i can log those things in my laravel.log file.
I think it's for laravel only. You should create a new folder with a class of Logs.
For example:
in Folder Logs:
class example_logs{
public static function viewLogs($datas){
echo 'Your Error' . $datas;
}
}
in your Controller:
Logs::viewlogs($datas);

laravel 4 header status always return 200 (OK)

I have a code below:
return Response::json($message,401);
It always return 200 OK status in my server.
The strange thing is it returned correct status code in my localhost (PHP 5.5), but when I deploy to web server (PHP 5.4.30), it always return 200 status code.
When I trace back the code, I found a difference in this file:
\vendor\symfony\http-foundation\Symfony\Component\HttpFoundation\Response.php
public function sendHeaders() {
// headers have already been sent by the developer
if (headers_sent()) {
return $this;
}
......
}
headers_sent() -> return false on my localhost, but return true on web server.
Update:
Not only Json resonse having problem, when I try to change the code as below:
http_response_code(401);
echo $message;
It will still always return with 200 code.
But if I run the script outside of laravel as below:
<?php
http_response_code(401);
echo $message;
?>
It's working fine.
Is this problem because of the difference in PHP version ?
If so, is there any way to workaround it ?
Thank you.
Make sure your server meets the Laravel requirements:
PHP >= 5.4, which seems to be the case.
Install the PHP JSON extension if not already installed (apt-get install php5-json).
Install the MCrypt PHP Extension if not already installed (apt-get install php5-mcrypt).
Make sure the app/storage directory is writable by the web server.
Also make sure you have no trailing PHP closing tags (?>) in your PHP files, as they are known to cause the headers already sent problem.

How to display errors on laravel 4?

I'm trying to create an app on Laravel 4 beta but I can't debug it because it doesn't show any error, display_errors is on, error_reporting is E_ALL and debug => true (config/app.php). When I try to do an error on public/index.php it shows a parse error, but when I do it on the router it just shows a blank page (White screen of death). How can I fix this?
Thank you
#Matanya - have you looked at your server logs to see WHAT the error 500 actually is? It could be any number of things
#Aladin - white screen of death (WSOD) can be diagnosed in three ways with Laravel 4.
Option 1: Go to your Laravel logs (app/storage/logs) and see if the error is contained in there.
Option 2: Go to you PHP server logs, and look for the PHP error that is causing the WSOD
Option 3: Good old debugging skills - add a die('hello') command at the start of your routes file - then keep moving it deeper and deeper into your application until you no longer see the 'hello' message. Using this you will be able to narrow down the line that is causing your WSOD and fix the problem.
I had a problem with the white screen after installing a new laravel instance. I couldn't find anything in the logs because (eventually I found out) that the reason for the white screen was that app/storage wasn't writable.
In order to get an error message on the screen I added the following to the public/index.php
try {
$app->run();
} catch(\Exception $e) {
echo "<pre>";
echo $e;
echo "</pre>";
}
After that it was easy to solve the problem.
Go to
app/config/app.php
and
set 'debug' => true,
Following the good advice by #The Shift Exchange I looked at the error_log and indeed managed to solve to problem. it was simply a permissions issue:
Tue Feb 26 11:22:20 2013] [error] [client 127.0.0.1] PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/Users/matanya/Sites/indgo/app/start/../storage/logs/log-apache2handler-2013-02-26.txt" could not be opened: failed to open stream: Permission denied' in /Users/matanya/Sites/indgo/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:71\nStack trace:\n#0 /Users/matanya/Sites/indgo/vendor/monolog/monolog/src/Monolog/Handler/RotatingFileHandler.php(77): Monolog\\Handler\\StreamHandler->write(Array)\n#1 /Users/matanya/Sites/indgo/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\\Handler\\RotatingFileHandler->write(Array)\n#2 /Users/matanya/Sites/indgo/vendor/monolog/monolog/src/Monolog/Logger.php(217): Monolog\\Handler\\AbstractProcessingHandler->handle(Array)\n#3 /Users/matanya/Sites/indgo/vendor/monolog/monolog/src/Monolog/Logger.php(281): Monolog\\Logger->addRecord(400, Object(ErrorException), Array)\n#4 [internal function]: Monolog\\Logger->addError(Object(ErrorException))\n#5 /Users/matanya/Sites/in in /Users/matanya/Sites/indgo/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 71
Once I used chmod to apply less stringent permissions, all went back to normal.
However, I'm not sure that it answers the OP's question, as he was getting a blank screen rather than a server error.
Inside config folder open app.php
Change
'debug' => false,
to
'debug' => true,
Further to #cw24's answer • as of Laravel 5.4 you would instead have the following amendment in public/index.php
try {
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
} catch(\Exception $e) {
echo "<pre>";
echo $e;
echo "</pre>";
}
And in my case, I had forgotten to fire up MySQL.
Which, by the way, is usually mysql.server start in Terminal
In the Laravel root folder chmod the storage directory to 777
Maybe not on Laravel 4 this time, but on L5.2* I had similar issue:
I simply changed the ownership of the storage/logs directory to www-data with:
# chown -R www-data:www-data logs
PS: This is on Ubuntu 15 and with apache.
My logs directory now looks like:
drwxrwxr-x 2 www-data www-data 4096 jaan 23 09:39 logs/
https://github.com/loic-sharma/profiler this is good example for alternative to laravel3 debug bar.
Just go to your app/storage/logs there logs of error available. Go to filename of today's date time and you will find latest error in your application.
OR
Open app/config/app.php and change setting
'debug' => false,
To
'debug' => true,
OR
Go to .env file to your application and change the configuratuion
APP_LOG_LEVEL=debug

syntax error at server for the code works fine at localhost... it is weird! :/

I have an interesting issue :/ I use CodeIgniter and the code below is working fine at my localhost, but when I upload to server I come cross with an error message like
Parse error: syntax error, unexpected
T_OBJECT_OPERATOR in
/home3/blabla/public_html/blablabla/applications/frontend/models/our_work_model.php
on line 99
function next_project($sort_work)
{
$query = $this->db->select('wname')->order_by('sort', 'asc')->getwhere('works', array('sort >' => $sort_work, 'case_study != ' => ""), 1, 0); //line 99
any idea? appreciate helps! thanks!
I know chaining like that only works in PHP5 - is the server perhaps running an older version of PHP?
Given your last question: __construct() { issue for PHP4 and PHP5. maybe an another reason
I'd say you're running PHP4.
How do you know that your CodeIgniter installation is actually using PHP 5? It could be the case that there are several PHP installations in that machine. To test it, create a PHP file in your server with the following code:
<?php
phpinfo();
?>
Then let us know what version it is showing.
initially i was getting a blank page. so i removed this
error_reporting((E_ALL & ~E_DEPRECATED));
yes if you are using codeigniter and you have to make ove code to this
error_reporting((E_ALL));
and then you will get the error above. and i found it was due to php5 being unused.

Resources