简体   繁体   中英

Connect website to MySQL database in cPanel

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

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.

如果您使用托管文件的同一cpanel或同一服务器的 mysql,则可以在主机名中使用localhost ,这将为您工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM