# Apache Web Server Installation and Configuration

### **Apache Web Server Installation and Configuration**

#### **Overview**
This page provides instructions for setting up and configuring Apache on *buzz.deome.net*. It includes steps for installing Apache, configuring virtual hosts for multiple sites, securing with SSL certificates, and basic performance tuning.

---

#### **1. Apache Installation**

1. **Update System Packages**:
   - Start by updating the package list and upgrading existing packages:
     ```bash
     sudo apt update && sudo apt upgrade -y
     ```

2. **Install Apache**:
   - Install Apache with the following command:
     ```bash
     sudo apt install apache2 -y
     ```

3. **Start and Enable Apache**:
   - Start the Apache service and enable it to run on boot:
     ```bash
     sudo systemctl start apache2
     sudo systemctl enable apache2
     ```

4. **Verify Installation**:
   - Check the Apache status to ensure it’s running:
     ```bash
     sudo systemctl status apache2
     ```

---

#### **2. Basic Apache Configuration**

1. **Main Configuration File**:
   - The main Apache configuration file is located at:
     ```bash
     /etc/apache2/apache2.conf
     ```

2. **Enable Recommended Modules**:
   - Enable commonly used modules:
     ```bash
     sudo a2enmod rewrite ssl headers
     ```
   - Restart Apache to apply the changes:
     ```bash
     sudo systemctl restart apache2
     ```

---

#### **3. Setting Up Virtual Hosts**

1. **Create a New Virtual Host**:
   - For each site, create a configuration file in `/etc/apache2/sites-available/`. For example, for *wiki.deome.net*:
     ```bash
     sudo nano /etc/apache2/sites-available/wiki.deome.net.conf
     ```
   - Add the following configuration:
     ```apache
     <VirtualHost *:80>
       ServerName wiki.deome.net
       DocumentRoot /var/www/wiki
       <Directory /var/www/wiki>
           AllowOverride All
       </Directory>
       ErrorLog ${APACHE_LOG_DIR}/wiki_error.log
       CustomLog ${APACHE_LOG_DIR}/wiki_access.log combined
     </VirtualHost>
     ```

2. **Enable the Virtual Host**:
   - Use `a2ensite` to enable each virtual host:
     ```bash
     sudo a2ensite wiki.deome.net.conf
     ```
   - Reload Apache to apply changes:
     ```bash
     sudo systemctl reload apache2
     ```

3. **Repeat for Additional Sites**:
   - Create similar configuration files for *gallery.deome.net*, *buzz.deome.net*, and any other sites you plan to host.

---

#### **4. SSL Configuration with Let’s Encrypt**

1. **Install Certbot**:
   - Install Certbot to automate SSL certificate generation:
     ```bash
     sudo apt install certbot python3-certbot-apache -y
     ```

2. **Generate SSL Certificates**:
   - Use Certbot to obtain SSL certificates for each virtual host:
     ```bash
     sudo certbot --apache -d wiki.deome.net
     sudo certbot --apache -d gallery.deome.net
     ```
   - Certbot will automatically configure SSL for the specified domains.

3. **Set Up Auto-Renewal**:
   - To ensure certificates renew automatically:
     ```bash
     sudo certbot renew --dry-run
     ```

---

#### **5. Performance and Optimization**

1. **Adjust Apache Settings**:
   - Open the main Apache configuration file:
     ```bash
     sudo nano /etc/apache2/apache2.conf
     ```
   - Consider modifying these settings under the `mpm_prefork_module` or `mpm_worker_module`:
     ```apache
     KeepAlive On
     MaxKeepAliveRequests 100
     KeepAliveTimeout 5
     ```

2. **Enable Caching**:
   - Install and enable Apache caching modules if desired:
     ```bash
     sudo a2enmod cache
     sudo a2enmod cache_disk
     sudo systemctl restart apache2
     ```

3. **Optimize Logging**:
   - Adjust log levels or configure centralized logging if needed. Logging configuration is in each virtual host file and `/etc/apache2/apache2.conf`.

---

#### **6. Maintenance and Monitoring**

1. **Monitor Apache Status**:
   - Check Apache’s status periodically:
     ```bash
     sudo systemctl status apache2
     ```

2. **Check Logs**:
   - Access logs for each virtual host in `/var/log/apache2/`, e.g.:
     ```bash
     sudo tail -f /var/log/apache2/wiki_access.log
     sudo tail -f /var/log/apache2/wiki_error.log
     ```

3. **Restarting Apache**:
   - Restart Apache after any configuration changes:
     ```bash
     sudo systemctl restart apache2
     ```

---

This wiki page provides a thorough guide for Apache installation, virtual host setup, SSL configuration, and performance tuning. Let me know if you’d like any additional details or further customization for your setup!