Laravel Sail setup

This commit is contained in:
2025-10-30 11:10:32 -07:00
parent e7c90db220
commit 283595485c
7 changed files with 74 additions and 112 deletions

View File

@@ -4,7 +4,7 @@
Clone the repo.
### 1a. Docker (Recommended)
### 1a. Laravel Sail / Docker (Recommended)
It's recommended to use Docker to set up the development environment. It's literally one command:
@@ -12,48 +12,38 @@ It's recommended to use Docker to set up the development environment. It's liter
docker compose up -d
```
From this point onward, run all shell commands inside the `ewaste-backend-laravel-1` container. The easiest way to do this is through your IDE's Docker extension, but the manual way is:
From this point onward, run all shell commands with the `./vendor/bin/sail` prefix so they get run inside the container. You might want to set up a shell alias in `~/.bashrc` to remove the relative path:
```bash
docker exec -it ewaste-backend-laravel-1 /bin/bash
alias sail='./vendor/bin/sail '
```
### 1b. Manual
Alternatively, you can install PHP 8 (with the relevant extensions), PHP Composer, and Postgres on your system, then go into this directory and run:
Alternatively, you can install PHP 8 (with the [relevant extensions](https://stackoverflow.com/questions/40815984/how-to-install-all-required-php-extensions-for-laravel)), PHP Composer, and Postgres on your system, then go into this directory and run:
```bash
composer install
```
Don't use the `sail` prefix if you install it this way.
### 2. Migrations
Apply all migrations to the database:
```bash
php artisan migrate
sail php artisan migrate
```
**Note:** this step has to be redone every time a new database migration is written.
### 3. Generate key
Your .env should look something like this prior to running the command:
```
DB_CONNECTION=pgsql
DB_HOST=db
DB_PORT=5432
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=secret
APP_KEY=
```
Generate Artisan key necessary for accessing endpoint:
Copy the `.env.example` file to `.env`. Generate the application encryption key:
```bash
exec laravel php artisan key:generate
sail php artisan key:generate
```
## Development
@@ -61,24 +51,18 @@ exec laravel php artisan key:generate
### Dev Server
To start the Laravel dev server, run this *inside* the Docker container:
Start the Laravel dev server with this command:
```bash
composer run dev
sail php artisan serve --host=0.0.0.0
```
Then you can go to http://localhost:8000 in your browser, like it says. The site will live update any time you make changes.
Then you can go to http://localhost/ in your browser (if using Sail) or http://localhost:8000/ (for manual installs). The site will live update any time you make changes.
### Changing Docker Configs
If you change the Dockerfile, run this *outside* the Docker container:
```bash
docker compose up --build -d
```
If you change the docker-compose.yml file, run this *outside* the Docker container:
If you change the compose.yml file, run this in your shell (not with Sail):
```bash
docker compose restart
```
```