A comprehensive, production-ready guide for deploying a modern LAMP (Linux, Apache, MySQL, PHP) stack on Ubuntu with security best practices, automated backups, monitoring, and a fully functional sample application.
- Overview
- Features
- Prerequisites
- Quick Start
- Project Structure
- Documentation
- Sample Application
- What You'll Learn
- Contributing
- License
This project provides a hands-on, educational guide to deploying a production-ready LAMP stack on AWS EC2 (or any Ubuntu server). It goes beyond basic installation to include:
- Modern Software: PHP 8.2/8.3, MySQL 8.0/MariaDB 10.11+, Ubuntu 24.04 LTS
- Security Hardening: SSL/TLS, UFW firewall, fail2ban, SSH hardening
- Automation: Automated backups, health monitoring, log rotation
- Best Practices: Environment variables, prepared statements, proper permissions
- Real Application: Fully functional PHP CRUD application demonstrating the stack
This is NOT a containerized or automated deployment tool. It's designed for hands-on learning of Linux server administration, teaching you the "why" behind each configuration decision.
- SSL/TLS encryption with Let's Encrypt (automated certificate renewal)
- UFW firewall configuration for network security
- fail2ban intrusion prevention system
- SSH hardening (key-based auth, root login disabled)
- Security headers (HSTS, XSS Protection, etc.)
- Prepared SQL statements to prevent injection attacks
- Automated MySQL backups with retention policies
- AWS S3 integration for offsite backup storage
- Database restore scripts with verification
- Cron-based scheduling for hands-free operation
- Health check scripts for service monitoring
- Log rotation with logrotate
- Email alerts for critical issues
- Performance monitoring basics
- PHP OPcache for bytecode caching
- Apache MPM optimization
- MySQL query optimization and tuning
- Gzip compression for faster page loads
- Browser caching configuration
- Task Management System built with PHP
- Full CRUD operations (Create, Read, Update, Delete)
- Bootstrap UI for modern, responsive design
- Environment-based configuration (.env file)
- Database schema and sample data included
Before starting, you should have:
- β AWS account (or any Ubuntu server provider)
- β Basic Linux command line knowledge
- β SSH client installed
- β Text editor familiarity (vim, nano, etc.)
- π‘ Domain name (for SSL setup)
- π‘ Basic understanding of web servers
- π‘ Familiarity with databases
- OS: Ubuntu 22.04 or 24.04 LTS
- RAM: 1GB minimum (2GB+ recommended)
- Storage: 20GB minimum
- Network: Public IP address
π Detailed setup instructions: docs/prerequisites.md
# AWS EC2 t2.micro or t3.micro (free tier eligible)
# Ubuntu 24.04 LTS AMI
# Configure security groups: SSH (22), HTTP (80), HTTPS (443)ssh -i your-key.pem ubuntu@your-server-ip# Clone this repository (or download documentation)
# Follow project.md for complete walkthrough
# Or jump to specific sections:
# - Initial Server Setup
# - Install Apache, MySQL, PHP
# - Configure Security
# - Deploy Sample Application
# - Setup Backups & Monitoring# Copy application files to /var/www/yourdomain
# Import database schema
# Configure .env file
# Visit your domain!π Complete walkthrough: project.md
P1_LAMP_Deployment/
βββ README.md # This file
βββ project.md # Main step-by-step deployment guide
βββ CHANGELOG.md # Version history
βββ LICENSE # MIT License
βββ .gitignore # Git ignore rules
βββ .env.example # Environment variables template
β
βββ docs/ # Additional documentation
β βββ prerequisites.md # AWS setup, security groups, SSH
β βββ architecture.md # System architecture & components
β βββ troubleshooting.md # Common issues & solutions
β
βββ configs/ # Configuration templates
β βββ apache-vhost.conf # Apache virtual host template
β βββ php.ini # PHP configuration customizations
β βββ my.cnf # MySQL tuning parameters
β
βββ scripts/ # Helper scripts
β βββ backup.sh # Automated MySQL backup
β βββ restore.sh # Database restoration
β βββ health-check.sh # Service monitoring
β βββ setup-ssl.sh # SSL certificate automation
β
βββ app/ # Sample PHP application
βββ .env.example # App configuration template
βββ config/
β βββ database.php # Database connection
βββ includes/
β βββ functions.php # Helper functions
βββ public/ # Web root
β βββ index.php # Task list (Read)
β βββ create.php # Create task
β βββ read.php # View task details
β βββ update.php # Edit task
β βββ delete.php # Delete task
βββ sql/
βββ schema.sql # Database schema
- project.md - Complete deployment walkthrough (10 sections)
- Section 1: Initial Server Setup & Security
- Section 2: Apache Installation & Configuration
- Section 3: MySQL Setup & Hardening
- Section 4: PHP Installation & Optimization
- Section 5: Virtual Host Configuration
- Section 6: SSL/TLS with Let's Encrypt
- Section 7: Application Deployment
- Section 8: Backups & Monitoring
- Section 9: Performance Tuning
- Section 10: Testing & Verification
- docs/prerequisites.md - AWS setup, EC2 launch, SSH access
- docs/architecture.md - Architecture diagrams, component descriptions
- docs/troubleshooting.md - Common issues, debug commands, log locations
- configs/apache-vhost.conf - Apache virtual host with security headers
- configs/php.ini - PHP optimizations and security settings
- configs/my.cnf - MySQL performance tuning
The included Task Management System demonstrates a complete LAMP stack application:
- β Create, Read, Update, Delete (CRUD) operations
- β Task filtering and search
- β Priority levels (Low, Medium, High)
- β Status tracking (Pending, In Progress, Completed)
- β Due date management
- β Responsive Bootstrap UI
- β Secure database operations (prepared statements)
- β Environment-based configuration
- Frontend: Bootstrap 5, Bootstrap Icons
- Backend: PHP 8.2+ with PDO
- Database: MySQL 8.0 with InnoDB
- Security: Input validation, output escaping, CSRF protection
Application screenshots will be here after deployment
By completing this project, you'll gain hands-on experience with:
- Linux server setup and user management
- SSH key-based authentication
- Firewall configuration (UFW)
- Service management with systemd
- File permissions and ownership
- Log management and rotation
- Apache installation and configuration
- Virtual host setup
- SSL/TLS certificate management
- Security headers implementation
- Performance optimization
- MySQL installation and security
- User and permission management
- Database backup and restoration
- Query optimization
- Performance tuning
- PHP 8.x features and best practices
- PDO for database connections
- MVC-style organization
- Environment variable usage
- Security best practices
- Automated backup strategies
- Health monitoring and alerts
- Log rotation and management
- Cron job scheduling
- Disaster recovery planning
Contributions are welcome! If you find issues or have improvements:
- Fork the repository
- Create a feature branch (
git checkout -b feature/improvement) - Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/improvement) - Open a Pull Request
- Additional security configurations
- Performance optimization tips
- More sample applications
- Docker/container version (separate branch)
- Terraform/automation scripts (separate branch)
- Translations
- Video tutorials
This project is licensed under the MIT License - see the LICENSE file for details.
- Ubuntu Community for excellent documentation
- Apache Software Foundation
- MySQL and MariaDB teams
- PHP community
- Let's Encrypt for free SSL certificates
- All contributors and users of this guide
- Issues: GitHub Issues
- Documentation: Check docs/ directory
- Troubleshooting: See docs/troubleshooting.md
β If this project helped you, please give it a star!
π Related Projects:
- LEMP Stack (Nginx variant)
- WordPress on LAMP
- Laravel deployment guide
π Learning Resources: