Laravel 5 - env local debug true no errors shown - php

I'm trying to enable the debug for my app but it looks like I don't have any feedback.
The environment is set to local (in the .env file) and if I run
php artisan env
I get this
Current application environment: local
The debug config for my local env is set to true
return [
'debug' => true,
Also if I set in my main config file (app.php inside the config folder) the debug = true I still have ho feedback that there is an error in the code.
I only have an empty page if there is an error in the code (as for debug = false)
What am I missing?

I have worked around the issue by chmod -R 777 storage/ on my host machine (Mac OS X). On my guest machine (Ubuntu 14.04) chmod -R 777 storage/ did not change permissions actually.

php artisan optimize and if it still does not work delete the file storage/meta/compiled.php as mentioned in a forum topic on Laracasts
I had the same problem and the artisan command did the trick.
UPDATE
I found out that a nice way to workaround storage folder related issues is to set www-data as its owner.
I'm using two commands:
sudo chown $(whoami):www-data . -R
and
sudo chown www-data: storage -R
From Laravel 5.1 it may be necessary to do this last command on bootstrap folder too.

I had a situation where I had the exact same symptom, some routes were not providing any feedback, just a white page, no error in the log no information at all.
Turns out, I was adding a new middleware, and I forgot to return $next($request) from my handle method. This was even more frustrating, because this middleware did not apply to every route, so I assumed that there was an intermittent error that was being thrown but not displayed on these routes.

As Blair said, it may turn out that you put some wrong code in the middleware or in 'Exceptions/Handler.php' e.g. :
if($e->getStatusCode()===404) { ... }
instead of
if($e instanceof NotFoundHttpException) { ... }

Even on Windows needs to do : chmod -R 777 storage/
You can run it with Git Bash;

Also if you just installed lumen make sure you have renamed .env.example to .env in your main app directory as it won't work if your config is still named environment file is still named .env.example.

I actually solved the problem by un-commenting the line
Dotenv::load(__DIR__.'/../'); in bootstrap/app.php.
So that it actually loads it before compiling it and caching it , well running php artisan optimize does it for you , if you have Laravel (Not Lumen)
But if you look at their documentation it is commented out by default, i think they might have fixed it by now http://lumen.laravel.com/docs/installation.

Just for the sake of completeness, I had this issue when the error occurred in methods that used Model::findOrFail($someId). Replacing it with Model::find($someId) displayed the error log.

If the above answers didn't work for you, you may want to check the config files that you might have changed and start debugging from there.
In my case, the above solutions didn't work for me because the root cause of my problem was changing the timezone in config/app.php file (from laravel default UTC I changed it to EST5EDT). For some reason the timezone setting change prevents laravel from logging the errors in storage folder and I am getting blank screen (no whoops! error message). I changed the timezone to America/New_York instead and the error logs are working again.
Hope this helps.

For me what worked perfectly was disabling hhvm in the Homestead.yaml file, then I did vagrant reload --provision and that was it!

Go to config/app.php and if it is like this :
'debug' => env('APP_DEBUG', false),
Then it change to :
'debug' => env('APP_DEBUG', true),
this.

I have faced same problem so i have checked handler.php file of exceptions folder where render function that have return value line is commented so page make blank.
public function render($request, Exception $exception)
{
//return parent::render($request, $exception);
}

Please check in
.env file
APP_ENV=local
APP_DEBUG=true
and also in config/app.php, check for these values
'env' => env('APP_ENV', 'local'),
'debug' => true,

Related

Call to undefined method Closure::__set_state() error on php artisan optimize [duplicate]

My code in on production and I ran
php artisan config:clear
After that, my code was not running. The index pages and all other pages went white screen and gave 500 internal server error in firebug. When I tried to run
php artisan
it gave me error as
PHP Fatal error: Call to undefined method Closure::__set_state() in /var/www/live/vendor/config.php on line 56
My code is in production!! /vendor/config.php file was not present before, what happened with that code??
Have you faced any such error?
I had given all permissions to storage/ folder and vendor/.
Any help/guide would be much appreciated.
I had similar issues when I ran php artisan config:cache. Apparently, it is an issue when the application is trying to load cached configuration files that have closures in it. It won't be fixed in Laravel since it is a bad practice to have closures in config files. Refer this Github issue
The way I solved this is by undo-ing this.
Delete the cache for config.
It is located in here
bootstrap/cache/config.php
OR
vendor/config.php
I had faced the similar issue in past don't know what caused it but as of now you can delete the config.php from /vendor it won't break your code.
And your code will be start working..
Among other root-causes, this error results from calling php artisan config:cache when a closure is defined inside any configuration file that Laravel attempts to load. Laravel does not allow for closures in configuration files; see:
https://github.com/laravel/framework/issues/9625
Deleting the resultant cache file, usually located at bootstrap/cache/config.php, "fixes" the error.
The long-term solution is to eliminate closures from all configuration files. The problematic config file can be determined by inspecting the offending line, as mentioned in the error message.
If the offending file is third-party, it is best to open an issue with the library, so that the issue is fixed upstream.
Here is what I did to solve it:
Go to /vendor/tymon/jwt-auth/src/config/config.php and replace the lines for storage and auth with:
'auth' => 'Tymon\JWTAuth\Providers\Auth\IlluminateAuthAdapter',
'storage' => 'Tymon\JWTAuth\Providers\Storage\IlluminateCacheAdapter'
Go to /bootstrap/cache/config.php and delete it
Run the following commands in order:
A) php artisan config/cache
B) php artisan jwt:generate
C) php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\JWTAuthServiceProvider"
and that should do it!
Try to remove the config.php from bootstrap/cache folder. It worked for me.
Edit vendor\laravel\framework\src\Illuminate\Foundation\Support\Providers\RouteServiceProvider.php:108
and delete required.
Changing the config.php file inside the vendor/tymon/jwt-auth/src/config to this
'auth' => Tymon\JWTAuth\Providers\Auth\IlluminateAuthAdapter::class`
and this
'storage' => Tymon\JWTAuth\Providers\Storage\IlluminateCacheAdapter::class`
before runnning php artisan config:cache worked for me.
solved using
composer update
composer install

Uncaught Exception: Unable to locate Mix file

I am trying to run a laravel app in my local system. I have followed the https://gist.github.com/hootlex/da59b91c628a6688ceb1 link. I run the command php artisan serve command, and when I browse it, then produces the error
PHP Fatal error: Uncaught Exception: Unable to locate Mix file: /css/vendor.css. Please check your webpack.mix.js output paths and try again. in /var/www/html/laravel-app/app/helpers.php:439
In the specified line of helpers.php, it has
if (! isset($manifest[$path])) {
throw new Exception(
"Unable to locate Mix file: {$path}. Please check your ".
'webpack.mix.js output paths and try again.'
);
}
public/mix-manifest.json
{
"/mix.js": "/mix.js"
}
I couldn't sort it out. Please help. Thanks
The blade file you're loading obviously has mix('/css/vendor.css') call. You either comment out this line(s) or install npm then build your assets.
Your manifest file doesn't have /css/vendor.css but if you check your blade files (views) you'll see you are calling mix('/css/vendor.css'). So if you find and comment out this line(s) your problem will be solved.
Ideally, mix() is used for loading assets that were built by webpack. It will then take care of the versioning string for you. How mix can be used is detailed in the documentation. I will refrain myself from discussing that here.
You've built your assets by running npm run dev or similar commands. And then the manifest file doesn't contain those assets mapping. And your public directory doesn't have those assets as well. Then it's safe to assume that you can remove those mix calls from your blade (views) files.
If you have the assets built in your public directory then you can load those assets by assets function.
Lastly, you should know your assets first, before loading them to your site. I get the notion that you don't have any clue where those assets came from, so you shouldn't load them in the first place.
This happened with me and after spending quite some time and effort, I did manage to figure out what was happening and how to fix it.
Here's what happens:
You update your webpack.mix.js file with the destination where you wish to publish your compiled JS and CSS files respectively.
mix.js('resources/js/app.js', 'public/js').vue();
Mix compiles and stores the hence generated CSS and JS files within their respective destination folders when you run npm run dev or npm run watch.
laravel-app (Your laravel app root folder)
\public
\css
\app.css
\js
\app.js
When you open the application in your browser with, say Valet, Laravel spits out the following error message:
Unable to locate Mix file: /js/app.js
(or)
Unable to locate Mix file: /css/app.css
Something worth noting on the Uncaught Exception screen though, is that Laravel by default attempts to look for the files at localhost:8080. Implied that Laravel is looking for the files respectively at:
localhost:8080\css\app.css
(and)
localhost:8080\js\app.js
Hence, if your hostname or port is anything other than localhost:8080, Laravel would not be able to find your files. For example, if you're using Valet, your default URL would become laravel-app.test where laravel-app is the name of your app's root folder.
But, there's a way to fix this. And it comes directly out to Laravel's documentation.
Solution (TL;DR)
In order to use a custom mix base URL, you would require to update your config\app.php file to add the following configuration value for setting the mix URL:
'mix_url' => env('MIX_ASSET_URL', 'localhost'),
With your mix_url config option set in your app.php file, you should now be able to manipulate it by adding the MIX_ASSET_URL key in your .env file and setting it to blank, so that it points to \public\js\app.js and \public\css\app.css respectively, within your project directory.
MIX_ASSET_URL=""
That solved it for me. Hope it does it for your too. Lemme know how it goes. Cheers!
Try running npm install and after that build the assets, either npm run dev or npm run watch , depends on what you are using.
In my case,
laravel 9
I should have changed the mix-manifest.json file
"/js/application.js": "/js/application.js",
"/js/admin.js": "/js/admin.js",
"/css/application.css": "/css/application.css",
"/css/admin.css":"/css/admin.css"
Delete package-lock.json.
Delete folder 'node_modules' and run 'npm install' to reinstall all modules.
Then run 'npm run watch' or 'npm run production'.
That helps me to fix that problem.
check the package.json file for the command to build the scripts and styles, normally you will have by default: npm run dev. Might happen that you will need to run:
npm rebuild node-sass
npm run dev or npm run watch
I changed my webpack.mix.js files and made these changes there and worked. Only define the specific path to public/js/app.js in webpack.mix.js
mix.js(
[
"resources/assets/js/jquery.js",
"resources/assets/js/popper.js",
"resources/js/app.js",
],
"public/js/app.js"
)
.autoload({
jquery: ["jquery", "jQuery", "$", "window.jQuery"],
Popper: ["popper", "Popper", "popper.js"],
popper: ["Popper", "popper.js"],
})
.vue()
.postCss("resources/css/app.css", "public/css", [])
.sass("resources/sass/app.scss", "public/css")
.disableNotifications(); // to disable notifications of building app;
In My case, I change
'debug' => false, to true
in the file app.config under config folder in my project to see log in my browser. Then when I run my project got error above like you. then I change to
'debug' => false again. It works.

Laravel 5 on php artisan config:clear generated Closure::__set_state() error

My code in on production and I ran
php artisan config:clear
After that, my code was not running. The index pages and all other pages went white screen and gave 500 internal server error in firebug. When I tried to run
php artisan
it gave me error as
PHP Fatal error: Call to undefined method Closure::__set_state() in /var/www/live/vendor/config.php on line 56
My code is in production!! /vendor/config.php file was not present before, what happened with that code??
Have you faced any such error?
I had given all permissions to storage/ folder and vendor/.
Any help/guide would be much appreciated.
I had similar issues when I ran php artisan config:cache. Apparently, it is an issue when the application is trying to load cached configuration files that have closures in it. It won't be fixed in Laravel since it is a bad practice to have closures in config files. Refer this Github issue
The way I solved this is by undo-ing this.
Delete the cache for config.
It is located in here
bootstrap/cache/config.php
OR
vendor/config.php
I had faced the similar issue in past don't know what caused it but as of now you can delete the config.php from /vendor it won't break your code.
And your code will be start working..
Among other root-causes, this error results from calling php artisan config:cache when a closure is defined inside any configuration file that Laravel attempts to load. Laravel does not allow for closures in configuration files; see:
https://github.com/laravel/framework/issues/9625
Deleting the resultant cache file, usually located at bootstrap/cache/config.php, "fixes" the error.
The long-term solution is to eliminate closures from all configuration files. The problematic config file can be determined by inspecting the offending line, as mentioned in the error message.
If the offending file is third-party, it is best to open an issue with the library, so that the issue is fixed upstream.
Here is what I did to solve it:
Go to /vendor/tymon/jwt-auth/src/config/config.php and replace the lines for storage and auth with:
'auth' => 'Tymon\JWTAuth\Providers\Auth\IlluminateAuthAdapter',
'storage' => 'Tymon\JWTAuth\Providers\Storage\IlluminateCacheAdapter'
Go to /bootstrap/cache/config.php and delete it
Run the following commands in order:
A) php artisan config/cache
B) php artisan jwt:generate
C) php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\JWTAuthServiceProvider"
and that should do it!
Try to remove the config.php from bootstrap/cache folder. It worked for me.
Edit vendor\laravel\framework\src\Illuminate\Foundation\Support\Providers\RouteServiceProvider.php:108
and delete required.
Changing the config.php file inside the vendor/tymon/jwt-auth/src/config to this
'auth' => Tymon\JWTAuth\Providers\Auth\IlluminateAuthAdapter::class`
and this
'storage' => Tymon\JWTAuth\Providers\Storage\IlluminateCacheAdapter::class`
before runnning php artisan config:cache worked for me.
solved using
composer update
composer install

Laravel Lumen Memcached not found

Ok, I just started with Lumen and I'm trying to use the Auth, but a call to either Auth::check or any other function of Auth.. leads to the below Error
Fatal error: Class 'Memcached' not found in vendor\illuminate\cache\MemcachedConnector.php on line 52.
I don't want to use Memcached never used it before.
I disabled it in the .env file and set the CACHE_DRIVER and SESSION_DRIVER to array, but still shows the same error.
I decided not to use Auth again and to manually handle my authetication with sessions/tokens, but enabling the MiddleWare StartSession results to the same error.
$app->middleware([
// 'Illuminate\Cookie\Middleware\EncryptCookies',
// 'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
'Illuminate\Session\Middleware\StartSession',
// 'Illuminate\View\Middleware\ShareErrorsFromSession',
// 'Laravel\Lumen\Http\Middleware\VerifyCsrfToken',
]);
Please I'd be so glad if anyone can really help me out here
EDIT
After going A little Deep in the framework
I Hard Coded the session driver name in the SessionManager Class
within the method getSessionConfig
public function getSessionConfig()
{
$this->setDefaultDriver("cookie");//I added this line
return $this->app['config']['session'];
}
It works though but not a good way of doing things.
There is no config file, i believe all configurations are written in .env file, but i really don't know why the session_driver and cache_driver is defaulted to memecached even after changing it in the .env and then ran composer dump-autoload ... Lumen :(
EDIT
This is my .env file
APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomKey!!!
APP_LOCALE=en
APP_FALLBACK_LOCALE=en
DB_CONNECTION=mysql
DB_HOST=localhost
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=
CACHE_DRIVER=array
SESSION_DRIVER=cookie
QUEUE_DRIVER=database
I already have this line uncommented in my bootsrap/app.php
Dotenv::load(__DIR__.'/../');
My DataBase configuration works perfectly so the .env file is loaded
quite alright.
I spent 3 hours on this problem today. With the help of the post of demve in this topic, I found the solution. Very simple! I hope it won't affect me later in my development.
Just to it, in the .env file :
CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_DRIVER=array
Ok, I make an UPDATE because I was faced with a new problem about the session. In fact, when you set the previous parameters, your session won't be persistent, like said in the documentation: array - sessions will be stored in a simple PHP array and will not be persisted across requests.
So I have to change it, always in .env a file like that :
SESSION_DRIVER=cookie
With a var_dump(Session::all()); I now can see the whole values of my session
You may need to restart your server, especially if you're using php artisan serve.
Lumen doesn't appear to pick up .env changes per-request.
I had exactly the same issue - trying to use file cache, but received errors regarding Memcached - restarting the server reloads the .env file.
This issue resolved when i installed this package so try at least
First i tried this and it works fine
CACHE_DRIVER = array
but then thought about what is memcached
Then i tried this and it works fine without changing driver memcached
apt-get install php-memcached
yum package manager or in Amazon Linux.
yum install php-memcached -y
In .env file replace
#This line:-
CACHE_DRIVER = memcached
#With this:-
CACHE_DRIVER = array
Make sure not to get caught out by your .env file not being loaded, which by default it's commented out in Lumen. So if you are specifying a different cache driver in your .env, do the following.
Note: If you are using the .env file to configure your application, don't forget to uncomment the Dotenv::load() method in your bootstrap/app.php file.
Source: http://lumen.laravel.com/docs/cache
in your .env file, you can also use CACHE_DRIVER=file instead of CACHE_DRIVER=memcached
In my case i added Add CACHE_DRIVER=array in .env file
Then
Dotenv::load(__DIR__.'/../');
in my bootstrap/app.php and the .env file started working.
For me, the issue was that I used the php-7 branch of homestead repository which does not have PHP memcached ready.
I had a similar problem now, I couldn't track it down but my guess is that it has something to do with the fact that the defaults configurations are stored in the vendor/laravel/lumen-framework/config folder, the DotEnv::$inmutable setting and the artisan serveserver.
The solution that worked for me was:
Add in bootstrap/app.php the following:
Dotenv::makeMutable();
Dotenv::load(__DIR__.'/../');
Dotenv::makeImmutable();
in the .env file, set all the configuration to "basic drivers" (array, file) even if you are not going to use them, because you w
If you have a new lumen installation,
you must rename .env.example to .env . So it can read your configurations!
This happens if your .env file is owned by another user than the one trying to run the artisan command.
Check if memcached is installed, if not install it by running:
apt-get install php5-memcached

Laravel on shared hosting - subdomain

I am trying to deploy my laravel application on a shared hosting. It should be deployed in www.subdomain.something.com
My folder structure is:
/laravel
app/
vendor/
bootstrap/
server.php
artisan
composer.json
composer.lock
phpunit.xml
/public_html
subdomain/
index.php
My index.php have the following paths:
require '/../../laravel/bootstrap/autoload.php';
$app = require_once '/../../laravel/bootstrap/start.php';
My paths.php
'app' => __DIR__.'/../../laravel/app',
'public' => __DIR__.'/../../public_html/subdomain',
'base' => __DIR__.'/../../laravel',
'storage' => __DIR__.'/../../laravel/app/storage',
Can anyone see what I am missing? I tried google, and found a bunch of step-by-step explanations but nothing seems to work - It results in a 500 internal server error.
Thanks for any feedback
Wesley
Follow the first rule here.
If you use the first rule then everything should work fine. But somehow if you face 500 Internal Server Error then login to ur server public_html directory through ssh and give the following command.
sudo chmod 755 -R laravel
chmod -R o+w laravel/storage
Here laravel is your Laravel project directory.
Make sure you have write permissions to app/storage/ and all the sub directories. This sounds like the culprit but if not then see if you get any errors in the app/storage/logs dir. If not see if you can parse the server logs.
I was having similar problem and found the solution.Maybe someone can get help with this,
Install LARAVEL 5 Locally Same as Share Hosting Directory (Deploy L5 Share Hosting Solution)
I tried to deploy my first Laravel 8 application on shared hosting on DreamHost, and did encounter some issues.
First I was not able to use composer. Composer 1 was available however, I was unable to upgrade it to Composer 2. ( Was getting errors)
Finally, I ended up uploading all files from my local system to the subdomain root folder (e.g. cota.mydomain.com)
When I tried cota.mydomain.com, I got 404 error.
When I changed url to cota.mydomain.com/public/index.php, the application started working. However, all href links which were defined like href="/home" or href="/client/create" started giving 'not found' errors. To fix this issue I had to use named routes in href, e.g. href=" {{ route('client.show',['id'=>$client->id]) }}". This solved the issue, however, the URL displayed included public/index.php, e.g. cota.mydomain.com/public/index.php/client/show/1.
To further fix the problem, I changed the web folder (root folder) for my subdomain to include public, i.e. cota.mydomain.com/public
Next I added an index.php in cota.mydomain.con with the following contents
header("Location: http://www.cota.mydomain.com/public/index.php"); die();
This fixed all issues, including remving public and index.php from link URLs.

Categories