skip to Main Content

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:

  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?

2

Answers


  1. 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

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search