1

I have just uploaded a Laravel project to a web server but it cannot be connected to the database. I have imported the database to phpmyadmin, and have also set the .env and config/database.php file. When I run the page, it still shows me my localhost database settings (username, password, database etc).

This is my .env file

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:qvuzPrZW3awGcn8etObsyAT7SaKRfgr6AHfpnUPfygE=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://findajob.af/

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=database_name_on_server
DB_USERNAME=username_on_server
DB_PASSWORD=password_on_server

This is my config/database.php file

'mysql' => [
    'driver' => 'mysql',
    'host' => env('DB_HOST', 'localhost'),
    'port' => env('DB_PORT', '3306'),
    'database' => env('DB_DATABASE', 'database_name_on_server'),
    'username' => env('DB_USERNAME', 'username_on_server'),
    'password' => env('DB_PASSWORD', 'password_on_server'),
    'unix_socket' => env('DB_SOCKET', ''),
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    'prefix' => '',
    'strict' => true,
    'engine' => null,
],

When I load the page, it gives me following errors:

QueryException in Connection.php line 647:
SQLSTATE[HY000] [2002] Connection refused (SQL: )

And the second error message is

PDOException in Connector.php line 68:
SQLSTATE[HY000] [2002] Connection refused

    1. in Connector.php line 68
    2. at PDO->__construct('mysql:host=127.0.0.1;port=3306;dbname=databasename_on_localhost', 'localhost_username', 'localhost_password', array(0, 2, 0, false, false)) in Connector.php line 68
Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
Ajmal Razeel
  • 1,663
  • 7
  • 27
  • 51
  • Database and project are on the same server? – Mirek Kowieski Jul 28 '17 at 22:02
  • Yes they are on the same server. I purchased the hosting from easyname.com – Ajmal Razeel Jul 28 '17 at 22:03
  • So you don't need use that host - e73573-mysql.services.easyname.eu. Try change it to localhost. – Mirek Kowieski Jul 28 '17 at 22:07
  • I did change it to localhost but still doesn't work. If you see the second error message, it is showing me the database name, username and password which I set on my localhost. I don't know why. – Ajmal Razeel Jul 28 '17 at 22:10
  • sometimes `127.0.0.1` works better than localhost, altough they should be the same thing. – online Thomas Jul 28 '17 at 22:14
  • Ok, I think where is the problem. Try clear your cache on the server. `php artisan key:generate / php artisan cache:clear / php artisan config:clear` in Project directory. – Mirek Kowieski Jul 28 '17 at 22:14
  • U mean clear cache on localhost or online server? Can I do on online server?? I mean in Cpanel. I don't see any such option. – Ajmal Razeel Jul 28 '17 at 22:16
  • I mean online server. You need to connect with your server via ssh and run that 3 commands in project directory. – Mirek Kowieski Jul 28 '17 at 22:21
  • I am new to these things. I have enabled the SSH on my Cpanel but now I don't know how to run those commands and where? I am using Windows OS and the server is I think Linux – Ajmal Razeel Jul 28 '17 at 22:33
  • You can use `puTTy` to connect with your server via ssh. You only need to configure your server connection in putty. Read this [Tutorial](https://mediatemple.net/community/products/dv/204404604/using-ssh-in-putty-) – Mirek Kowieski Jul 28 '17 at 22:38

1 Answers1

2

I think you can try this :

DB_HOST=hostname_from_server
DB_PORT=3306
DB_DATABASE=database_name_on_server
DB_USERNAME=username_on_server
DB_PASSWORD=password_on_server

After clear the cache on live like:

php artisan config:cache
php artisan cache:clear

Hope this work for you !!!

Hope this work for you !!!

AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57