I initially deployed my Laravel app with APP_DEBUG set to true, but now we're in production I don't want it to whoops! every time there's an error.
I've changed the contents of our EB .config file so that APP_DEBUG: false and I can see the change in Elastic Beanstalk's environment properties:
But Laravel itself is still dumping everything to the screen when there's an error.
I've tried ssh-ing into our server and running php artisan config:clear to see if it was that, but it still didn't work.
I don't understand why Laravel isn't respecting the updated configuration on deployment. Can anyone explain the logic here?
Update: I updated the security settings on the instance and noticed that it was giving our custom error screen. Can anyone explain what happened? Was restarting the server after running php artisan config:clear what did it?
I had issues like this before where I changed something in the console's environment properties which did not correspont with what I got using tinker. You can find the env file on your instance here:
/opt/elasticbeanstalk/deployment/env
if you open the file you see that variables set in .env are not quoted so if you have a password with for example a hashtag or a name with spaces it can result in unintended problems.
I would suggest to stop using environment variables via .yaml config files and start deploying your .env to the elastic beanstalk S3 bucket and fetching it on deployment. This will result in you having more control over the content of the file.
Example of this can be found here:
https://github.com/rennokki/laravel-aws-eb/blob/master/.ebextensions/00_copy_env_file.config
Related
I have deployed a Laravel app via EBS but without the .env file.
Instead, i have entered all of the variables in the EBS configuration > Software tab.
I did a test just so I can check if they are properly read so I set APP_ENV=stage but when I ssh to the ec2 insteance created by EBS and I run the php artisan env command it shows production instead of stage which means the variables are not injected properly.
I tried rebuilding the environment several times but no clue. Anyone can help?
When you use EBS configuration > Software tab to define the environment variables, they take effect when the serve a request. they dont update the .env file.
when using CLI artisan commands, it will only follow the .env variables
I have APP_URL env variable set to domainname.com and I have url set to the same domain in config file as well. route('route.name') in artisan tinker returns the proper domain. yet when used in the applicaiton code, it returns localhost. Any thoughts from you would be appreciated.
Edit: My environment is Github codespaces
Try running php artisan optimize:clear command to clear cache,
routes etc all in one go.
If you have separate frontend then change it there as well to hit the
right backend with your provided domain name.
Restart your docker containers if you are using Docker.
I am using a form from front end to change my .env file variable values, after changing the values, changes are being saved in my env file, but its not reflecting on my laravel application, after restarting my server its reflecting on my website, but i cant do this if its in live server, I tried PHP artisan config:clear and PHP artisan cache:clear but none of its working.
Can anyone please tell me how to do this without restarting server.
I am trying to change these values in .env
HTTP_HOST=http://
SFTP_HOST=10.10.10.64
So i'm using Laravel with Kubernetes and everything works great, except for the fact that when i access the website, it takes too much to load. I troubleshot it and i found out that some CSS and JS files are loaded using the private ip (the one that starts with 10: 10.244.xx.xx)
I have no idea what's going on. Is it some kind of NGINX setting that messes it up? I am using the default NGINX Ingress for the cluster and i repeat: everything works great, except with this particular thing.
Edit: It seems like the route:cache command messes everything. I don't know why.
Never use secure_asset() over asset() unless you know what it can do.
I had to replace all my secure_asset() with asset()
make sure you got the domain right in .env file, in the root folder of your Application run:
sudo nano .env
find APP_URL parameter and configure it right, then run:
php artisan config:cache
So, i found it. It seems like i had to run route:cache between config:cache and view:cache on each pod deployment.
I'm trying to deploy to production my app that is working well in local.
Thing is when try:
dd(getenv('APP_ENV'));
it returns "false"
but when I connect ssh and type:
php artisan env
I get
production
Any idea why it stopped working???
For the record, In production, my deploy script execute 3 commands:
composer dump-autoload -o
php artisan route:cache
php artisan config:cache
I mention it because it is possibly the only software config that is different.
EDIT: I identify that the problematic command is:
php artisan config:cache
If if do:
php artisan config:clear
problem is solved.
Tx!
When using a cached config the .env file is not used anymore so getenv is useless, because the config is loaded from:
bootstrap/cache/config.php
Instead you can get the current environment from the loaded application configuration like so:
config('app.env');
Or directly using the app helper function:
app('env');
As a third option you can always use the environment method to get the current environment:
app()->environment(); // or App::environment()
Laravel uses the dotenv library internally to load the configuration keys from the .env file and add them to the environment variables using putenv, but when you cache your configuration that loading part is not done anymore because Laravel detects that there is a cache file present and uses that instead, so those keys from .env are not loaded into the environment, this not accessible via getenv.
And because configuration values from the .env file are only cached when they are used in an actual configuration file from the config directory, you need to create a configuration option for them to be cached and accessible when you're using the cache.
So if you want to have a BASE_URL key in your .env file with this value:
BASE_URL=http://domain.com/
If you want to be able to access its value when the configuration is cached, you need to use it in a configuration file. For example, you can add it to your config/app.php file like so:
'base_url' => env('BASE_URL')
Then you can access even when the configuration iit using:
config('app.base_url')
You can read more about accessing configuration values in the Laravel Documentation.