rumenx / php-seo
AI-powered, framework-agnostic PHP package for automated SEO optimization. Intelligently generates meta tags, titles, descriptions, and alt texts using configurable AI providers or manual patterns.
Fund package maintenance!
RumenDamyanov
Requires
- php: ^8.2
- ext-curl: *
- ext-json: *
- guzzlehttp/guzzle: ^7.8
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/log: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.48
- laravel/framework: ^11.0
- mockery/mockery: ^1.6
- orchestra/testbench: ^9.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-type-coverage: ^2.8
- phpstan/phpstan: ^1.10
- phpstan/phpstan-strict-rules: ^1.5
- squizlabs/php_codesniffer: ^3.8 || ^4.0
- symfony/dependency-injection: ^7.3
- symfony/framework-bundle: ^7.0
- symfony/http-kernel: ^7.3
- symfony/var-dumper: ^7.0
- twig/twig: ^3.21
Suggests
- laravel/framework: For Laravel integration (^10.0|^11.0)
- monolog/monolog: For enhanced logging support
- symfony/framework-bundle: For Symfony integration (^6.0|^7.0)
This package is auto-updated.
Last update: 2025-09-22 13:51:17 UTC
README
php-seo is a modern, AI-powered, framework-agnostic PHP package for automated SEO optimization. It intelligently generates meta tags, titles, descriptions, and alt texts using configurable AI providers or manual patterns, seamlessly integrating with Laravel, Symfony, or any PHP project.
โจ Features
๐ค AI-Powered Automation
- Intelligent Content Analysis: AI reads and analyzes page content to generate optimal titles, descriptions, and meta tags
- Image Analysis: Automatically generates alt text and titles for images by analyzing context
- Social Media Optimization: Generates platform-specific meta tags (Open Graph, Twitter Cards, etc.)
- Multi-Provider Support: Integration with popular AI models (GPT-4/5, Claude, Gemini, Grok, Ollama)
๐ง Manual Configuration Mode
- Pattern-Based Generation: Generate titles and descriptions using configurable patterns
- Manual Override: Full manual control over all SEO elements
- Fallback Systems: Graceful degradation when AI services are unavailable
- Template-Based: Use predefined templates for consistent SEO across pages
๐๏ธ Framework Integration
- Laravel: Native service provider, facades, config publishing, middleware
- Symfony: Bundle integration with services and configuration
- Generic PHP: Framework-agnostic core that works with any PHP project
๐ Modern PHP
- Type-safe: Full PHP 8.2+ type declarations and strict types
- Extensible: Plugin architecture for custom analyzers and generators
- High Performance: Optimized for speed with caching and lazy loading
- 100% Test Coverage: Comprehensive test suite using Pest
๐ Quick Links
- ๐ Installation
- ๐ก Usage Examples
- โ๏ธ Configuration
- ๐ค AI Providers
- ๐งช Testing & Development
- ๐ค Contributing
- ๐ฌ Discussions
- ๐ Security Policy
- ๐ Support & Funding
- ๐ License
๐ฆ Installation
Install via Composer:
composer require rumenx/php-seo
Requirements
- PHP 8.2 or higher
- ext-json
- ext-curl
๐ Usage Examples
Laravel Example
Basic Setup
// In your controller use Rumenx\PhpSeo\SeoManager; public function show(Post $post, SeoManager $seo) { $content = view('posts.content', compact('post'))->render(); $seoData = $seo->analyze($content, [ 'title' => $post->title, 'url' => request()->url(), 'image' => $post->featured_image, 'author' => $post->author->name, 'published_at' => $post->published_at->toISOString(), ])->generateAll(); return view('posts.show', compact('post', 'seoData')); }
Blade Template
@extends('layouts.app') @section('head') {!! app('seo')->renderMetaTags($seoData) !!} @endsection @section('content') <!-- Your content here --> @endsection
Using Facade
use Rumenx\PhpSeo\Facades\Seo; // Quick generation $title = Seo::analyze($content)->generateTitle(); $description = Seo::generateDescription(); $metaTags = Seo::generateMetaTags(); // Complete SEO data $seoData = Seo::analyze($content, $metadata)->generateAll();
Middleware Integration
// In app/Http/Kernel.php protected $routeMiddleware = [ 'seo' => \Rumenx\PhpSeo\Integrations\Laravel\SeoMiddleware::class, ]; // In your routes Route::get('/posts/{post}', [PostController::class, 'show']) ->middleware('seo');
Symfony Example
Controller Usage
use Rumenx\PhpSeo\SeoManager; use Symfony\Component\HttpFoundation\Response; class PostController extends AbstractController { public function show(Post $post, SeoManager $seo): Response { $content = $this->renderView('post/content.html.twig', ['post' => $post]); $seoData = $seo->analyze($content, [ 'title' => $post->getTitle(), 'url' => $this->generateUrl('post_show', ['id' => $post->getId()], UrlGeneratorInterface::ABSOLUTE_URL), 'image' => $post->getFeaturedImage(), 'author' => $post->getAuthor()->getName(), ])->generateAll(); return $this->render('post/show.html.twig', [ 'post' => $post, 'seo_data' => $seoData, ]); } }
Twig Template
{% extends 'base.html.twig' %} {% block head %} {{ seo_meta_tags(seo_data)|raw }} {% endblock %} {% block body %} <!-- Your content here --> {% endblock %}
Generic PHP Example
require 'vendor/autoload.php'; use Rumenx\PhpSeo\SeoManager; use Rumenx\PhpSeo\Config\SeoConfig; // Basic usage $seo = new SeoManager(); $content = file_get_contents('page-content.html'); $seoData = $seo->analyze($content, [ 'title' => 'My Page Title', 'url' => 'https://example.com/page', ])->generateAll(); // Output meta tags echo $seo->renderMetaTags($seoData); // With custom configuration $config = new SeoConfig([ 'title' => [ 'pattern' => '{title} - {site_name}', 'site_name' => 'My Website', 'max_length' => 55, ], 'mode' => 'ai', 'ai' => [ 'provider' => 'openai', 'api_key' => $_ENV['OPENAI_API_KEY'], ], ]); $seo = new SeoManager($config); $optimizedTitle = $seo->analyze($content)->generateTitle();
โ๏ธ Configuration
Laravel Configuration
Publish the configuration file:
php artisan vendor:publish --provider="Rumenx\PhpSeo\Integrations\Laravel\SeoServiceProvider"
Edit config/seo.php
:
return [ 'mode' => 'hybrid', // 'ai', 'manual', 'hybrid' 'ai' => [ 'provider' => 'openai', 'api_key' => env('SEO_AI_API_KEY'), 'model' => 'gpt-4-turbo-preview', ], 'title' => [ 'pattern' => '{title} | {site_name}', 'site_name' => env('APP_NAME'), 'max_length' => 60, ], // ... more configuration ];
Environment Variables
# Basic settings SEO_ENABLED=true SEO_MODE=hybrid SEO_CACHE_ENABLED=true # 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" # Social media SEO_OG_SITE_NAME="My Website" SEO_TWITTER_SITE="@mywebsite"
๐ค AI Providers
OpenAI (GPT-4/5)
$config = new SeoConfig([ 'ai' => [ 'provider' => 'openai', 'api_key' => 'your-openai-api-key', 'model' => 'gpt-4-turbo-preview', ], ]);
Anthropic (Claude)
$config = new SeoConfig([ 'ai' => [ 'provider' => 'anthropic', 'api_key' => 'your-anthropic-api-key', 'model' => 'claude-3-sonnet-20240229', ], ]);
Google (Gemini)
$config = new SeoConfig([ 'ai' => [ 'provider' => 'google', 'api_key' => 'your-google-api-key', 'model' => 'gemini-pro', ], ]);
Local AI (Ollama)
$config = new SeoConfig([ 'ai' => [ 'provider' => 'ollama', 'api_url' => 'http://localhost:11434', 'model' => 'llama2', ], ]);
Multiple Providers (Fallback)
$config = new SeoConfig([ 'ai' => [ 'provider' => 'openai', 'api_key' => 'primary-key', 'fallback_providers' => [ ['provider' => 'anthropic', 'api_key' => 'backup-key'], ['provider' => 'ollama', 'api_url' => 'http://localhost:11434'], ], ], ]);
๐ฏ Advanced Features
Custom Analyzers
use Rumenx\PhpSeo\Contracts\AnalyzerInterface; class CustomContentAnalyzer implements AnalyzerInterface { public function analyze(string $content, array $metadata = []): array { // Your custom analysis logic return [ 'custom_data' => $this->extractCustomData($content), // ... other data ]; } public function supports(string $contentType): bool { return $contentType === 'custom/format'; } } // Use your custom analyzer $seo = new SeoManager( config: $config, contentAnalyzer: new CustomContentAnalyzer() );
Custom Generators
use Rumenx\PhpSeo\Contracts\GeneratorInterface; class CustomTitleGenerator implements GeneratorInterface { public function generate(array $pageData): string { // Your custom generation logic return $this->createCustomTitle($pageData); } public function generateCustom(mixed $customInput, array $pageData = []): string { // Handle custom input return $this->processCustomTitle($customInput, $pageData); } public function supports(string $type): bool { return $type === 'title'; } }
Batch Processing
$posts = Post::all(); $seoResults = []; foreach ($posts as $post) { $content = $post->getContent(); $metadata = [ 'title' => $post->getTitle(), 'url' => $post->getUrl(), 'author' => $post->getAuthor(), ]; $seoResults[$post->getId()] = $seo ->analyze($content, $metadata) ->generateAll(); }
๐งช Testing & Development
Running Tests
# Run all tests composer test # Run tests with coverage composer test-coverage # Generate HTML coverage report composer test-coverage-html # Run specific test ./vendor/bin/pest tests/Unit/SeoManagerTest.php
Code Quality
# Check coding standards composer style # Fix coding standards composer style-fix # Run static analysis composer analyze # Run all quality checks composer quality
๐ Documentation
- Configuration Reference
- AI Integration Guide
- Laravel Examples
- Symfony Examples
- Plain PHP Examples
- Basic Examples
- Home
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details.
- ๐ Report issues
- ๐ก Request features
- ๐ง Submit pull requests
๐ Security
If you discover a security vulnerability, please review our Security Policy for responsible disclosure guidelines.
๐ Support
If you find this package helpful, consider:
- โญ Starring the repository
- ๐ Supporting development
- ๐ Reporting issues
- ๐ค Contributing improvements
๐ License
MIT License. Please see the license file for more information.
๐ About
php-seo is created and maintained by Rumen Damyanov. It's inspired by the success of php-sitemap and aims to bring the same level of quality and ease-of-use to SEO optimization.
Related Projects
- php-chatbot - AI powered chatbot package
- php-sitemap - Framework-agnostic sitemap generation
- php-feed - Framework-agnostic rss feed generation
- php-calendar - Framework-agnostic calendar package
- php-vcard - Framework-agnostic vcard generation
- More projects coming soon!
Framework-agnostic AI-powered SEO optimization for modern PHP applications.