Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Setting up a MySQL database for the app

Katja Durrani edited this page Oct 28, 2020 · 10 revisions

Create a database with initial tables and a first user

(This is again written on the basis that we use Laradock, but should be easy to transfer to other environments)

Set up the database

1. Set environment variables for Laradock and the app

Below are the configurations for the two .env files. It does not matter what you choose for names (database, user and password), as long as they are the same for both files.

codehub-mentorships/.env:

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=mentoring
DB_USERNAME=mentor
DB_PASSWORD=bristol

laradock/.env:

### MYSQL #################################################
MYSQL_VERSION=8.0.21
MYSQL_DATABASE=mentoring
MYSQL_USER=mentor
MYSQL_PASSWORD=bristol
MYSQL_PORT=3306
MYSQL_ROOT_PASSWORD=root
MYSQL_ENTRYPOINT_INITDB=./mysql/docker-entrypoint-initdb.d

2. Start docker containers with the new configuration

Inside the laradock directory, run docker-compose up -d nginx mysql

3. Create database

Inside laradock, run docker-compose exec mysql mysql -u root -p, then enter your db root password. This should take you onto the mysql commandline inside the mysql docker container.

Now you can create the database:

mysql>  CREATE DATABASE mentoring;

This is all we need to do in this container; \q will take you out of mysql and the container.

4. Create initial tables from inside the workspace container, and a first user

Enter the workspace container with docker-compose exec workspace bash.
Inside the container, you should be in the /var/www directory

Please note, if you have set up the project previously, you might have to run composer dump-autoload to make the class for the user seeder available.

Then you can run:

php artisan migrate:fresh --seed

This will create the database tables for the application and create a User that you can use to authenticate in the application.

The login credentials for this test user are:

email: [email protected] password: password

After rebuilding the frontend of the app with npm run dev or yarn dev you should be able to use these credentials to log in at localhost/login