Jan and RESTless
Jan and RESTless

Reputation: 388

How to configure the connection to a ".sql" - database file in the ".env"-file of a laravel-project?

I've downloaded someones laravel-project and try to run it. There was also a '.sql'-file attached.

The '.env' -file was mentioned in the project's .gitignore-file, hence it wasn't included in the repository (which is the best practice, I recon). I copied this one into the project's root: https://github.com/laravel/laravel/blob/master/.env.example

I've configured the database-related section of this file like so:

(no password required)

I've run the command php artisan key:generate to add the encryption key to the ".env"-file, and tried the following steps to run the app:

  1. I start the apache web server and mysql database using the xampp-manager (macOS)
  2. I run the app using the command php artisan serve

The app itself loads, but it's empty since it doesn't read the data. However, phpMyAdmin shows that the database and it's data is readable at: http://localhost/phpmyadmin/sql.php?server=1&db= [my_own_db] [name of the table]

Here's a screenshot of the settings:

SQL Database settings shown in myPHPAdmin

These are the db's privileges:

enter image description here

What am I doing wrong?

Upvotes: 0

Views: 5543

Answers (2)

Hanis Harun
Hanis Harun

Reputation: 43

First you need to have an empty database.

Then check your database information in .env file. Make sure it connected to correct database.

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=yourdbname
DB_USERNAME=dbuser
DB_PASSWORD=dbpass

If needed, run composer install or update

composer install

Then run key generate

php artisan key:generate

Then run migration

php artisan migrate:fresh

If the project have seeder, use:

php artisan migrate:fresh --seed

Then serve to run the localhost server

php artisan serve

If you are developing project using Laravel, I would suggest you to use Laragon instead of XAMPP

Upvotes: 0

HXavS
HXavS

Reputation: 119

The DB_CONNECTION should still read mysql. That field is the driver of database connection. Xampp is a bundle of software for local web development, but your database looks to be a MariaDB. MariaDB is a fork of mysql and driver compatible.

DB_CONNECTION=mysql

Upvotes: 2

Related Questions