Skip to content

jaymineh/P1_LAMP_Deployment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

43 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

LAMP Stack Deployment - Production-Ready Guide

LAMP Stack Ubuntu Apache MySQL PHP License

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.

πŸ“‹ Table of Contents

🎯 Overview

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.

✨ Features

πŸ”’ Security

  • 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

πŸ’Ύ Backup & Recovery

  • 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

πŸ“Š Monitoring & Logging

  • Health check scripts for service monitoring
  • Log rotation with logrotate
  • Email alerts for critical issues
  • Performance monitoring basics

πŸš€ Performance

  • PHP OPcache for bytecode caching
  • Apache MPM optimization
  • MySQL query optimization and tuning
  • Gzip compression for faster page loads
  • Browser caching configuration

πŸ“± Sample Application

  • 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

πŸ“š Prerequisites

Before starting, you should have:

Required

  • βœ… AWS account (or any Ubuntu server provider)
  • βœ… Basic Linux command line knowledge
  • βœ… SSH client installed
  • βœ… Text editor familiarity (vim, nano, etc.)

Recommended

  • πŸ’‘ Domain name (for SSL setup)
  • πŸ’‘ Basic understanding of web servers
  • πŸ’‘ Familiarity with databases

Server Requirements

  • 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

πŸš€ Quick Start

1. Launch Ubuntu Server

# AWS EC2 t2.micro or t3.micro (free tier eligible)
# Ubuntu 24.04 LTS AMI
# Configure security groups: SSH (22), HTTP (80), HTTPS (443)

2. Connect via SSH

ssh -i your-key.pem ubuntu@your-server-ip

3. Follow Step-by-Step Guide

# 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

4. Deploy Sample Application

# Copy application files to /var/www/yourdomain
# Import database schema
# Configure .env file
# Visit your domain!

πŸ“– Complete walkthrough: project.md

πŸ“ Project Structure

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

πŸ“– Documentation

Main Guide

  • 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

Supporting Documentation

Configuration Files

πŸ’» Sample Application

The included Task Management System demonstrates a complete LAMP stack application:

Features

  • βœ… 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

Technology Stack

  • Frontend: Bootstrap 5, Bootstrap Icons
  • Backend: PHP 8.2+ with PDO
  • Database: MySQL 8.0 with InnoDB
  • Security: Input validation, output escaping, CSRF protection

Screenshots

Application screenshots will be here after deployment

πŸŽ“ What You'll Learn

By completing this project, you'll gain hands-on experience with:

System Administration

  • 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

Web Server Management

  • Apache installation and configuration
  • Virtual host setup
  • SSL/TLS certificate management
  • Security headers implementation
  • Performance optimization

Database Administration

  • MySQL installation and security
  • User and permission management
  • Database backup and restoration
  • Query optimization
  • Performance tuning

Application Development

  • PHP 8.x features and best practices
  • PDO for database connections
  • MVC-style organization
  • Environment variable usage
  • Security best practices

DevOps Practices

  • Automated backup strategies
  • Health monitoring and alerts
  • Log rotation and management
  • Cron job scheduling
  • Disaster recovery planning

🀝 Contributing

Contributions are welcome! If you find issues or have improvements:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/improvement)
  3. Commit your changes (git commit -am 'Add new feature')
  4. Push to the branch (git push origin feature/improvement)
  5. Open a Pull Request

Areas for Contribution

  • Additional security configurations
  • Performance optimization tips
  • More sample applications
  • Docker/container version (separate branch)
  • Terraform/automation scripts (separate branch)
  • Translations
  • Video tutorials

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • 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

πŸ“ž Support


⭐ If this project helped you, please give it a star!

πŸ”— Related Projects:

  • LEMP Stack (Nginx variant)
  • WordPress on LAMP
  • Laravel deployment guide

πŸ“š Learning Resources:

About

DevOps Project

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors