skip to Main Content

I have uploaded my website in cPanel but still don’t know how to change my .env file or database.php to connect my site to the database. The connection works on localhost without any error but what do I need to change in these file when I move my project from localhost to an online host?

I created my database in cPanel -> phpmyadmin and created a user which has a password, my user is a Privileged Users for this database.

How can I connect my project on the host with my database?

My .env file looks as follows:

APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://domain_name

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=databasename
DB_USERNAME=username
DB_PASSWORD=password

2

Answers


  1. If you are using mysql of same cpanel or same server where you have hosted the files, you can use localhost in host name, this will work for you.

    Login or Signup to reply.
  2. It seems like you have the correct .env values (please check this once more to be 100% sure).
    If it is the case that you have the correct .env values your problem is probably with caching.

    Laravel caches config values using php artisan config:cache whenever you make a change to your .env file you will need to recreate your config cache.
    If you cannot run commands on your server you can delete the bootstrap/cache/config.php file to remove the config cache.

    On another note, if your webserver and sqlserver are on the same physical server you can use localhost as the correct host.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search