A modern, secure, and well-architected Blog Content Management System built with PHP 8+, featuring user authentication, CSRF protection, input validation, and a clean Bootstrap 5 interface. This project demonstrates professional PHP development practices with proper separation of concerns, repository pattern, and comprehensive security features.
This Blog CMS System is a production-ready content management platform that showcases modern PHP development practices. It features a clean MVC-inspired architecture, robust security measures, and an intuitive user interface built with Bootstrap 5.
.env file supportBlog-CMS-System-PHP/
├── bootstrap.php # Application initialization
├── .env # Environment configuration (not in repo)
├── .env.example # Environment template
├── docker-compose.yml # Docker configuration
├── Dockerfile # Docker image definition
│
├── database/
│ └── schema.sql # Database schema with indexes
│
├── public/ # Public web root
│ ├── index.php # Homepage (list posts)
│ ├── view_post.php # Single post view
│ ├── create_post.php # Create new post
│ ├── edit_post.php # Edit existing post
│ ├── delete_post.php # Delete post handler
│ ├── login.php # User login
│ ├── register.php # User registration
│ └── logout.php # Logout handler
│
├── src/
│ ├── Config/
│ │ └── Database.php # Database connection (Singleton)
│ │
│ ├── Controllers/
│ │ ├── PostController.php # Post management logic
│ │ └── AuthController.php # Authentication logic
│ │
│ ├── Models/
│ │ ├── BaseRepository.php # Base CRUD operations
│ │ ├── PostRepository.php # Post-specific queries
│ │ └── UserRepository.php # User-specific queries
│ │
│ ├── Middleware/
│ │ └── Auth.php # Authentication middleware
│ │
│ ├── Helpers/
│ │ ├── Env.php # Environment variable loader
│ │ ├── Logger.php # File-based logger
│ │ ├── Session.php # Session management
│ │ ├── CSRF.php # CSRF token handler
│ │ └── Validator.php # Input validation
│ │
│ └── Views/
│ ├── header.php # HTML header template
│ └── footer.php # HTML footer template
│
├── logs/ # Application logs
└── tests/ # Unit tests (future)
| Layer | Technology | Version |
|---|---|---|
| Language | PHP | 8.0+ |
| Database | MySQL / MariaDB | 8.0+ / 10.5+ |
| Web Server | Apache / Nginx | Latest |
| Frontend | Bootstrap | 5.3.2 |
| Icons | Bootstrap Icons | 1.11.1 |
| Container | Docker | Latest |
| PHP Extensions | PDO, pdo_mysql, mbstring | - |
git clone https://github.com/UNC-GDSC/Blog-CMS-System-PHP.git
cd Blog-CMS-System-PHP
cp .env.example .env
Edit .env with your database credentials:
DB_HOST=localhost
DB_PORT=3306
DB_NAME=blog_cms
DB_USER=your_username
DB_PASS=your_password
mysql -u root -p
CREATE DATABASE blog_cms CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
mysql -u your_username -p blog_cms < database/schema.sql
chmod -R 755 .
chmod -R 777 logs/
cd public
php -S localhost:8000
Open your browser and navigate to:
All configuration is managed through the .env file:
# Application
APP_NAME="Blog CMS System"
APP_ENV=development # development | production
APP_DEBUG=true # true | false
APP_URL=http://localhost:8000
# Database
DB_HOST=localhost
DB_PORT=3306
DB_NAME=blog_cms
DB_USER=root
DB_PASS=
# Session
SESSION_LIFETIME=7200 # 2 hours in seconds
SESSION_NAME=blog_cms_session
# Security
SECRET_KEY=your-secret-key-change-in-production
CSRF_TOKEN_EXPIRY=3600 # 1 hour
# Timezone
APP_TIMEZONE=UTC
# Logging
LOG_LEVEL=debug # debug | info | warning | error
LOG_PATH=logs/app.log
# Pagination
POSTS_PER_PAGE=10
For production deployment, ensure:
APP_ENV=production and APP_DEBUG=falseSECRET_KEY/public/register.php/public/login.phpCreate Post:
Edit Post:
Delete Post:
Search Posts:
All forms include CSRF tokens that are validated on submission:
<?= CSRF::field() ?> // Generates hidden input
CSRF::verify(); // Validates token
Comprehensive validation with custom rules:
$validator = new Validator($data);
$validator->rule('title', 'required|min:3|max:200', 'Title')
->rule('email', 'required|email', 'Email');
if ($validator->fails()) {
$errors = $validator->errors();
}
password_hash() with bcryptAll database queries use prepared statements:
$stmt = $this->db->prepare("SELECT * FROM posts WHERE id = :id");
$stmt->execute(['id' => $id]);
docker-compose up -d
This starts three services:
docker-compose down
docker-compose logs -f app
The .env file is automatically loaded. Ensure these match your docker-compose.yml:
DB_HOST=db
DB_NAME=blog_cms
DB_USER=blog_user
DB_PASS=blog_password
PHPUnit tests will be added in the tests/ directory:
./vendor/bin/phpunit tests/
Database Connection Failed
.envCSRF Token Mismatch
.env has SECRET_KEY setPermission Denied Errors
chmod -R 777 logs/ for log directoryBootstrap/CSS Not Loading
We welcome contributions! Please follow these guidelines:
git checkout -b feature/amazing-featuregit commit -m 'Add amazing feature'git push origin feature/amazing-featureThis project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2025 UNC-CH Google Developer Student Club
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
UNC-CH Google Developer Student Club (GDSC)
Special thanks to all contributors who helped make this project better!
Current Version: 2.0.0 Status: Active Development Last Updated: January 2025
v2.0.0 - Complete Reorganization & Enhancement
v1.0.0 - Initial Release
Built with ❤️ by the UNC-CH GDSC Team