Files
linux-sysadmin-journey/projects/01-homelab-setup/service-deployment.md
T
2025-02-09 01:25:38 -06:00

3.4 KiB

Service Deployment Documentation

Overview

This document tracks the setup and configuration of web and database services on our Ubuntu Server VM.

Web Server Setup

1. Apache Installation and Basic Configuration

# Update package list
sudo apt update

# Install Apache
sudo apt install apache2

# Check service status
sudo systemctl status apache2

# Allow HTTP through firewall
sudo ufw allow 'Apache Full'

Installation Status

  • Apache installed and running
  • Default page accessible
  • Firewall configured for HTTP/HTTPS

Configuration Plan

  1. Basic Setup

    • Install Apache
    • Configure firewall
    • Test default page
    • Set up virtual hosts
  2. Security Hardening

    • Configure SSL/TLS
    • Set up mod_security
    • Configure proper permissions
    • Implement best practices
  3. Performance Tuning

    • Optimize Apache configuration
    • Enable caching
    • Configure logging

2. Virtual Hosts Configuration

# Create directory structure
sudo mkdir -p /var/www/your-domain
sudo chown -R $USER:$USER /var/www/your-domain
sudo chmod -R 755 /var/www/your-domain

# Create sample page
sudo nano /var/www/your-domain/index.html

Sample index.html content:

<!DOCTYPE html>
<html>
<head>
    <title>Welcome to Your Domain</title>
</head>
<body>
    <h1>Success! Your virtual host is working!</h1>
</body>
</html>

Create virtual host configuration:

# Create new virtual host file
sudo nano /etc/apache2/sites-available/your-domain.conf

Virtual host configuration:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName your-domain
    ServerAlias www.your-domain
    DocumentRoot /var/www/your-domain
    ErrorLog ${APACHE_LOG_DIR}/your-domain_error.log
    CustomLog ${APACHE_LOG_DIR}/your-domain_access.log combined
</VirtualHost>

Enable the site:

# Enable virtual host
sudo a2ensite your-domain.conf

# Disable default site (optional)
sudo a2dissite 000-default.conf

# Test configuration
sudo apache2ctl configtest

# Reload Apache
sudo systemctl reload apache2

3. Apache Basic Security

# Basic security configurations
sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.bak

# Secure directory permissions
sudo chown -R root:root /etc/apache2
sudo chmod -R 644 /etc/apache2
sudo find /etc/apache2 -type d -exec chmod 755 {} \;

Database Server Setup

1. MySQL Installation and Initial Setup

# Install MySQL
sudo apt install mysql-server

# Check service status
sudo systemctl status mysql

# Run security script
sudo mysql_secure_installation

2. Database and User Setup

# Access MySQL as root
sudo mysql

# Inside MySQL prompt:

# Create new database
CREATE DATABASE homelab;

# Create new user
CREATE USER 'admin'@'localhost' IDENTIFIED BY 'Password123!';

# Grant privileges
GRANT ALL PRIVILEGES ON homelab.* TO 'admin'@'localhost';
FLUSH PRIVILEGES;

# Verify setup

SHOW DATABASES;
SELECT user,host FROM mysql.user;

Implementation Status

  • Web Server
    • Basic Installation
    • Security Configuration
    • Performance Optimization
  • Database Server
    • Basic Installation
    • Security Setup
    • User Management

Service Configuration Status

  • Apache
    • Installation
    • Basic Security
  • MySQL
    • Installation
    • Root Password
    • Database Users