Laravel 5.2가 env 파일을 읽지 않음
Laravel 5.2로 업그레이드 한 후 .env
파일 값이 읽혀지지 않습니다. 업그레이드 지침을 따랐습니다 . auth.php를 제외하고는 내 구성 파일이 변경되지 않았습니다. 이전 버전 5.1.19에서는 모두 잘 작동했습니다.
.env
다음과 같은 값을 포함합니다.
DB_DATABASE=mydb
DB_USERNAME=myuser
config/database.php
포함
'mysql' => [
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
]
이 오류가 발생합니다.
PDOException: SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO)
분명히 내 환경 구성을 가져 오지 않습니다. 이것은 bugsnag와 같은 타사를 포함하여 내 구성 파일의 모든 단일 파일에 영향을 미칩니다.
나는 또한 시도했다
php artisan config:clear
php artisan cache:clear
최신 정보
견딜 수 없는 php artisan tinker
>>> env('DB_DATABASE')
=> null
>>> getenv('DB_DATABASE')
=> false
>>> config('database.connections.mysql.database')
=> "forge"
>>> dd($_ENV)
[]
Laravel 5.2의 새 복사본을 설치해 보았습니다. 기본적으로 내 app
폴더 에만 복사했습니다 . 추가 작곡가 패키지는 포함되어 있지 않습니다. 여전히 같은 문제가 있습니다. 잘 작동하는 동일한 서버에 다른 Laravel 5.2 프로젝트가 있습니다.
공식 Laravel 5.2 업그레이드 노트에서 :
config:cache
배포 중에 명령을 사용하는 경우 응용 프로그램의 다른 곳이 아닌 구성 파일 내 에서만 함수를 호출하는지 확인 해야합니다env
.
env
애플리케이션 내에서 호출하는 경우 적절한 구성 값을 구성 파일에 추가하고env
대신 해당 위치env
에서config
호출 하여 호출을 호출 로 변환 할 수 있도록 하는 것이 좋습니다 .
참조 : https://laravel.com/docs/5.2/upgrade#upgrade-5.2.0
귀하의 경우 .env
변수가 공백을 포함, 당신은 큰 따옴표를 포장해야합니다. 예를 들면 :
SITE_NAME="My website"
테스트하기 전에 캐시를 지우는 것을 잊지 마십시오.
php artisan config:cache
php artisan config:clear
와. 맙소사. 따옴표로 묶지 않고 공백이있는 env 값이 있기 때문입니다.
이
SITE_NAME=My website
이것으로 변경
SITE_NAME="My website"
고쳤다. 나는 이것이 Laravel 5.2 에서 vlucas / phpdotenv 를 1.1.1에서 2.1.0으로 업그레이드하는 것과 관련 이 있다고 생각합니다.
비슷한 문제가 있었고 및 명령을 config/services.php
사용하여 해결했습니다 .config clear
optimize
php artisan config:clear
php artisan optimize
이것을 실행하십시오 :
php artisan config:clear
php artisan cache:clear
그때
php artisan config:cache
나를 위해 다음 순서로 작동했습니다.
php artisan config:cache
php artisan config:clear
php artisan cache:clear
그리고 나는 운없이 모든 나머지를 시도했습니다.
명령 php artisan config:cache
을 실행하면 모든 env
변수 env()
가 지워지고 null 값이 제공됩니다. 다음 명령을 실행하고 env()
다시 모든 env
변수 를 잡기 시작 합니다.
php artisan config:clear
나는 지역 환경에서 동일한 문제가 있었으며
- php artisan config : clear
- PHP 장인 설정 : 캐시
- and then cancelling php artisan serve command, and restart again.
I missed this in the upgrade instructions:
Add an env configuration option to your
app.php
configuration file that looks like the following:'env' => env('APP_ENV', 'production')
Adding this line got the local .env
file to be read in correctly.
The simplicity is the power:
php artisan config:cache
You will receive:
Configuration cache cleared!
Configuration cached successfully!
For me the following worked
- php artisan config:cache
- php artisan config:clear
- php artisan cache:clear
delete cache using:
php artisan config:clear
php artisan config:cache
Same thing happens when :port is in your local .env
again the double quotes does the trick
APP_URL="http://localhost:8000"
and then
php artisan config:clear
Also additional to what @andrewtweber suggested make sure that you don't have spaces between the KEY= and the value unless it is between quotes
.env file e.g.:
...
SITE_NAME= My website
MAIL_PORT= 587
MAIL_FROM_NAME= websitename
...
to:
...
SITE_NAME="My website"
MAIL_PORT=587
MAIL_FROM_NAME=websitename
...
I ran into this same problem on my local, and I have tried all the answers here but to no avail. Only this worked for me, php artisan config:clear
and restart server
. Works like a charm!
I solved this problem generating a new key using the command: php artisan key:generate
if you did call config:cache during local development, you can undo this by deleting the bootstrap/cache/config.php file. and this is work for me.
if you did call config:cache during local development, you can undo this by deleting the bootstrap/cache/config.php file. and this is work for me.
@Payal Pandav has given the comment above.
I want to tell a simple workaround. Just edit the config.php file in the bootstrap/cache/ folder. And change the credentials. This worked for me. Please don't delete this file since this may contain other crucial data in the production environment.
In my case laravel 5.7 env('APP_URL')
not work but config('app.url')
works. If I add new variable to env
and to config - it not works - but after php artisan config:cache
it start works.
If you run this php artisan config:cache
command on console then it will store all the .env file contents in cache, after this command if you append any contents into .env file the it will not be not be available until you run php artisan config:clear
command
I experienced this. Reason was that apache(user www-data) could not read .env due to file permissions. So i changed the file permissions to ensure that the server (apache) had read permissions to the file. Just that and boom, it was all working now!
I made the mistake by doing dd/die/dump in the index.php
file. This causes the system to not regenerate the configs.
Just do dump in view files will do. The changes to .env
file update instantly.
I face the same problem much time during larval development. some times env stop working and not return any value. that reason may be different that depends on your situation. but in my case a few days ago I just run
PHP artisan::config:clear
so be careful use of this command. because it will wipe all config data form its cache. so after that, it will not return any value. So in this situation, you need to use this first if you have run PHP artisan config:: clear command.
php artisan config:cache // it will cache all data
php artisan config:clear
Configuration cache cleared!
참고URL : https://stackoverflow.com/questions/34420761/laravel-5-2-not-reading-env-file
'Development Tip' 카테고리의 다른 글
iOS 7에서 탭 막대 색조 색상 변경 (0) | 2020.10.17 |
---|---|
Android에서 애플리케이션을 닫고 홈 화면을 시작합니다. (0) | 2020.10.17 |
Linq to Entity에서 최대 ID를 얻으려면 어떻게해야합니까? (0) | 2020.10.17 |
APK META-INF / license.txt에 복사 된 Android Gradle 중복 파일 (0) | 2020.10.17 |
IEnumerable을 지원하는 컬렉션을 반복하는 방법은 무엇입니까? (0) | 2020.10.17 |