Skip to content

Manasess896/BLOG

Repository files navigation

PHP & MongoDB Blog CMS

A fully custom-built Content Management System (CMS) tailored for blogging. Engineered with modern PHP and MongoDB, this platform features a robust administrative dashboard, an integrated AI writing assistant, advanced security protocols, and built-in newsletter capabilities.

Key Features

  • Rich Text Editor: Integrated Quill WYSIWYG editor for seamless content creation.
  • Image Handling: image uploading and rendering utilizing MongoDB GridFS.
  • AI-Powered Assistant: Integrated with the Gemini API to help draft content, generate SEO meta descriptions, and rewrite excerpts.
  • Draft & Publish Workflow: Manage post statuses seamlessly before pushing them live.
  • Two-Factor Authentication (2FA): Enforced TOTP-based authentication for administrative access.
  • Anti-Brute Force: Login rate limiting (account lockouts/delay after successive failed attempts).
  • Session Protection: Strict session management, hijacking prevention (User Agent & IP binding), and secure httponly cookies.
  • xSS & CSRF Mitigation: HTMLPurifier for robust content sanitization and CSRF tokens across all mutable forms.
  • Bot Protection: Google reCAPTCHA v2 integration on forms.
  • SEO Optimized: Custom slugs, meta titles, descriptions, and dynamic OpenGraph/Twitter cards.
  • Newsletter System: Collect subscriber emails and broadcast newsletters directly from the dashboard.
  • Analytics Dashboard: Track total views, published documents, and recent engagement metrics.

Technology Stack

  • Backend: PHP 8.1+
  • Database: MongoDB (via the mongodb/mongodb driver)
  • Dependency Management: Composer
  • Frontend: HTML5, CSS3, JavaScript, Bootstrap 5
  • Key Libraries:
    • vlucas/phpdotenv: Environment variable management.
    • spomky-labs/otphp: Two-Factor Authentication (TOTP).
    • ezyang/htmlpurifier: XSS payload sanitization.
    • phpmailer/phpmailer or HTTP-based mailer APIs.

Installation & Setup

  1. Clone the repository (if applicable) or place the files in your web directory (e.g., htdocs/blog).

  2. Install Composer Dependencies Navigate to the project root and run:

    composer install
  3. Environment Configuration Create a .env file in the root directory and configure your environment variables:

    # web base url
    BASE_URL="http://localhost/blog/"
    
    #database credentials
    MONGODB_URI="mongodb+srv://<username>:<password>@cluster.mongodb.net/?retryWrites=true&w=majority"
    MONGODB_DATABASE="my_blog_db"
    
    #recaptcha 
    RECAPTCHA_SECRET_KEY="your-google-recaptcha-secret"
    
    #gemin api 
    GEMINI_API_KEY="your-google-gemini-api-key"
    
    # Mail (Brevo / Sendinblue example)
    BREVO_API_KEY="your-brevo-api-key"
    MAIL_FROM_ADDRESS="[email protected]"#from brevo you have to setup this email as a recipient and sender in brevo dashboard
    MAIL_FROM_NAME="Admin" #this is the name that appears after you have sent an email 
  4. Initialize the Admin Account Run the secure seeder script from your terminal to generate the first super admin.

    php seed_admin.php

    Note: For security reasons, the seeder script is programmed to automatically delete itself (unlink) upon successful execution. *The script has preset values such as email and password please replace the values before running the script *

  5. First Login Navigate to /admin/login, log in with the credentials provided by the prompt, and immediately configure your 2FA using a mobile Authenticator app (e.g., Google Authenticator, Authy) this is optional .

Project Structure

  • /admin/ - Fully protected administrative dashboard, login, write/edit interface, and configuration scripts.
  • /vendor/ - Composer dependencies.
  • index.php - Homepage / Blog listing.
  • blog.php - Single article view.
  • contact.php - Contact form.
  • serve_image.php - Secure file handler extracting GridFS images to the browser.
  • .htaccess - Critical security headers, URL rewriting, and directory protection.

Contributing

Contributions, issues, and feature requests are welcome! Ensure you test your code and adhere to the built-in security practices

License

This project is licensed under the MIT License.

Releases

No releases published

Packages

 
 
 

Contributors