API Setup
This guide will walk you through setting up the EasyOTC API project from scratch.
Where this lives
- Repo:
https://github.com/Eliinova/the-one-otc-api - Local dev URL:
http://localhost:8000 - Staging API:
https://stage-api.easyotc.com - Admin (staging):
https://stage-api.easyotc.com/admin - Horizon (staging):
https://stage-api.easyotc.com/horizon - Storefront (staging):
https://stage.easyotc.com - Run locally:
php artisan serve(from thethe-one-otc-apirepo root)
See /access for the full URL and credentials list across environments.
Prerequisites
Before you begin, ensure you have the following installed on your system:
- PHP 8.4+
- Composer 2.8+
- Node.js 22+
- Bun 1.2+
- PostgreSQL 13+
- Redis 8.0+
- Meilisearch 1.15+
Quick Start
1. Clone the Repository
git clone https://github.com/Eliinova/the-one-otc-api
cd the-one-otc-api2. Install PHP Dependencies
composer install3. Environment Configuration
# Copy the environment file
cp .env.example .env
# Generate application key
php artisan key:generate4. Configure Database and Services
Edit the .env file with your database credentials and service configurations:
# Database Configuration
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=otc_api
DB_USERNAME=your_username
DB_PASSWORD=your_password
# MeiliSearch Configuration
MEILISEARCH_HOST=http://localhost:7700
MEILISEARCH_KEY=your-search-key5. Install and Start MeiliSearch
# Download and install MeiliSearch binary
curl -L https://install.meilisearch.com | sh
# Start MeiliSearch (run this in a separate terminal)
./meilisearchMeiliSearch will be available at http://localhost:7700
⚠️ IMPORTANT: MeiliSearch must be running before you run database seeding. If MeiliSearch is not running, the seeding process will fail.
6. Run Database Migrations
# Create database tables
php artisan migrate
# Seed with initial data
php artisan db:seed7. Install Frontend Dependencies (Optional)
If you plan to work with the frontend assets:
npm install
# or
bun install8. Start the Development Server
php artisan serveYour API will be available at http://localhost:8000 locally. For deployed environments, use:
| Environment | URL |
|---|---|
| Local | http://localhost:8000 |
| Staging API | https://stage-api.easyotc.com |
| Admin (staging) | https://stage-api.easyotc.com/admin |
| Horizon (staging) | https://stage-api.easyotc.com/horizon |
| Storefront (staging) | https://stage.easyotc.com |
See /access for the complete URL list.
Development Setup
Database Seeding
The project comes with comprehensive seeders for development:
# Seed all data
php artisan db:seed
# Seed specific data
php artisan db:seed --class=UserSeeder
php artisan db:seed --class=CarrierSeeder
php artisan db:seed --class=ProductSeederDefault Users
After seeding, you'll have these default users (roles defined in app/Enums/RoleEnum.php):
- OTC_ONE_ADMIN:
admin@example.com/password - CARRIER_ADMIN:
admin2@example.com/password - MEMBER:
member@example.com/password
Testing
# Run all tests
php artisan test
# Run specific test file
php artisan test tests/Feature/LoginControllerTest.phpProduction Setup
Environment Variables
For production, ensure these environment variables are properly configured:
APP_ENV=production
APP_DEBUG=false
APP_URL=https://your-domain.com
# Database
DB_CONNECTION=pgsql
DB_HOST=your-db-host
DB_PORT=5432
DB_DATABASE=your-database
DB_USERNAME=your-username
DB_PASSWORD=your-secure-password
# Mail configuration
MAIL_MAILER=smtp
MAIL_HOST=your-smtp-host
MAIL_PORT=587
MAIL_USERNAME=your-email
MAIL_PASSWORD=your-password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=noreply@your-domain.com
MAIL_FROM_NAME="${APP_NAME}"
# Search engine
MEILISEARCH_HOST=http://localhost:7700
MEILISEARCH_KEY=your-search-keyOptimization
# Cache configuration
php artisan config:cache
php artisan route:cache
php artisan view:cache
# Optimize autoloader
composer install --optimize-autoloader --no-devTroubleshooting
Common Issues
Permission Denied Errors
# Set proper permissions on storage and bootstrap/cache
chmod -R 775 storage bootstrap/cacheComposer Memory Issues
# Increase memory limit
COMPOSER_MEMORY_LIMIT=-1 composer installDatabase Connection Issues
- Verify database credentials in
.env - Ensure database server is running
- Check if database exists:
php artisan migrate:status
Port Already in Use
# Use different port
php artisan serve --port=8001MeiliSearch Issues
- Ensure MeiliSearch is running:
./meilisearch - Check if port 7700 is available:
lsof -i :7700 - Verify MeiliSearch is accessible:
curl http://localhost:7700/health - If seeding fails: Make sure MeiliSearch is running before running
php artisan db:seed