Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To establish a connection with a MySQL database located remotely in Laravel, you need to follow these steps:

  1. Configure the database settings in the .env file Open the .env file in your Laravel application and update the following lines to add your database details:

DBCONNECTION=mysql DBHOST=yourdatabasehost DBPORT=yourdatabaseport DBDATABASE=yourdatabasename DBUSERNAME=yourdatabaseusername DBPASSWORD=yourdatabasepassword

  1. Ensure that the remote MySQL server can be accessed The remote MySQL server should allow incoming connections from your IP address. You can check with your server provider or system administrator to ensure that the necessary ports are open.

  2. Test the database connection You can test the database connection by running the following command in your terminal:

php artisan migrate

If the connection is established successfully, you should see the migration results.