- PHP 7.4 or 8.0+
- Composer
- OpenSSL extension
- PDO extension
cd /home/k1ng5/Mylab/Bahll
composer install# Copy environment template
cp .env.example .env
# Edit .env with your settings
nano .env# Option A: Using PHP built-in server
php api/index.php
# Option B: Using Docker
docker-compose up -d
# Option C: Using Docker Compose with custom port
BAHLL_API_PORT=9000 docker-compose up -d# Check health endpoint
curl http://localhost:8000/api/health
# Expected response:
# {"status":"healthy","timestamp":"2026-06-16T10:30:45+00:00","version":"1.1.0"}# Generate your first API key
curl -X POST http://localhost:8000/api/auth/generate-key \
-H "Content-Type: application/json" \
-d '{
"key_name": "My First App"
}'
# Save the api_key and token from response
# You'll use this token for all subsequent requests!# Get token first (see above)
TOKEN="your-token-here"
curl -X POST http://localhost:8000/api/crypto/encrypt-symmetric \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"plaintext": "Hello, World!",
"key": "my-secret-key-at-least-32-chars"
}'TOKEN="your-token-here"
CIPHERTEXT="from-previous-response"
curl -X POST http://localhost:8000/api/crypto/decrypt-symmetric \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"ciphertext": "'$CIPHERTEXT'",
"key": "my-secret-key-at-least-32-chars"
}'TOKEN="your-token-here"
# Create hash
HASH_RESPONSE=$(curl -s -X POST http://localhost:8000/api/crypto/hash \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"data": "password123",
"algorithm": "sha256"
}')
echo "$HASH_RESPONSE"
# Extract hash from response and verify
# {
# "status": "success",
# "data": {
# "hash": "ef92b778bafe771e89245d171bafbee4ff06f8f38eed6e1983ad1e8e8c7b052e",
# "algorithm": "sha256"
# }
# }
# Verify
curl -X POST http://localhost:8000/api/crypto/verify-hash \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"data": "password123",
"hash": "ef92b778bafe771e89245d171bafbee4ff06f8f38eed6e1983ad1e8e8c7b052e",
"algorithm": "sha256"
}'TOKEN="your-token-here"
# Generate RSA key pair
KEYPAIR=$(curl -s -X POST http://localhost:8000/api/keyring/generate-keypair \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"key_size": 2048}')
echo "$KEYPAIR"
# Extract keys from response
# {
# "status": "success",
# "data": {
# "public_key": "-----BEGIN PUBLIC KEY-----\n...",
# "private_key": "-----BEGIN RSA PRIVATE KEY-----\n...",
# "key_size": 2048,
# "algorithm": "RSA"
# }
# }
# Use public key to encrypt
curl -X POST http://localhost:8000/api/crypto/encrypt-asymmetric \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"plaintext": "Secret message",
"public_key": "PUBLIC_KEY_HERE"
}'
# Use private key to decrypt
curl -X POST http://localhost:8000/api/crypto/decrypt-asymmetric \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"ciphertext": "CIPHERTEXT_HERE",
"private_key": "PRIVATE_KEY_HERE"
}'TOKEN="your-token-here"
# Get all logs
curl -X GET "http://localhost:8000/api/audit/logs?limit=10" \
-H "Authorization: Bearer $TOKEN"
# Get specific log
curl -X GET "http://localhost:8000/api/audit/logs/1" \
-H "Authorization: Bearer $TOKEN"
# Get statistics
curl -X GET "http://localhost:8000/api/audit/stats" \
-H "Authorization: Bearer $TOKEN"
# Filter logs by operation
curl -X GET "http://localhost:8000/api/audit/logs?operation=symmetric_encrypt&status=success" \
-H "Authorization: Bearer $TOKEN"# Build and start
docker-compose up -d
# Check status
docker-compose ps
# View logs
docker-compose logs -f bahll-apidocker-compose downdocker-compose build --no-cache
docker-compose up -d# Create .env file
cat > .env << EOF
BAHLL_API_PORT=8000
BAHLL_JWT_SECRET=your-super-secret-key
BAHLL_LOG_LEVEL=info
BAHLL_CORS_ORIGINS=*
EOF
# Start with custom config
docker-compose up -d- Uncomment PostgreSQL section in
docker-compose.yml - Update
api/config/config.phpto use PostgreSQL - Set database credentials in
.env - Run:
docker-compose up -d
Default: 100 requests per minute per API key
Modify in api/config/config.php:
'rate_limit' => [
'requests_per_minute' => 200, // Change this value
],# Generate secure random secret
php -r "echo bin2hex(random_bytes(32));"
# Add to .env
BAHLL_JWT_SECRET=your-generated-secret-here# Set in .env
BAHLL_CORS_ORIGINS=https://example.com,https://app.example.com# Change port in .env or docker-compose.yml
BAHLL_API_PORT=9000
# Or kill process on port 8000
lsof -ti:8000 | xargs kill -9# Ensure storage directory exists
mkdir -p storage
chmod 777 storage
# Reset database
rm storage/bahll.db
php api/index.php # Will recreate on startupGenerate new token:
curl -X POST http://localhost:8000/api/auth/token \
-H "Content-Type: application/json" \
-d '{"api_key": "YOUR_API_KEY"}'Wait 1 minute or check remaining requests:
- Header:
X-RateLimit-Remaining - Header:
X-RateLimit-Reset
- Use connection pooling in production
- Enable caching for frequently used operations
- Monitor audit logs regularly (clear old entries)
- Use shorter keys when possible (asymmetric crypto is slower)
- Batch operations to reduce API calls
- ✅ Change
BAHLL_JWT_SECRETin production - ✅ Use HTTPS in production (enable TLS/SSL)
- ✅ Store API keys securely (never commit to git)
- ✅ Rotate API keys periodically
- ✅ Monitor audit logs for suspicious activity
- ✅ Use rate limiting to prevent abuse
- ✅ Validate input data on client side
- ✅ Keep PHP and dependencies updated
Full API documentation: API_DOCUMENTATION.md
- GitHub: https://github.com/BangAguse/Bahll
- Issues: https://github.com/BangAguse/Bahll/issues
- Documentation: API_DOCUMENTATION.md