Skip to content

Installation Guide

Rumen Damyanov edited this page Jul 31, 2025 · 1 revision

Installation Guide

This page provides detailed installation instructions for php-chatbot in various environments.

Table of Contents

Requirements

System Requirements

  • PHP: 8.3 or higher
  • Composer: Latest version recommended
  • Extensions: curl, json, mbstring
  • Memory: Minimum 128MB (256MB+ recommended)

Optional Requirements

  • Laravel: 8.0+ (for Laravel integration)
  • Symfony: 5.4+ (for Symfony integration)
  • Node.js: 16+ (for frontend component development)

Installation Methods

Method 1: Composer (Recommended)

composer require rumenx/php-chatbot

Method 2: Manual Download

  1. Download the latest release from GitHub
  2. Extract to your project directory
  3. Include the autoloader:
require_once 'path/to/php-chatbot/vendor/autoload.php';

Method 3: Development Installation

For contributing or development:

git clone https://github.com/RumenDamyanov/php-chatbot.git
cd php-chatbot
composer install

Framework-Specific Setup

Laravel Integration

Auto-Discovery (Laravel 5.5+)

The service provider is automatically discovered. No manual registration needed!

Manual Registration (Older Versions)

Add to config/app.php:

'providers' => [
    // Other providers...
    Rumenx\PhpChatbot\Adapters\Laravel\PhpChatbotServiceProvider::class,
],

Publish Configuration

php artisan vendor:publish --provider="Rumenx\PhpChatbot\Adapters\Laravel\PhpChatbotServiceProvider"

This creates:

  • config/phpchatbot.php - Main configuration file
  • resources/views/vendor/phpchatbot/ - View templates

Publish Assets (Optional)

php artisan vendor:publish --provider="Rumenx\PhpChatbot\Adapters\Laravel\PhpChatbotServiceProvider" --tag=assets

Symfony Integration

Register the Bundle

Add to config/bundles.php:

return [
    // Other bundles...
    Rumenx\PhpChatbot\Adapters\Symfony\PhpChatbotBundle::class => ['all' => true],
];

Publish Configuration

php bin/console chatbot:publish-config

Configure Services (Optional)

Create config/packages/phpchatbot.yaml:

phpchatbot:
    model: 'openai'
    api_key: '%env(OPENAI_API_KEY)%'
    prompt: 'You are a helpful assistant.'

Plain PHP Integration

Basic Setup

<?php
require_once 'vendor/autoload.php';

use Rumenx\PhpChatbot\PhpChatbot;
use Rumenx\PhpChatbot\Models\ModelFactory;

// Load configuration
$config = require 'path/to/config/phpchatbot.php';

// Create model and chatbot
$model = ModelFactory::make($config);
$chatbot = new PhpChatbot($model, $config);

Custom Configuration Path

// Use environment variable for config path
$configPath = getenv('PHPCHATBOT_CONFIG_PATH') ?: __DIR__ . '/config/phpchatbot.php';
$config = require $configPath;

Environment Configuration

Create .env File

Copy the example environment file:

cp .env.example .env

Configure API Keys

Add your AI provider API keys to .env:

# OpenAI
OPENAI_API_KEY=sk-your-openai-key-here

# Anthropic
ANTHROPIC_API_KEY=your-anthropic-key-here

# Google Gemini
GEMINI_API_KEY=your-gemini-key-here

# xAI
XAI_API_KEY=your-xai-key-here

# Meta
META_API_KEY=your-meta-key-here

# DeepSeek
DEEPSEEK_API_KEY=your-deepseek-key-here

Environment Variables

Variable Description Default
PHPCHATBOT_MODEL Default AI model openai
PHPCHATBOT_TIMEOUT API timeout (seconds) 30
PHPCHATBOT_MAX_TOKENS Maximum tokens per response 1000
PHPCHATBOT_TEMPERATURE Response creativity (0.0-1.0) 0.7

Security Configuration

# Rate limiting
PHPCHATBOT_RATE_LIMIT=10
PHPCHATBOT_RATE_WINDOW=60

# Content filtering
PHPCHATBOT_ENABLE_FILTERING=true
PHPCHATBOT_PROFANITY_FILTER=true

Verification

Test Installation

Create a test script (test-installation.php):

<?php
require_once 'vendor/autoload.php';

use Rumenx\PhpChatbot\PhpChatbot;
use Rumenx\PhpChatbot\Models\DefaultAiModel;

try {
    // Test with default model (no API key needed)
    $model = new DefaultAiModel();
    $chatbot = new PhpChatbot($model);
    
    $response = $chatbot->ask('Hello, world!');
    echo "✅ Installation successful!\n";
    echo "Response: " . $response . "\n";
} catch (Exception $e) {
    echo "❌ Installation failed: " . $e->getMessage() . "\n";
}

Run the test:

php test-installation.php

Test with AI Provider

<?php
require_once 'vendor/autoload.php';

use Rumenx\PhpChatbot\PhpChatbot;
use Rumenx\PhpChatbot\Models\ModelFactory;

try {
    $config = [
        'model' => 'openai',
        'api_key' => 'your-api-key-here',
        'prompt' => 'You are a helpful assistant.',
    ];
    
    $model = ModelFactory::make($config);
    $chatbot = new PhpChatbot($model, $config);
    
    $response = $chatbot->ask('What is PHP?');
    echo "✅ AI integration successful!\n";
    echo "Response: " . $response . "\n";
} catch (Exception $e) {
    echo "❌ AI integration failed: " . $e->getMessage() . "\n";
}

Laravel Verification

# Test Artisan command
php artisan route:list | grep chatbot

# Test in tinker
php artisan tinker
>>> app('phpchatbot')->ask('Hello!')

Symfony Verification

# Check services
php bin/console debug:container | grep chatbot

# Test command
php bin/console chatbot:test

Common Issues

Composer Issues

# Clear Composer cache
composer clear-cache

# Update autoloader
composer dump-autoload

Permission Issues

# Fix directory permissions
chmod -R 755 vendor/
chmod -R 644 config/

Extension Issues

# Check required extensions
php -m | grep -E "(curl|json|mbstring)"

# Install missing extensions (Ubuntu/Debian)
sudo apt-get install php-curl php-json php-mbstring

Next: Quick Start Guide

Clone this wiki locally