.env can't get read from inside a job - php

I have a Laravel project (v8.12) running on PHP 7.4.3 in a dedicated AWS instance with Ubuntu 20.04. When I try to read an environment variable from inside a job, the value is always null, but it works elsewhere. I tried to switch from supervisord to sync driver, still couldn't reach it.

Your problem could be from cache .
you can below commands for remove cache .
php artisan cache:clear
php artisan config:clear
php artisan view:clear

Run below commands
composer dump-autoload
php artisan clear-compiled
php artisan optimize
php artisan route:clear
php artisan view:clear
php artisan cache:clear
php artisan config:cache
php artisan config:clear
For Example
In your env file
SITE_NAME="My website"
Get your env variable like
$data = env('SITE_NAME');
echo $data;

Related

Can i run multiple command with artisan serve laravel?

Is it possible to run some other arrtisan command when we run php artisan serve . at the same time ? Is there any way to do that?
You can run multiple commands separated by a semi-colon.
For example:
php artisan view:clear; php artisan route:clear; php artisan cache:clear; php artisan config:clear
Would that help?
You need to setup supervisor on the server. It will start the queue:work for you. It can also run multiple executions of same commands.

Laravel cache:clear broke application

After executing
php artisan config:cache
php artisan cache:clear
The application doesn't work anymore, it seems to be something about the session. Stopped create the session files.
The error returning is:
file_put_contents(path/to/file/storage/framework/sessions/PullrofroFB2gGJNA8v7Zo7OcdTzno4ZDTVmfBBi):
failed to open stream:
No such file or directory
The config:cache and the cache:clear don't refer to the same cache.
If you run php artisan config:cache --help shows the following description:
Description: Create a cache file for faster configuration loading
Running php artisan cache:clear --help shows the following description:
Description: Flush the application cache
And there's also another command: config:clear which
Description: Remove the configuration cache file
So... cache:clear only clears the application cache while config:clear will remove the cache file created by config:cache. Also you may try running config:cache whith admin privileges.

Lumen 5.6 php artisan migrate --env=testing not working

Lumen Version: 5.6
PHP Version: 7.2
Database Driver & Version: SQLite 3
Steps To Reproduce:
cp .env .env.testing
SetAPP_ENV=testing
Run php artisan migrate --env=testing
Problem
Old env file configuration is executing.
First:
php artisan cache:clear
php artisan config:cache
You need to specify the environment before the migrate command.
php artisan --env=testing migrate
I found the solution myself. This feature is not there in this lumen version.
PR LINK FIX

Laravel doesn't read config in .env file

Laravel doesn't read config in env, so env('APP_KEY') always returns NULL. I also use:
php artisan config:clear
and
php artisan config:cache
but it doesn't have any effect. Do you have any solutions to fix? First time, I could fix by using 2 command above, but now I can't.
Try:
php artisan config:clear
then:
php artisan cache:clear
and make sure that you have permissions to run these commands, or you can simply run them with sudo.

How to migrate table in october cms?

When I migrate the table, the php artisan migrate does not work.
Use composer.
Navigate to the root directory of the project. Run,
php artisan october:up
if you want to roalback you can run
php artisan october:down
Be sure to use composer in the project directory
php artisan migrate:refresh php artisan migrate:rollback php artisan migrate --force are some cmd's you could try. I don't know if this helps you otherwise please explain your question a bit more.
Go to the root directory of your project in command prompt and run these commands
To reset the current migrations if there are some php artisan migrate:reset
then run php artisan migrate

Categories