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
Related
After upgrade from 5.0 to 5.8, laravel stopped reading env variables if the env is different than .env file.
For example, if i have .env file with the USE_SSL=true inside it.
env('USE_SSL') will be true
But if i have .env file pointing to another env:
APP_ENV=dev
and than i'll have .env.dev file containing USE_SSL=true , env('USE_SSL') will be null.
I tried composer dump-autoload and php artisan config:clear, and php artisan config:cache - no luck. cached or not, i can't get the value.
I tried naming the files .dev.env and .env.dev - no luck.
Any ideas would be appreciated.
I'm adding this as an answer, but please note this isn't how .env file should be used according to laravel docs. It's just a way i needed to use due to some restrictions which required me to use different config files for each env, and load it in runtime. For correct usage of .env file check the docs.
This is a way of loading different config files in runtime depends on where the APP_ENV is pointing. I'm marking this as answered since it's answering this specific question.
.env
APP_ENV=specific_domain
.env.specific_domain
USE_SSL=true
Http/Kernel.php
public function __construct(Application $app, Router $router)
{
parent::__construct($app, $router);
$app_env = explode("=", file($app->environmentFilePath(), FILE_IGNORE_NEW_LINES)[0])[1];
$app->loadEnvironmentFrom(".env.$app_env");
}
Alright if you really wanted to do this,
Route::get('renderEnvChaining',function(){
$myCustomEnv = parse_ini_file(base_path(env('CUSTOM_ENV')));
return $myCustomEnv['USE_SSL']; // This will return true
});
In my .env file i've mentioned this,
CUSTOM_ENV=.env.example
Now i in default env.example i put this
USE_SSL="true" // This will return true
USE_SSL=true // This will return 1
I just found that .ini and .env follows the same values, so i parsed .env file as .ini file,
Give this a try, i've never done this thing before, please concern with other developers before running this into production server
In my PHP Laravel 5.3 app I have my config settings in my .env file with the
APP_ENV=local which can be changed to APP_ENV=production when my app is in production/live mode.
In that .env file I also have a MAIL_DRIVER=preview setting which gets pulled into my config/mail.php config file with env('MAIL_DRIVER', 'smtp') like this:
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
]
So now my question is, when I change my .env setting APP_ENV=local into APP_ENV=production
How can I make it load a different env('MAIL_DRIVER') setting based on that env('APP_ENV') setting?
is there a way to load different .env files for each environment or different config files or how do you handle this in Laravel 5.3.
I remember in older versions of Laravel you simply created a new folder in the config folder for each environment but the whole config system is different from those older versions.
With Laravel 5, you have a different copy of your .env file in each environment.
This file is NOT committed into your repository. Rather, your .env.example file is, and that is what you make a copy of and name as .env in the environment.
In previous versions of Laravel (i.e. <= 4) you could have separate environment files in the same checked out copy of the project and switch between environments, but that doesn't actually make much sense.
Keep your .env.example file up to date with all the options you will need in your app, and initialize them to empty values. When you deploy to a new environment, you copy it as a new file, which keeps you from accidentally committing credentials to your repo and keeps things simple:
cp .env.example .env
Then edit the file and set the values to be appropriate in that specific environment. For example, instead of using test API keys, you may use the production keys for some service. Editing, for example:
sudo vim .env # If you like VIM
or
sudo nano .env # If you like NANO
An exception to what I just said above is with testing. Per the documentation:
You may also create a .env.testing file. This file will override values from the .env file when running PHPUnit tests or executing Artisan commands with the --env=testing option.
In that case though, having your .env.testing file in your repo is most likely acceptable assuming it doesn't contain any sensitive production values, which it probably shouldn't anyway.
In my .env file of a laravel 5.1 project i have set the APP_ENV to local, But when i run the test from the terminal the with
vendor/bin/phpunit
the debug and die on
dd(env(APP_ENV));
gives me "testing".
I Have dont a good research on this, tried using the following ways -
trying to set the APP_ENV=local pipelining vendor/bin/phpunit form the cli.
Trying to add env variable in the phpunit.xml file<env name="APP_ENV" value="local" override="true"> (dosent seem to override though)
adding a .env.testing file and setting the APP_ENV=local
in the testCase.php file where the application autoloads $app->loadEnvironmentFrom('.env.testing');
none of the above methods give me the expected result rather everytime i run the test give APP_ENV as "testing".
Not able to trace where is phpunit setting this variable from.
Pls help out!
In vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php search for putenv('APP_ENV=testing'); try to change this to local.
This should work for you, though it is not advisable.
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,
I'm trying to set up an existing site that was built using Laravel 4 on my server. I've gotten stuck at an error: Driver [file] not supported. It's throwing the error from Illuminate/Support/Manager.php.
I've tried using boilerplate Laravel files for the Manager.php file, as well as the SessionManager.php file, but it still won't work. I've also tried to figure out if file is registered as a driver, but when I try to insert the code for it, I get lost because of undeclared functions.
When I try to change the default session driver in app/config/session to anything else, it just throws other errors at me. Yet this is the same way the site was originally set up on its own server, so I don't understand why it isn't working. Can anyone help me out?
I was stuck in same problem, solved it. After changing any configuration config cache must be cleared using php artisan config:cache. Hope it helps.
What is your php version?
Try to clean the session dir
app/storage/sessions
then try to clean autoload file
cd [YOUR LARAVEL ROOT DIR]
composer dump-autoload
and update composer package to be sure vendor folder is ok
cd [YOUR LARAVEL ROOT DIR]
composer update