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:
- DB_CONNECTION=xampp
- DB_HOST=localhost
- DB_PORT=3306
- DB_DATABASE= my_own_db
- DB_USERNAME=root
- DB_PASSWORD=
(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:
- I start the apache web server and mysql database using the xampp-manager (macOS)
- 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:
These are the db’s privileges:
What am I doing wrong?
2
Answers
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
First you need to have an empty database.
Then check your database information in .env file. Make sure it connected to correct database.
If needed, run composer install or update
Then run key generate
Then run migration
If the project have seeder, use:
Then serve to run the localhost server
If you are developing project using Laravel, I would suggest you to use Laragon instead of XAMPP