Skip to main content

Setup & Installation

Complete guide to setting up the ZÈYA API backend for development.

Prerequisites

  • PHP 8.1 or higher
  • Composer
  • MySQL/PostgreSQL
  • Redis
  • MongoDB (optional, for product search)
  • AWS S3 account
  • Firebase project
  • Node.js & NPM (for asset compilation)

Installation Steps

1. Clone Repository

cd api

2. Install Dependencies

# Install PHP dependencies
composer install

# Install frontend dependencies (if needed)
npm install

3. Environment Configuration

# Copy environment file
cp .env.example .env

# Generate application key
php artisan key:generate

# Generate JWT secret
php artisan jwt:secret

4. Configure Database

Edit .env file with your database credentials:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=zeya
DB_USERNAME=root
DB_PASSWORD=

5. Run Migrations

# Run migrations
php artisan migrate

# Seed database (optional)
php artisan db:seed

6. Build Assets (if needed)

npm run build

7. Start Development Server

php artisan serve

The API will be available at http://localhost:8000

Environment Configuration

See Environment Configuration for complete environment variables reference.

Additional Setup

Queue Workers

For development, run queue workers:

php artisan queue:work

Redis Setup

Ensure Redis is running:

# Check Redis status
redis-cli ping

MongoDB Setup (Optional)

If using MongoDB for product search:

# Install MongoDB extension
pecl install mongodb

# Add to php.ini
extension=mongodb.so

Verification

Health Check

curl http://localhost:8000/api/health

Expected response:

{
"status": "healthy",
"timestamp": "2024-12-18T10:00:00.000000Z"
}

Test Authentication

# Register a test user
curl -X POST http://localhost:8000/api/v1/register \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"password": "password123",
"name": "Test User"
}'

Troubleshooting

Common Issues

Issue: Class 'PDO' not found

  • Solution: Install PHP PDO extension: sudo apt-get install php-pdo

Issue: JWT secret not set

  • Solution: Run php artisan jwt:secret

Issue: Redis connection refused

  • Solution: Start Redis server: redis-server

Issue: MongoDB connection failed

  • Solution: Ensure MongoDB is running and credentials are correct in .env

Permissions

Ensure storage directories are writable:

chmod -R 775 storage bootstrap/cache

Next Steps