Support the ongoing development of Laravel.io →
Configuration
Last updated 2 years ago.
0
$env = $app->detectEnvironment(function()
{
    return getenv('APP_ENV') ?: 'local';
});

If APP_ENV variable exists, use that, if not, use 'local'

Of course you have to set the APP_ENV in Forge.

Last updated 2 years ago.
0

pogachar said: Of course you have to set the APP_ENV in Forge.

Well still not working with Forge. These are in my nginx config script


fastcgi_param APP_ENV "production";
fastcgi_param ENV "production";

forge@Fitness:~/default$ php artisan queue:work

[PDOException]
SQLSTATE[HY000] [2002] Connection refused

Also

forge@Fitness:~/default$ php artisan queue:work --env=production

[PDOException]
SQLSTATE[HY000] [2002] Connection refused

Last updated 2 years ago.
0

Anyone?

Last updated 2 years ago.
0

I am struggling with this issue too. It was working with setting the --env before, but not anymore.

Could you check what "php artisan env" gives you?

I get "local" even I set those in ngix.

fastcgi_param ENV "production"; fastcgi_param LARA_ENV "production";

here is my start.php

$env = $app->detectEnvironment(function() {

if (getenv('LARA_ENV')) {
    return getenv('LARA_ENV');
} else {
    return 'local'; // Or whatever your default is
}

});

Last updated 2 years ago.
0

I get production but still connection refused.

Last updated 2 years ago.
0

I wonder why no one knows the answer to this basic question!

Last updated 2 years ago.
0

Environment variables set in nginx won't work on command line. Use the --env=whatever artisan option.

Last updated 2 years ago.
0

valorin said:

Environment variables set in nginx won't work on command line. Use the --env=whatever artisan option.

I am using Forge's queue workers screenshot. There is no place to use --env=whatever!

Also look at post number 1

forge@Fitness:~/default$ php artisan queue:work --env=production

[PDOException] SQLSTATE[HY000] [2002] Connection refused

Last updated 2 years ago.
0

Jesus someone answer this it's been a week!

Last updated 2 years ago.
0

No one is going to bother helping you if you are rude and offensive.

"Connection refused" means your database credentials are wrong. Check your config and credentials are valid...

Last updated 2 years ago.
0

valorin said:

No one is going to bother helping you if you are rude and offensive.

"Connection refused" means your database credentials are wrong. Check your config and credentials are valid...

valorin, who's been rude bro?

Database credentials are set in Froge. They should be right since the website is working, no?

Peace, love and cuddles

Last updated 2 years ago.
0

I don't have a Forge account to check, but is it possible it's using Environment Variables to set the db credentials maybe?

Worst case scenario, delete the VM, and re-create it from scratch. Something might've gone weird during the set up process.

Last updated 2 years ago.
0

valorin said:

I don't have a Forge account to check, but is it possible it's using Environment Variables to set the db credentials maybe?

Worst case scenario, delete the VM, and re-create it from scratch. Something might've gone weird during the set up process.

Hey;

Forge allows you to set ENV variables. But apparently they are not the ones that Artisan uses.

Not sure why there are no docs on this!

Last updated 2 years ago.
0

Hey @behnampmdg3 ran into the same issue and found Matt Stauers post, he says:

However, based on some of my experiences with queues and other aspects of Forge, I'd still highly recommend you use the associative array form of environment detection rather than using a Closure

Basically with Forge you need to be more explicit with your environment. Instead of using an environment var to detect, you'll want to use your production server hostname:

$env = $app->detectEnvironment(array(
    'production' => array('your-server-hostname'),
    'local'      => array('homestead', '.local')
));

http://mattstauffer.co/blog/laravel-forge-using-environment-variables-for-environment-detection

Last updated 10 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.