i download from https://github.com/luciddreamz/laravel laravel for openshift
then upload over my repository over github . this code for connect to database not work.
the problem is that load variable from .env
file that locate in root of project
for solve this problem change.env
# local environment only
# for production, see .openshift/.env
APP_ENV=APPLICATION_ENV
APP_DEBUG=true
APP_URL=OPENSHIFT_APP_DNS
APP_KEY=OPENSHIFT_SECRET_TOKEN
DB_DRIVER=mysql
DB_HOST=OPENSHIFT_MYSQL_DB_HOST
DB_PORT=OPENSHIFT_MYSQL_DB_PORT
DB_DATABASE=OPENSHIFT_APP_NAME
DB_USERNAME=OPENSHIFT_MYSQL_DB_USERNAME
DB_PASSWORD=OPENSHIFT_MYSQL_DB_PASSWORD
CACHE_DRIVER=apc
SESSION_DRIVER=file
my error :SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
createConnection('mysql:host=OPENSHIFT_MYSQL_DB_HOST;port=OPENSHIFT_MYSQL_DB_PORT;dbname=OPENSHIFT_APP_NAME',
array('driver' => 'mysql',
'host' => 'OPENSHIFT_MYSQL_DB_HOST',
'port' => 'OPENSHIFT_MYSQL_DB_PORT',
'database' => 'OPENSHIFT_APP_NAME',
'username' => 'OPENSHIFT_MYSQL_DB_USERNAME',
'password' => 'OPENSHIFT_MYSQL_DB_PASSWORD',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'name' => 'mysql'),
array('0', '2', '0', false, '0')) in MySqlConnector.php line 20
First line of the error message describes the error type: "PDOException". The next line displays
PDO::errorInfo
, i.e:The stack trace you attached, line 3, reveals that you did not specify the database connection parameters in the configuration file. The error show up when you test on local, right? You need to update
/.env
with the actual database connection parameters.I was having the same problem and everyone was talking about this is related to DNS configuration, which make sense, since your container maybe isn't knowing how to resolve the name of the domain where your database is.
I guess your can configure that at the moment you start your container, but I think it's better to config this once and for all.
I'm using Windows 10 and in this case docker's gui give us some facilities.
Just right click on docker's icon in the tray bar and select "Settings" item.
Then, on the Docker's window, select the "Network" section and change the DNS option from "Automatic" to "Fixed" and hit "Apply". Docker will restart itself after that. I putted the Google's DNS (8.8.8.8) and it worked fine to me.
Hope it helps.
Just as on FYI to others suddenly experiencing this on an otherwise (previously) working Laravel installation:
My Laravel environment is on a Ubuntu VirtualBox hosted on a Win-10 laptop.
I used my phone to share Internet via USB and suddenly started experiencing this issue. I changed to using the phone as wireless hotspot and the issue went away. This is a nameserver/networking issue and is not specific to Laravel or MySQL.
It looks like you did not add a MySQL database to your application, OR you added it after you installed laravel. In that case, you need to stop & start (not restart) your application so that it will pick up your environment variables. (rhc app stop , rhc app start ). If you did not add a database yet, you will need to add one of the mysql cartridges, and then stop & start your application using the previously shown commands.
Check your
DB_HOST
on your.env
filephp artisan config:clear
it will help you, clear cached configIn my case, everything was set up correctly, but my
Docker
infrastructure needed more RAM. I'm using Docker for Mac, where default RAM was around 1 GB, and as MySQL uses around 1.5Gb of RAM ( and probably was crashing ??? ), changing the Docker RAM utilization level to 3-4 Gb solved the issue.