For some reason, my production laravel app thinks that it is in the local environment.
/var/www/appname/.env.php
<?php
return
[
'APP_ENV' => 'production',
'DB_HOST' => 'HIDDEN',
'DB_NAME' => 'HIDDEN',
'DB_PASSWORD' => 'HIDDEN'
];
/var/www/appname/bootstrap/start.php
$env = $app->detectEnvironment(function()
{
return getenv('APP_ENV') ?: 'local';
});
/var/www/appname/app/config/database.php
...
...
'mysql' => array(
'driver' => 'mysql',
'host' => getenv('DB_HOST'),
'database' => getenv('DB_NAME'),
'username' => getenv('DB_USERNAME'),
'password' => getenv('DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => 'lar_',
),
...
...
sudo php artisan env
(via SSH)
`Current application environment: local
php artisan tinker
then getenv('DB_NAME')
$ php artisan tinker
[1] > getenv('DB_NAME');
// false
So either my environment variables are not being set, or Laravel is not recognising my .env.php
file for the production environment.
Update
With some help from Anultro on IRC, it appears that .env.php is not loaded yet. As such APP_ENV must be set before laravel tries to detect environments. This makes sense, because Laravel needs to know what environment is running before determining whether to use .env.php
or .env.local.php
.
Having said this, .env.php
should still be used to store db credentials and secret keys etc... But I am still having a problem because the app is still returning false when I try to run getenv('DB_NAME')
Any suggestions?
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:
You can use Azure Pipelines to build your Laravel application. Here is an example in how to implement Azure Pipelines with App Service Linux. Create a new DevOps project then go to Pipelinesand select Create Pipeline. Select your code repository. Select PHP as Linux Web App on Azuretemplate. Select the web app where you will deploy.
PHP 7.x on Azure App Service Linux use Apache as the Web Server. Since Laravel uses /publicas the site root we need to use an .htaccessto rewrite these requests accordingly. Create an .htaccessin the root of your repo with the following:
I can confirm once again that piping yes cancels the command, although there's also an -n flag (which stands for 'no interaction') and using that prevents Artisan from asking for confirmation. Also, I'm using Laravel 5+ for this particular application.
For all who want to know... to solve this issue, I just edited my httpd.conf file on the production server as follows:
SetEnv APP_ENV production
Now laravel knows that the app is in production.
If you are using nginx which I have now migrated my site to add the following where you pass scripts to the FCGI server in the active sites-available /etc/nginx/sites-available/{sitename}
:
fastcgi_param APP_ENV production;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With