I am developing an application using anuglarJs on client side and Lumen in server side for REST API's. My .env configuration given below,
APP_ENV=local
APP_DEBUG=TRUE
APP_KEY=XrPbyRlU5p0szSw5MrAQWwWim8C0MXjT
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=kainfo
DB_USERNAME=root
DB_PASSWORD=
CACHE_DRIVER=file
SESSION_DRIVER=file
And enabled Dotenv::load(__DIR__.'/../'); in bootstrap/app.php
My problem is,sometimes Lumen throws 500 exception and working well on next refresh request.
The Error log is ,
[2015-06-06 07:51:41] lumen.ERROR: exception 'PDOException' with message 'SQLSTATE[HY000] [1044] Access denied for user ''#'localhost' to database 'forge'' in C:\xampp\htdocs\Study\kasrodinfo\web\vendor\illuminate\database\Connectors\Connector.php:47
You need to change the database,username,password in \vendor\laravel\lumen-framework\config\database.php file
Also affected by this, here is what we have found on this issue:
We were using Apache 2.4 with the Event MPM and a thread-safe build of PHP 7. This caused the env() method to not respond reliably - it could give you the right variable at one point in the code, then just a few rows down it would return something else. (Like the default variable which trevorg was experiencing.)
We switched to using the prefork MPM and the problems vanished instantly.
Yes, prefork sucks in terms of speed when compared to another MPM, but it seems there is some issue with the event MPM and environmental variables in Apache, PHP and/or Laravel/Lumen.
Related
I created my first App, using Laravel in the Backend. Everything was running on my localhost and I deployed everything to my Netcup Webhosting Server.
I run composer install successfully, generated the API key by using php artisan key:generate --ansi and set up my .env file. The File looks like:
APP_NAME="App Name"
APP_ENV=prod
APP_KEY=base64_key
APP_DEBUG=false
APP_URL=https://xx.xxxxx.de
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME="db_user"
DB_PASSWORD="db_user_password"
The I want to create all the database tables by using php artisan migrate. I tripple checked the values set in the .env and red a lot of solutions of other posts, but nothing worked. I keep getting the following error:
I already added quotes to DB_User and Pasword in .env file. I restarted the server several times and cleaned the cache.
It looks like some problems with auth on the Netcup Web hosting Server. Can you check list of user with access to db_name? Besides, by screenshoot I guessing that hosting add prefix ("k177581_") for db_name and db_user
Solved the issue:
As #N69S correctly suggested it was related to Netcup. For any other Netcup user the following solution.
Netcup devides its Webhosting and Database. Therefore you need to put you Database IP into your .env file. That can be found in the connection data.
I just updated my Laravel application to 6.0 to use the new tool Vapor.
However, after the deployment process end, I get this error when i access the app using the vanity url :
ErrorException thrown with message
"file_put_contents(/tmp/storage/framework/sessions/cqDlEgxQSwsYKnBGpPjv94Dvzasa0ECmqF1Rl9xV):
failed to open stream: No such file or directory"
Do you have some ideas about the reason of this error ?
Thank you
I faced the same issue while deploying a Laravel app using Vapor.
And solved it by
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=dynamodb
SESSION_LIFETIME=9999
QUEUE_DRIVER=sync
I am running lumen on my backend, and on the frontend I am using AJAX to make requests to the server every 5 seconds. At first the requests run fine, but after about 20 requests I get the following error:
The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.
In my .env file I have this:
APP_ENV=local
APP_DEBUG=true
APP_KEY=1jleJ3gqex79HZ39mP5nWgtX2u1HD8X1
What is causing this to happen and is there anyway to fix it?
One thing I read is that the file is getting locked and it isn't able to read the .env so it throws an error.
I have 2 Laravel applications running on the same server. The server is Apache 2.4 and I have vhosts set up to serve each application on a different domain.
The first application is an API and it's .env file is set up like this:
APP_ENV=production
APP_KEY=YYYYYYYYYYYYYYYYYY
APP_DEBUG=false
APP_LOG_LEVEL=debug
APP_URL=https://notify.mysite.com
APP_DOMAIN=notify.mysite.com
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=notify
DB_USERNAME=YYYYYYYYYYYYYYYYYY
DB_PASSWORD=YYYYYYYYYYYYYYYYYY
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
The second application is a UI that among other things, utilizes the API from the first application. Its .env file is set up like this:
APP_ENV=local
APP_KEY=XXXXXXXXXXXXXX
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=https://asapps.mysite.com
APP_DOMAIN=asapps.mysite.com
APP_VERSION=1
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=asapps
DB_NOTIFY_DATABASE=notify
DB_FLIGHT_DATABASE=flights
DB_USERNAME=XXXXXXXXXXXXXX
DB_PASSWORD=XXXXXXXXXXXXXX
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
I can send messages to my API from my Swagger editor, from Postman, and from other servers and everything works as expected.
My second application by itself also works as expected.
However, if my second application sends a request to the API, the API application throws this error:
exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'asapps.preprocessor_config' doesn't exist'
in C:\notify\vendor\laravel\framework\src\Illuminate\Database\Connection.php:332
WTH?
The database for the API is set to DB_DATABASE=notify and it definitely does properly use that connection when I send messages from other servers. So why the heck is it trying to use the second application's database
connection when I call the API from that app??? Its almost like it's caching the DB connection and trying to keep using that same one.... How do I stop that?
Table 'asapps.preprocessor_config' doesn't exist'
After more digging (read frantic googling), I found the problem and solution here
The bottom line, when site A accepts a request, php loads it's .env variables for the entire length of the http request. During that request, when site A calls site B, since they are on the same server running the same php, php is still using the .env from site A and does not separately load site B's .env file at all.
The author's better explanation:
The .env file with the variables was created so that people would not push their credentials to github repositories and other places where they may share the source.
Now, being environment variables they become system wide for the entire duration of the http request (in this case script execution). The point is that you got a long running script.
To find a definitive solution you could go one of the three ways.
....
'namespace' the ENV variables.
I've looked through a bunch of other threads but can't find a solution. My .env file is set up correctly and I can access the database fine through the php artisan tinker command. However when I spin it up on the browser I get access denied. I've changed the password a few different times to make sure I was putting in the correct username/password but still nothing.
APP_ENV=local
APP_DEBUG=true
APP_KEY=rUzE03agyabewGSbhch7QFKE0jqZqifO5
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=username
DB_PASSWORD=password
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
I have reloaded the virtualbox and even forced provisioned it, ran php config:clear, stop and started the mysql db. tried different users/passwords/dbs, switched localhost to 127.0.0.1, followed the documentation on laravel.com. Nothing has worked.
I'm at a loss...help would be appreciated.
The tutorials were not very clear on this point but basically I had to access mysql on the VM by using "vagrant ssh" and then logging onto mysql through the cli to create the correct user. Also all the migrate commands needed to be executed while logged into the VM through the ssh.
While the artisan commands will add the appropriate "make:' objects in either only the VM cli will allow you to access the correct database. Hopefully this post will save someone a day of sifting through a lot of posts about the .env file.