Change Laravel Mysql Database Connection On Shared Hosting Cpanel - FreeCodeBlog
Last updated: Dec 16, 2021
Want to change local to cpanel MySQL database connection in laravel on cpanel? Yes. Well, You need to change laravel MySQL database connection on shared hosting cpanel after deploy laravel project on cpanel. So I hope you deploy laravel in cpanel to change laravel mysql database in cpanel. You can easily use Cpanel MySQL database information into laravel to change laravel database connection. Wait a minute, Do you have any created database cpanel? Why created cpanel database? Actually you must need a created database to connect cpanel MySQL database in laravel. Don't worry I will also help you to create a database from cpanel to cennect MySQL database in laravel project.
1. Create Database On Cpanel.
First you need to create a new database in the shared hosting cpanel to change the Laravel MySQL database connection. I have already created a MySQL database in cpanel to change the Laravel database connection to the shared hosting cpanel. So sorry in this tutorial I can't explain to you how to create MySQL database in cpanel. If you have not created a database or do not know how to create a new database in cpanel then read how to create mysql database on shared hosting cpanel tutorial.
2. Copy Database Information.
After creating a new MySQL database in the shared hosting cPanel you need to copy the MySQL database information created to change the Laravel MySQL database connection. don't forget to copy database, username, password for laravel MySQL database connection. If you have a created database, be sure to copy that information.
3. Deploy Laravel To Shared Hosting Cpanel.
Before changing the Laravel MySQL database connection on shared hosting cpanel you need to install laravel in cpanel. You really can't change laravel database on cpanel without deploy laravel on cpanel. So I hope you understand that you must deploy laravel on cpanel before changing laravel MySQL database from cpanel. I have already created a lot of tutorials on installing Laravel on Shared Hosting Cpanel. You can read deploy laravel project to shared hosting cpanel using zip file tutorial.
4. Change Laravel Database Connection.
Did you upload laravel to cpanel? Yes. After uploading laravel to cpanel you will see an env file in the laravel project folder. If you do not see an env file in the laravel project folder then don't forget to copy laravel .env.example file to .env file. Now open the laravel env file in the cpanel editor to edit the laravel env file to change the laravel MySQL database connection. Remember this part is very very important to change laravel MySQL database from cpanel. So don't forget to read below laravel database connection information slowly and carefully.
Have you created a cpanel database account to connect to laravel database? Yes. Did you copy the newly created cPanel database? Yes. Good, You need to open cpanel phpmyadmin page. The cpanel phpmyadmin page is not required to connect laravel databases to cpanel If you have already copied data from cpanel database. Open cpanel phpmyadmin page will help you to get the host, port information of the database.
DB_CONNECTION: In this tutorial I will use MySQL database connection. you can use others database connection for your laravel project. No need to change database connection in laravel env file because new laravel used MySQL database connection.
DB_HOST: In this tutorial I will use MySQL database connection so no need to change database host in laravel env file.
DB_PORT: For MySQL database connection no need to change database port in laravel env file.
DB_DATABASE: You need to change database name in laravel env file. so use your created database name in db database.
DB_USERNAME: You need to change database username in laravel env file. so use your created database username in db username.
DB_PASSWORD: Also you need to change database password in laravel env file. so use your created database user password in db password.
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=cpanel-database-name DB_USERNAME=cpanel-user-name DB_PASSWORD=cpanel-user-password
Did you use cpanel database correctly in laravel .env file? Yes. Okay good, But you should check all laravel database information again from cpanel. Finally click on the save button to change laravel MySQL database connection.
5. Import Database Tables.
I hope you did change laravel MySQL database on cpanel correctly. I think now you need to import laravel database on cpanel MySQL database. After changing laravel MySQL database connection on shared hosting cpanel you may want to import local database tables on cpanel database. So you can read how to import MySQL database table on cpanel tutorial to import laravel MySQL database on cpanel.
Okay so this is for today. See you again next tutorials. Thanks
In fact, every Laravel user authentication uses Laravel hash passwords by default. Want to know how a hash password works in Laravel? Yes! Okay In... Read More
Create singular to plural converter online tool in laravel to convert singular word "car, student, teacher" to plural word "cars, students, teacher... Read More
Want to create cpanel ssh key? Yes. You can create public and private ssh key on cpanel. The public and private key are similar to a puzzle. They a... Read More
Do you have any websites on the live server that need redirection? Yes. Did you find a duplicate version of the website? Yes. Then you need to use... Read More
Want to make a user email verification in laravel using ui, jetstream, breeze user authentication package? Yes! Okay then you must need to read thi... Read More