How to debug Laravel 5 projects? - php

I ran command
php artisan optimize
and changed debug settings in app.php file to be
'debug' => 'true',
and added 'everyone' to have full access over 'storage' folder. I don't know what else I can do to let debugger work in my Laravel 5 project.
I'm stuck with 'Whoops, looks like something went wrong' message.
Any Ideas??

The debug => true will just show you the full error stack when you hit an error with your app. It doesn't give metrics and statistics. If you are looking for that kind of information check out the article here:
https://laravel-news.com/2015/02/laravel-debugbar/

The error you are receiving is a general error, likely server-side configuration. Without any information on your setup it will be pretty hard to determine what your issue is. Based upon your question and comments to others responses I have a couple of things for you.
You stated "I don't know what else I can do to let debugger work in my Laravel 5 project". Laravel 5 doesn't have a native debugger any more which I imagine is why your page just shows "Whoops, looks like something went wrong". Your statement would indicate that you have a debugger, so which are you trying to use, or was that statement incorrect?
You stated that you changed the debug settings the app.php file. Is there a reason why you changed this in app.php? The debug setting by default is 'debug' => env('APP_DEBUG') which is sufficient in most cases. You should have a .env file in the root of your project (created automatically if you did a composer create-project, if not you need to copy .env.example to .env on your own). The .env file will enable debug for you as there is a line that states APP_DEBUG=true.
Jesse Schutt gave great information in his response above (which I recommend upvoting), including a link to a debug bar that is compatible with L5. Yet again you are stating that you are satisfied with your error stack which implies that you actually have one. If you were satisfied with it, you would have no need to have posted here as you would already have more information on your error. If you are assuming that the filp/whoops is in l5 still and that's what you want you'll have to re-enable it. Follow the instructions at http://mattstauffer.co/blog/bringing-whoops-back-to-laravel-5

Related

PHP - Laravel error : Symfony\Component\Finder\Exception\DirectoryNotFoundExceptionon my cPanel

I mistakenly ran my laravel application on debug mode in my production environment, and it threw an error for me to change App_debug:true to App_debug:false, which I did, ever since then, my site has been throwing an HTTP ERROR 500
"This page isn’t working admin.robyhub.com is currently unable to handle this request.
HTTP ERROR 500"
I then went on to my cpanel terminal and tried to clear the logs on the config file but it gives me the below error.
[thehcerl#premium261 admin.robyhub.com]$ php artisan config:clear
Symfony\Component\Finder\Exception\DirectoryNotFoundException
The "/home/thehcerl/admin.robyhub.com/resources/lang/ha" directory does not exist.
at vendor/symfony/finder/Finder.php:590
586▕ } elseif ($glob = glob($dir, (\defined('GLOB_BRACE') ? \GLOB_BRACE : 0) | \GLOB_ONLYDIR | \GLOB_NOSORT)) {
587▕ sort($glob);
588▕ $resolvedDirs = array_merge($resolvedDirs, array_map([$this, 'normalizeDir'], $glob));
589▕ } else {
➜ 590▕ throw new DirectoryNotFoundException(sprintf('The "%s" directory does not exist.', $dir));
591▕ }
592▕ }
593▕
594▕ $this->dirs = array_merge($this->dirs, $resolvedDirs);
+2 vendor frames
3 app/Providers/TranslationServiceProvider.php:40
Illuminate\Support\Facades\Facade::__callStatic()
4 app/Providers/TranslationServiceProvider.php:27
App\Providers\TranslationServiceProvider::phpTranslations()
Cpanel Terminal
Ever since I changed debug to false on my .env from my laravel project main directory because the laravel documentation warned me to not use debug mode on a non-local environment. I expected my application would automatically stop receiving the laravel debug config solutions and would run properly.
This is not a very generic error, it's as a result of an error on my part, I created language folders that I did not link to my PHP "translationProvider.php" file, so it invariably gave me that issue.
I was using a purchased template from Envato so I hadn't taken the time to get the full inner working of the backend at the time.
If anyone has a similar error I hope this will guide you not to make the mistakes I made, and meticulously look through your code when making changed or edits.
Thanks, happy coding.

Add syslog handler in Laravel for paperTrail .

How could i link Laravel log files to PaperTrial ?
According to this article :
http://mattstauffer.co/blog/laravel-forge-logging-with-papertrail#step-4-add-a-syslog-handler
I followed steps and reached to step 4 putting Syslog Monolog handler in the /app/route.php file ,went to PaperTrial dashboard but i didn't see any output.
Any help ? thanks.
For Laravel 5.1 after setting up the forge, you should add to bootstrap/app.php file the following code just before the return of the $app variable
$app->configureMonologUsing(function($monolog){
$monolog->pushHandler(new Monolog\Handler\SyslogHandler('papertrail'));
});
return $app;
The parameter (in this case 'papertrail') can be whatever you want to, this name will show on the papertail's event screen.
I have it working using the standard logging facility instead of Monolog. This way there is nothing extra to install. Just add this to rsyslogd's conf:
### Laravel Log
$InputFileName /path/to/vhost/dir/app/storage/logs/laravel.log
$InputFileTag laravel-errors-domain.com:
$InputFileStateFile state-laravel-errors-domain.com
$InputFileSeverity error
$InputRunFileMonitor
And make sure that this log gets included in the send action, if you are not sending everything.
Then issue
service rsyslog restart
From my experience using Laravel 5.2.* with Forge, Step 4 from that article is not necessary anymore. All you have to do after Step 3 is set your Environment .env settings in Forge to APP_LOG=syslog for each site you want to use with papertrail.
However, this means that Laravel will not log to laravel.log anymore in this environment. But, in other environments (e.g. dev environment) you could of course continue logging to laravel.log by simply not making any changes to the .env file there.

Laravel 4.2 says my application is in production. How do I turn this off?

I have a fresh install of Laravel. When running php artisan migrate:refresh I get a message saying Application In Production! Do you really wish to run this command?'
I know this is an update in 4.2, however I can't figure out how to turn it off.
I found in the source that it comes from Illuminate\Console\ConfirmableTrait and runs if this if test passes : if ($this->getLaravel()->environment() == 'production')
I'm not sure why it thinks I'm in production. I never setup any environments. This is the default environment detection, which I'm still currently using.
$env = $app->detectEnvironment(array(
'local' => array('homestead')
));
Also, if I set a production environment to a hostname that isn't my machine, I still have the same problem.
Just specify a machine name for the host that matches a given environment, then laravel will automatically detect the environment (default is production), for example:
$env = $app->detectEnvironment(array(
//'local' => array('homestead'),
'local' => array('*.dev', gethostname()),
'production' => array('*.com', '*.net', 'www.somedomain.com')
));
Read the documentation and this answer as well.
Setting your environment to something other than production is The Right Way. See the accepted answer.
But, if you're looking for A Quick Fix you can use (in UNIXoid environments):
yes | php artisan migrate:refresh
All this does is send a stream of "y" to the program, which acts like you pressed "y" when prompted.
I find this to be a little better than --force, as not all the artisan commands support force.
In case if anyone stumbled upon this question while searching for similar problem in a lumen installation I'd suggest to check the .env file and add APP_ENV=local if its not already there. It solved my problem.
Hopefully this will help someone else. I suddenly had an issue where my dev site I was building stopped connecting to the DB saying:
PDOException SQLSTATE[HY000] [1049] Unknown database 'forge' failed
I was also receiving errors such as the OP when trying to run artisan migrate:refresh etc, the error was stating that i was in production etc etc.
After much head scratching (!) I found that my hostname value set inside the /bootstrap/start.php was wrong, because my hostname had changed on my macbook pro!? I have no idea how but it changed from something like RobMacbookPro2.local to RobMacbookPro.local. This meant it fell back to production thus loading the incorrect database.php file with the standard DB=forge (which was wrong)
Check this guide:
http://laravel.com/docs/4.2/configuration
Pay particular attention to the code:
<?php
$env = $app->detectEnvironment(array(
'local' => array('your-machine-name'),
));
On a mac and probably linux? you can determine your hostname by typing # hostname in terminal.
Hope that saves someone some time!

Laravel Framework not showing errors

Can anyone explain if there is a way to catch or log errors when the following code is executed?
//This has example has no semicolon.
Route::get('user/{id}', function($id)
{
return View::make('profile')
});
or
//This example has no dollar sign (part of a blade template).
Welcome {{ userName }}
I end up with an empty page for these and there have been a few other times this has happened where I can't remember the details.
I have debug set to true in app/config/app.php and I don't get any errors in the log files at app/storage/logs
Is this normal or do I have a problem with my setup?
Thanks
UPDATE
Laravel log commands aren't working for me. See the comment in reply to msturdy.
Sorted this now. I downloaded the latest Laravel and still had identical issues. Eventually I found out that Apache was pointing at a old version of php (5.3.0) that lived on a different drive (no idea how I've done that), anyway I had my command line pointed at the correct version of php, so that's why I've had no issues when installing/updating Laravel.
Small chance anyone would see similar issues as it was a bit of a random situation (my apologies). I now get the prettiest runtime exception page I've ever seen when running the examples :). Thanks msturdy

Jenkins PHP Template - Display's loading message and blocks UI

I'm trying to use the template from http://jenkins-php.org in my installation of Jenkins. As soon as I go in to configure the project I get a grey screen appearing and the words 'Loading'
If I look in the Browser error console I get TypeError: 'undefined' is not an object (evaluating 'registry.get')
Has anyone else experienced this problem? How can this be fixed?
We had this problem when upgraded to 1.528.
Digging further, we found out that the problem is originated from one of the client-side script files called "hudson-behavior.js" and is caused by the "Publish Over SSH" plugin. There have been other plugins that have caused this in the past, as well. We couldn't disable the plugin anyway. So we searched further.
Long story short, we ended up changing the script for the time being. If you, like us, install Jenkins using the war file, then the script file is probably extracted and cached in "/var/cache/jenkins/war/scripts/hudson-behavior.js".
The following change we made was in a function called "registerValidator":
if (depends==null) { // legacy behaviour where checkUrl is a JavaScript
try {
return eval(url); // need access to 'this', so no 'geval'
} catch (e) {
// set depends to an empty array.
depends = [];
}
}
var q = qs(this).addThis();
The URL may not always be valid. Thus, a try-catch is in order. Hope this helps!
I've just had the same issue, I'm using version 1.523 of Jenkins on an Ubuntu server.
The solution I found was to manually edit the project config.xml file.
sudo vim /var/lib/jenkins/jobs/yourProjectName/config.xml
I had images in the description and I removed those leaving the description tag empty.
I also had an empty plot section which I removed completely from the publishers section.
After saving the config and going back to 'manage Jenkins' and then 'Reload Configuration from Disk' I then reopend my project and the config opened normally again.
I wasn't getting quite the same error message as you in the browser console to start with, but I hope that helps.
I too downgraded to 1.523 and then it worked... So it's obviously some bug introduced after 1.524.
Upgrading from 1.530 to 1.531 fixed it for me.

Categories