Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect my Laravel to a external Database

Tags:

php

mysql

laravel

How can i connect my laravel to an extneral Database?

Example: I have a laravel on my local machine which is running on xammp. And i want it to connect to a cloud Server database.

like image 476
HASSANAL AGUAM Avatar asked Oct 27 '25 12:10

HASSANAL AGUAM


1 Answers

Open the .env file and edit it. Just set up correct external DB credentials:

DB_CONNECTION=mysql 
DB_HOST=127.0.0.1         // set external DB_Host 
DB_PORT=3306             // Your Database Port
DB_DATABASE=            // Your Database Name
DB_USERNAME=           // Your Database Username
DB_PASSWORD=          // Your Database Password

DB_USERNAME should be set to root if you do not have a default username in the installation time

If no password is set on the database, just clear it DB_PASSWORD

After .env edit, must be clear cache:

php artisan config:cache
like image 133
Udhav Sarvaiya Avatar answered Oct 30 '25 03:10

Udhav Sarvaiya