# BookStack Installation and Configuration on wiki.deome.net

#### **Overview**
This page provides a complete guide to setting up BookStack on *wiki.deome.net*, including installation, configuration, database setup, and SSL configuration with Let’s Encrypt.

---

#### **1. Prerequisites**

1. **Web Server**: Apache (refer to the Apache wiki page for installation).
2. **Database**: MariaDB (refer to the MariaDB wiki page for installation and configuration).
3. **PHP**: BookStack requires PHP 7.3 or higher. Install necessary PHP modules.
   ```bash
   sudo apt install php php-mysql php-xml php-mbstring php-zip php-gd -y
   ```

---

#### **2. Download and Install BookStack**

1. **Create the Document Root Directory**:
   - Create a directory for BookStack:
     ```bash
     sudo mkdir -p /var/www/wiki
     ```

2. **Download BookStack**:
   - Navigate to the web root and download the latest version:
     ```bash
     cd /var/www/wiki
     sudo git clone https://github.com/BookStackApp/BookStack.git ./
     sudo git checkout release
     ```

3. **Set File Permissions**:
   - Ensure Apache can read/write to the BookStack files:
     ```bash
     sudo chown -R www-data:www-data /var/www/wiki
     sudo chmod -R 755 /var/www/wiki
     ```

---

#### **3. Configure the Database**

1. **Log in to MariaDB**:
   ```bash
   sudo mysql -u root -p
   ```

2. **Create Database and User**:
   - Create a database for BookStack:
     ```sql
     CREATE DATABASE bookstackdb;
     CREATE USER 'bookstackuser'@'localhost' IDENTIFIED BY 'your_password';
     GRANT ALL PRIVILEGES ON bookstackdb.* TO 'bookstackuser'@'localhost';
     FLUSH PRIVILEGES;
     EXIT;
     ```

---

#### **4. Configure Environment Variables**

1. **Copy the Environment File**:
   - BookStack uses an `.env` file for configuration. Copy the example:
     ```bash
     sudo cp .env.example .env
     ```

2. **Edit the .env File**:
   - Open the `.env` file to configure your database and site settings:
     ```bash
     sudo nano .env
     ```
   - Update the following lines:
     ```env
     # Database configuration
     DB_HOST=localhost
     DB_DATABASE=bookstackdb
     DB_USERNAME=bookstackuser
     DB_PASSWORD=your_password

     # Application URL
     APP_URL=https://wiki.deome.net
     ```

3. **Save and Close**: Press `Ctrl + X`, then `Y`, and `Enter` to save changes.

---

#### **5. Set Up Apache Virtual Host for wiki.deome.net**

1. **Create the Virtual Host File**:
   ```bash
   sudo nano /etc/apache2/sites-available/wiki.deome.net.conf
   ```

2. **Configure the Virtual Host**:
   - Add the following configuration:
     ```apache
     <VirtualHost *:80>
       ServerName wiki.deome.net
       DocumentRoot /var/www/wiki/public
       <Directory /var/www/wiki/public>
           AllowOverride All
           Require all granted
       </Directory>
       ErrorLog ${APACHE_LOG_DIR}/wiki_error.log
       CustomLog ${APACHE_LOG_DIR}/wiki_access.log combined
     </VirtualHost>
     ```

3. **Enable the Site and Rewrite Module**:
   ```bash
   sudo a2ensite wiki.deome.net.conf
   sudo a2enmod rewrite
   sudo systemctl reload apache2
   ```

---

#### **6. Set Up SSL with Let’s Encrypt**

1. **Install Certbot**:
   - If Certbot is not already installed:
     ```bash
     sudo apt install certbot python3-certbot-apache -y
     ```

2. **Generate SSL Certificate**:
   ```bash
   sudo certbot --apache -d wiki.deome.net
   ```

3. **Auto-Renewal Setup**:
   - Certbot will auto-renew SSL certificates by default. To verify:
     ```bash
     sudo certbot renew --dry-run
     ```

---

#### **7. Complete BookStack Setup**

1. **Run the BookStack Installation Commands**:
   - Navigate to the BookStack directory and run the following commands to finish the setup:
     ```bash
     cd /var/www/wiki
     sudo -u www-data php artisan key:generate --force
     sudo -u www-data php artisan migrate --force
     ```

2. **Set Permissions (again, if necessary)**:
   - Ensure permissions are still correct after setup:
     ```bash
     sudo chown -R www-data:www-data /var/www/wiki
     sudo chmod -R 755 /var/www/wiki
     ```

---

#### **8. Testing and Verification**

1. **Access BookStack**:
   - Go to `https://wiki.deome.net` in your web browser.
   - Follow the on-screen instructions to set up the admin account.

2. **Check Logs**:
   - Monitor Apache logs if there are any issues:
     ```bash
     sudo tail -f /var/log/apache2/wiki_access.log
     sudo tail -f /var/log/apache2/wiki_error.log
     ```

---

#### **9. Ongoing Maintenance**

1. **Database Backups**:
   - Set up a cron job to regularly back up the BookStack database:
     ```bash
     mysqldump -u root -p bookstackdb > /path/to/backup/bookstackdb.sql
     ```

2. **Updating BookStack**:
   - Periodically pull the latest updates from the BookStack repository:
     ```bash
     cd /var/www/wiki
     sudo -u www-data git pull origin release
     sudo -u www-data php artisan migrate --force
     ```

---

This setup guide for BookStack covers installation, configuration, and basic maintenance. Let me know if you'd like additional details or specific troubleshooting steps included!