1

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
8
  • which php framework are you using, depend on that file name and location.Please share framework name. Commented Sep 19, 2018 at 7:59
  • Laravel framework Commented Sep 19, 2018 at 8:24
  • dear please make changes in .env file. it would be hidden. Commented Sep 19, 2018 at 9:00
  • I know where must i change(env or config/database.php), but the problem is how should i change it Commented Sep 19, 2018 at 9:04
  • Did you import the database to the same cPanel server? If so, you can still use localhost as database host. Commented Sep 19, 2018 at 9:15

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you , my problem solved. I have used host IP instead of localhost and this worked.
0

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.

1 Comment

Hello @Niranjan Kapadiya, thank you for your contribution, however as you can see in the question OP already tried to use localhost as the DB_HOST.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.