-
-
Notifications
You must be signed in to change notification settings - Fork 1
Configuration
Rumen Damyanov edited this page Sep 22, 2025
·
1 revision
This document provides a comprehensive reference for all configuration options available in the php-seo package.
The configuration system supports multiple ways to configure the package:
- Array-based configuration: Direct PHP array configuration
-
Environment variables: Using
.envfiles - Framework integration: Laravel config files, Symfony parameters
[
'enabled' => true, // Enable/disable the package
'mode' => 'manual', // 'ai', 'manual', 'hybrid'
'cache_enabled' => true, // Enable result caching
'cache_ttl' => 3600, // Cache time-to-live in seconds
]-
manual: Use only manual patterns and rules -
ai: Use AI providers for generation -
hybrid: Try AI first, fallback to manual
'ai' => [
'provider' => 'openai', // Primary AI provider
'model' => 'gpt-4-turbo-preview', // Model to use
'api_key' => 'your-api-key', // API key for the provider
'api_url' => null, // Custom API URL (for local providers)
'timeout' => 30, // Request timeout in seconds
'max_retries' => 3, // Maximum retry attempts
'cost_tracking' => false, // Track API costs
'rate_limiting' => [
'enabled' => true,
'requests_per_minute' => 10,
],
'fallback_providers' => [ // Fallback providers if primary fails
['provider' => 'anthropic', 'api_key' => 'backup-key'],
['provider' => 'ollama', 'api_url' => 'http://localhost:11434'],
],
]'ai' => [
'provider' => 'openai',
'api_key' => env('OPENAI_API_KEY'),
'model' => 'gpt-4-turbo-preview', // or 'gpt-3.5-turbo', 'gpt-4'
]'ai' => [
'provider' => 'anthropic',
'api_key' => env('ANTHROPIC_API_KEY'),
'model' => 'claude-3-sonnet-20240229',
]'ai' => [
'provider' => 'google',
'api_key' => env('GOOGLE_API_KEY'),
'model' => 'gemini-pro',
]'ai' => [
'provider' => 'ollama',
'api_url' => 'http://localhost:11434',
'model' => 'llama2', // or any local model
]'title' => [
'max_length' => 60, // Maximum title length
'min_length' => 10, // Minimum title length
'pattern' => '{title} | {site_name}', // Title pattern
'site_name' => 'My Website', // Site name for pattern
'separator' => ' | ', // Separator in patterns
'case' => 'title', // 'title', 'sentence', 'lower', 'upper'
'ai_prompt' => 'Generate an SEO-optimized title...',
]Available placeholders:
-
{title}- The generated or provided title -
{site_name}- The configured site name -
{separator}- The configured separator -
{page_type}- Page type from metadata -
{category}- Category from metadata
Examples:
'{title}' // "About Us"
'{title} | {site_name}' // "About Us | My Website"
'{site_name} - {title}' // "My Website - About Us"
'{title} {separator} {category}' // "About Us | Company"'description' => [
'max_length' => 160, // Maximum description length
'min_length' => 120, // Minimum description length
'pattern' => null, // Optional pattern (usually null)
'ai_prompt' => 'Generate an SEO-optimized meta description...',
]'meta_tags' => [
'default_tags' => [
'viewport' => 'width=device-width, initial-scale=1',
'charset' => 'utf-8',
'robots' => 'index,follow',
],
]'meta_tags' => [
'open_graph' => [
'enabled' => true,
'site_name' => 'My Website',
'type' => 'website', // 'website', 'article', 'product', etc.
'locale' => 'en_US',
],
]'meta_tags' => [
'twitter' => [
'enabled' => true,
'card' => 'summary_large_image', // 'summary', 'summary_large_image', 'app', 'player'
'site' => '@mywebsite',
'creator' => '@author',
],
]'meta_tags' => [
'robots' => [
'index' => true, // Allow indexing
'follow' => true, // Allow following links
'archive' => true, // Allow archiving
'snippet' => true, // Allow snippets
'imageindex' => true, // Allow image indexing
],
]'images' => [
'alt_text' => [
'enabled' => true,
'ai_vision' => false, // Use AI vision for alt text
'pattern' => null,
'ai_prompt' => 'Generate descriptive alt text...',
],
'title_text' => [
'enabled' => true,
'pattern' => null,
],
]'analysis' => [
'extract_headings' => true, // Extract H1-H6 tags
'extract_images' => true, // Extract image information
'extract_links' => true, // Extract link information
'extract_keywords' => true, // Extract keywords from content
'min_content_length' => 100, // Minimum content length to process
'language_detection' => true, // Detect content language
]'laravel' => [
'middleware' => [
'enabled' => false, // Enable automatic middleware
'routes' => ['web'], // Route groups to apply middleware
],
'blade_directives' => true, // Enable Blade directives
'config_cache' => true, // Enable config caching
]'symfony' => [
'twig_extensions' => true, // Enable Twig extensions
'event_listeners' => true, // Enable event listeners
'cache_pool' => 'cache.app', // Cache pool to use
]'logging' => [
'enabled' => false, // Enable logging
'level' => 'info', // Log level
'channels' => ['php-seo'], // Log channels
]'performance' => [
'lazy_loading' => true, // Enable lazy loading
'compression' => true, // Enable response compression
'minify_output' => false, // Minify HTML output
]All configuration options can be overridden using environment variables:
# Basic settings
SEO_ENABLED=true
SEO_MODE=hybrid
SEO_CACHE_ENABLED=true
SEO_CACHE_TTL=3600
# AI Provider
SEO_AI_PROVIDER=openai
SEO_AI_API_KEY=your-api-key-here
SEO_AI_MODEL=gpt-4-turbo-preview
# Title settings
SEO_TITLE_PATTERN="{title} | {site_name}"
SEO_SITE_NAME="My Website"
SEO_TITLE_MAX_LENGTH=60
# Description settings
SEO_DESCRIPTION_MAX_LENGTH=160
SEO_DESCRIPTION_MIN_LENGTH=120
# Open Graph
SEO_OG_ENABLED=true
SEO_OG_SITE_NAME="My Website"
SEO_OG_TYPE=website
# Twitter
SEO_TWITTER_ENABLED=true
SEO_TWITTER_CARD=summary_large_image
SEO_TWITTER_SITE=@mywebsite
# Robots
SEO_ROBOTS_INDEX=true
SEO_ROBOTS_FOLLOW=trueuse Rumenx\PhpSeo\Config\SeoConfig;
$config = new SeoConfig([
'title' => ['site_name' => 'My Site'],
'meta_tags' => [
'open_graph' => ['site_name' => 'My Site'],
],
]);$config = new SeoConfig([
'mode' => 'ai',
'ai' => [
'provider' => 'openai',
'api_key' => $_ENV['OPENAI_API_KEY'],
'model' => 'gpt-4-turbo-preview',
],
'title' => [
'pattern' => '{title} | {site_name}',
'site_name' => 'AI-Powered Website',
],
]);$config = new SeoConfig([
'mode' => 'hybrid',
'ai' => [
'provider' => 'openai',
'api_key' => $_ENV['OPENAI_API_KEY'],
'cost_tracking' => true,
'rate_limiting' => [
'enabled' => true,
'requests_per_minute' => 50,
],
'fallback_providers' => [
['provider' => 'anthropic', 'api_key' => $_ENV['ANTHROPIC_API_KEY']],
],
],
'cache_enabled' => true,
'cache_ttl' => 7200,
'logging' => [
'enabled' => true,
'level' => 'info',
],
]);The package automatically validates configuration and will throw exceptions for invalid settings:
try {
$config = new SeoConfig(['mode' => 'invalid_mode']);
} catch (InvalidArgumentException $e) {
echo "Invalid configuration: " . $e->getMessage();
}Configuration can be modified at runtime:
$config = new SeoConfig();
// Set individual values
$config->set('title.max_length', 55);
$config->set('ai.provider', 'anthropic');
// Merge new configuration
$config->merge([
'description' => ['max_length' => 150],
'ai' => ['model' => 'claude-3-sonnet'],
]);
// Create new instance with modifications
$newConfig = $config->with([
'mode' => 'ai',
'cache_enabled' => false,
]);