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
Error : Failed to connect to server: php_network_getaddresses: getaddrinfo failed. This error can occur due to two reasons. One, there might me an issue with your DNS settings and second, PHP may not be able to get the network addresses for a given host/domain name.
That usually means your DNS resolution is not working correctly. PHP cannot get the ip-address for hostnames used in the Memcache functions. Your options. Check/fix that DNS-lookups can be done correctly. Change your code to use ip-addresses instead of hostnames.
First line of the error message describes the error type: "PDOException". The next line displays PDO::errorInfo
, i.e:
- SQLSTATE error code (a five characters alphanumeric identifier defined in the ANSI SQL standard).
- Driver-specific error code.
- Driver-specific error message.
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.
Check your DB_HOST
on your .env
file
DB_HOST=http://localhost/ --> DB_HOST=localhost
php artisan config:clear
it will help you, clear cached config
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With