Use firstOrCreate instead of create so db:seed can run safely on container restart without duplicate key violation.
3.5 KiB
3.5 KiB
Deployment & Infrastructure
Prerequisites
- Docker ^19.*
- Docker Compose
- Make (optional, for Makefile commands)
Environment Configuration
Root .env (Docker-level)
Located at /root/sides/tckdev/.env:
POSTGRES_DB="tckdev"
POSTGRES_USER="tck"
POSTGRES_PASSWORD="projectdev##1"
PGADMIN_EMAIL="tck68000@gmail.com"
PGADMIN_PASSWORD="projectdev##1"
Application .env (Laravel-level)
Located at /root/sides/tckdev/src/.env:
Key configuration:
APP_URL=https://sides.tck.com.myDB_CONNECTION=pgsql→DB_HOST=192.168.0.211(direct IP, not Docker service name)SESSION_DRIVER=databaseCACHE_STORE=databaseQUEUE_CONNECTION=databaseMAIL_MAILER=smtpvia Gmail SMTP (sideskupang@gmail.com)- Firebase FCM credentials at
storage/app/firebase/sides-b4abb-3604a7cf7584.json
Initial Setup
From Scratch (New Project)
make create-project
This runs:
- Creates
src/directory - Builds Docker images
- Starts containers
- Runs
composer create-project laravel/laravel . - Generates application key
- Creates storage link
- Sets permissions
- Installs npm dependencies
From Existing Code (Clone)
make init
This runs:
- Builds and starts containers
composer install- Copies
.env.exampleto.env - Generates application key
- Creates storage link
- Sets permissions
npm installphp artisan migrate:fresh --seed
Makefile Commands Reference
| Command | Description |
|---|---|
make up |
Start containers (detached) |
make down |
Stop containers, remove orphans |
make down-v |
Stop containers, remove volumes |
make build |
Build Docker images |
make remake |
Full destroy + reinit |
make destroy |
Remove all containers, images, volumes |
make stop |
Stop containers |
make restart |
Down + up |
make ps |
Show container status |
make logs |
Show all container logs |
make logs-watch |
Follow all logs |
make log-app |
Show app container logs |
make log-db |
Show database logs |
make app |
Shell into app container |
make web |
Shell into web container |
make migrate |
Run migrations |
make fresh |
Fresh migration with seed |
make seed |
Run seeders |
make tinker |
Open Laravel tinker |
make test |
Run PHPUnit tests |
make cache |
Optimize autoload + cache |
make cache-clear |
Clear all caches |
Access Points
| Service | URL |
|---|---|
| Application | http://localhost:80 |
| pgAdmin | http://localhost:5050 |
| Adminer | http://localhost:6060 |
| PostgreSQL | localhost:5432 |
Database Connection Discrepancy
Important: The docker-compose.yml defines a postgres service, but src/.env connects to 192.168.0.211 — an external PostgreSQL host, not the Docker container. This means:
- In development/local: The app may connect to an external database instead of the Docker postgres container
- The Docker postgres service is still available at
postgres:5432for inter-container communication - The Python autoscript also connects to
192.168.0.211directly
To use the Docker PostgreSQL, change DB_HOST=postgres in src/.env.
Production Notes
APP_DEBUG=trueis set in.env— should befalsein productionURL::forceScheme('https')is enabled globally inAppServiceProvider- The app URL is
https://sides.tck.com.my - Gmail SMTP is used for password reset emails
- Firebase credentials JSON file is stored in
storage/app/firebase/