# Running a Laravel app

Recently I came upon a Laravel project: SAM, the legacy system of our club. As an absolute newcomer in backend, I had zero idea how I should start the app.

The first thing I tried was running the index.php file, which just printed out the HTML file in the console. Definitely not working—it's analogous to opening the index.html file of a Vue app. You have to actually start an HTTPS service on the localhost.

## Install dependencies​

Recall how a Vue app is run with yarn.

$yarn install$ yarn serve

Well, in Laravel, things are quite similar. The package manager used is composer, and I installed it globally following instructions here. We install the dependencies declared in composer.json.

$composer --versionComposer version 1.10.13 2020-09-09 11:46:34$ composer install

## Configure environment​

Next, we have to declare the environment. This is the first nuance between a front end project and a back end project. Because the Vue app is run in a browser, you don't worry so much about communicating with the outside. (You are in a sandbox anyways and you access everything through URLs.) But in the back end, the app has to reach out to the server, to the data base, and to all kinds of resources. For the sake of this project, we will configure the app environment and the database connection.

Laravel comes with a sample environment file .env.example. Duplicate it and rename it .env. Then change the first two blocks.

.env
APP_NAME=samAPP_ENV=localAPP_KEY=APP_DEBUG=trueAPP_LOG_LEVEL=debugAPP_URL=http://localhost

The field left empty in the environment is APP_KEY, which is used for encrypted services. Generate one using artisan.

$php artisan key:generateApplication key [base64:yPl2zp1+ZCZ1/7TK8QEM1uQTzOetXp8pl+/bTnbLAuw=] set successfully. ## Configure database​ We move to the database part. .env DB_CONNECTION=mysqlDB_HOST=127.0.0.1DB_PORT=3306DB_DATABASE=samDB_USERNAME=rootDB_PASSWORD=[the root password] I know that in production I'd better not use root to manage the database for security concerns, but it's development anyways, so I chose the easier path. Now, login to MySQL and create a database. $ mysql -u root -pEnter password:Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 38Server version: 8.0.23 HomebrewCopyright (c) 2000, 2021, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> CREATE DATABASE sam;Query OK, 1 row affected (0.01 sec)mysql> quit;Bye

The tables can be automatically generated using