This project runs two backend services together:
xiaowu(Laravel API) onhttp://127.0.0.1:8000python_service(FastAPI AI service) onhttp://127.0.0.1:8001
Use this guide to run everything on your own device.
Install these first:
- Git
- PHP 8.2+
- Composer 2+
- Python 3.11+ (3.11 or 3.12 recommended for better package compatibility)
- MySQL 8+
- (Optional but recommended) PowerShell 5+ on Windows
git clone <your-repo-url>
cd SafeGateFrom project root:
cd xiaowu
copy .env.example .env
composer install
php artisan key:generateOpen xiaowu\.env and update database settings to MySQL (important because the Python service reads the same DB):
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=XiaoWu
DB_USERNAME=root
DB_PASSWORD=your_passwordAlso make sure these service-link settings exist in xiaowu\.env:
PYTHON_SERVICE_BASE_URL=http://127.0.0.1:8001
PYTHON_INTERNAL_TOKEN=change-this-internal-token
LARAVEL_BASE_URL=http://127.0.0.1:8000Then run migrations:
php artisan migrateThe Python app auto-loads env values from:
python_service\.env(if present)xiaowu\.env
Create python_service\.env only if you want to override or add Python-specific values:
AI_PROVIDER=qwen
AI_MODEL=qwen-plus
AI_API_KEY=your_ai_api_key
VISUAL_SEARCH_DEVICE=cpu
VISUAL_SEARCH_CLIP_MODEL=ViT-B-32
VISUAL_SEARCH_CLIP_PRETRAINED=laion2b_s34b_b79kNotes:
- If
AI_API_KEYis empty, AI endpoints still run with fallback responses. - Visual search dependencies (
torch,open-clip-torch,faiss-cpu) may take time to install the first time.
From project root:
powershell -ExecutionPolicy Bypass -File .\run-dev.ps1What this script does:
- Creates
python_service\.venvif missing - Installs Python requirements
- Starts Laravel on port
8000 - Starts FastAPI on port
8001
If you prefer separate terminals:
Terminal 1 (Laravel):
cd xiaowu
php artisan serve --host 0.0.0.0 --port 8000Terminal 2 (Python):
cd python_service
python -m venv .venv
.\.venv\Scripts\python.exe -m pip install -r requirements.txt
.\.venv\Scripts\python.exe -m uvicorn app.main:app --host 0.0.0.0 --port 8001 --reloadCheck Laravel:
http://127.0.0.1:8000http://127.0.0.1:8000/api/health-check
Check Python:
http://127.0.0.1:8001/health
Laravel tests:
cd xiaowu
php artisan testStop services:
- If using
run-dev.ps1, pressCtrl + Cin that terminal. - If started manually, stop each terminal process with
Ctrl + C.
-
Database connection errors
- Confirm
DB_*values inxiaowu\.env. - Confirm MySQL is running and database exists.
- Run
php artisan migrateagain.
- Confirm
-
Python package install fails (Torch / Faiss)
- Upgrade pip:
python -m pip install --upgrade pip - Prefer Python 3.11/3.12.
- Recreate venv if needed: delete
python_service\.venvand runrun-dev.ps1again.
- Upgrade pip:
-
Laravel cannot reach Python service
- Confirm
PYTHON_SERVICE_BASE_URL=http://127.0.0.1:8001inxiaowu\.env. - Confirm both services are running.
- Confirm
-
Internal token errors between services
- Ensure
PYTHON_INTERNAL_TOKENis exactly the same value where used.
- Ensure