Step-by-Step Guide to Installing Phorum with Nginx on Debian 9

Phorum is a robust, open-source forum software built on PHP and MySQL. This guide will walk you through the comprehensive process of installing Phorum on a Debian 9 system using Nginx as the web server, MariaDB as the database solution, and leveraging acme.sh along with Let’s Encrypt for HTTPS support.

Requirements

Before beginning the installation, ensure that your system meets the following requirements:

  • Nginx
  • PHP version 5.2 or greater
  • MySQL/MariaDB version 5.0 or greater

Prerequisites

  • A Debian 9 operating system.
  • A non-root user with sudo privileges.

Initial Steps

Start by verifying your Debian version:

lsb_release -ds
# Debian GNU/Linux 9.8 (stretch)

Configure the system’s timezone:

sudo dpkg-reconfigure tzdata

Update all system packages to ensure you have the latest versions and the newest security patches:

sudo apt update && sudo apt upgrade -y

Install essential packages required for Debian basic administration:

sudo apt install -y curl wget vim git unzip socat bash-completion apt-transport-https build-essential

Step 1 – Install PHP

Next, install PHP and necessary PHP extensions:

sudo apt install -y php7.0 php7.0-cli php7.0-fpm php7.0-common php7.0-mysql

Verify the PHP modules and version:

php -m
# Modules like ctype, curl, exif, fileinfo, etc. will be displayed.
php --version
# PHP 7.0.33-0debian0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS )

Note that PHP-FPM starts automatically and is enabled on reboot, so no manual startup is required at this stage. Proceed to setting up the database.

Step 2 – Install MariaDB and Create a Database

Install MariaDB database server:

sudo apt install -y mariadb-server

Check the installed MariaDB version:

mysql --version

Run the mysql_secure_installation script to enhance security and set password for the root user:

sudo mysql_secure_installation

Following the prompts, provide answers similar to:

Would you like to setup VALIDATE PASSWORD plugin? N
New password: your_secure_password
Re-enter new password: your_secure_password
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Log in to MariaDB shell as root:

sudo mysql -u root -p
# Enter the root password when prompted

Create a new database and user for Phorum and ensure to remember your credentials:

mariadb> CREATE DATABASE dbname;
mariadb> GRANT ALL ON dbname.* TO 'username'@'localhost' IDENTIFIED BY 'password';
mariadb> FLUSH PRIVILEGES;

Exit the MariaDB shell:

mariadb> exit

Replace dbname, username, and password with your chosen values.

Step 3 – Install acme.sh Client and Obtain Let’s Encrypt Certificate (Optional)

Although not mandatory, securing your forum with HTTPS is recommended. We’ll use acme.sh, a simple UNIX shell-based tool, to obtain Let’s Encrypt TLS certificates.

First, download and install acme.sh:

sudo su - root
git clone https://github.com/Neilpang/acme.sh.git
cd acme.sh
./acme.sh --install --accountemail your_email@example.com
source ~/.bashrc
cd ~

Verify acme.sh installation:

acme.sh --version
# v2.8.0

Issue an RSA and ECC/ECDSA certificate for your domain:

# RSA 2048
acme.sh --issue --standalone -d example.com --keylength 2048
# ECDSA
acme.sh --issue --standalone -d example.com --keylength ec-256

The certificates will be located in:

  • RSA: /home/username/example.com
  • ECC/ECDSA: /home/username/example.com_ecc

Create a directory for storing your certificates:

mkdir -p /etc/letsencrypt/example.com
sudo mkdir -p /etc/letsencrypt/example.com_ecc

Install the certificates using acme.sh:

# RSA
acme.sh --install-cert -d example.com --cert-file /etc/letsencrypt/example.com/cert.pem --key-file /etc/letsencrypt/example.com/private.key --fullchain-file /etc/letsencrypt/example.com/fullchain.pem --reloadcmd "sudo systemctl reload nginx.service"
# ECC/ECDSA
acme.sh --install-cert -d example.com --ecc --cert-file /etc/letsencrypt/example.com_ecc/cert.pem --key-file /etc/letsencrypt/example.com_ecc/private.key --fullchain-file /etc/letsencrypt/example.com_ecc/fullchain.pem --reloadcmd "sudo systemctl reload nginx.service"

The certificates will automatically renew every 60 days. Log back out as the root user:

exit

Step 4 – Install and Configure NGINX

Install NGINX:

sudo apt install -y nginx

Verify the installed NGINX version:

sudo nginx -v
# nginx version: nginx/1.14.0 (Ubuntu)

Configure NGINX for Phorum by creating a new configuration file phorum.conf:

server {
  listen 80;
  listen 443 ssl;
  server_name example.com;
  root /var/www/phorum;
  ssl_certificate /etc/letsencrypt/example.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/example.com/private.key;
  index index.php index.html;

  location / {
    try_files $uri $uri/ /index.php?$query_string;
  }

  location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
  }
}

Enable the new configuration:

sudo ln -s /etc/nginx/sites-available/phorum.conf /etc/nginx/sites-enabled

Check NGINX configuration syntax:

sudo nginx -t

Reload the NGINX service to apply the changes:

sudo systemctl reload nginx.service

Step 5 – Install Phorum

Create a document root directory for Phorum:

sudo mkdir -p /var/www/phorum

Change ownership to your user:

sudo chown -R [your_user]:[your_user] /var/www/phorum

Navigate to the document root:

cd /var/www/phorum

Download the latest stable Phorum release from its official website:

wget https://www.phorum.org/downloads/phorum-5.2.23.tar.gz

Unpack the archive and move contents accordingly:

tar xvzf phorum-5.2.23.tar.gz
rm phorum-5.2.23.tar.gz
mv Core-phorum_5_2_23/* . && mv Core-phorum_5_2_23/.* .
rmdir Core-phorum_5_2_23

Configure database access:

cp include/db/config.php.sample include/db/config.php

Edit the configuration file and adjust the database settings:

vim include/db/config.php

Set the ownership of the Phorum directory to the web server:

sudo chown -R www-data:www-data /var/www/phorum

Complete the installation process by accessing the web-based installer at http://forum.example.com/admin.php in your browser.

Frequently Asked Questions (FAQ)

Q1: Can I install Phorum on a different operating system?
A1: Yes, Phorum can be installed on various Unix-like operating systems. This guide specifically covers the installation on Debian 9.
Q2: Do I need to configure HTTPS?
A2: While not necessary, enabling HTTPS is recommended for enhanced security and to protect data transmitted between your site’s visitors and server.
Q3: What should I do if I encounter errors during installation?
A3: Ensure you’ve followed each step accurately. Consult the community forums or documentation specific to the software pieces you’re working with if there are issues beyond this guide.
Q4: How can I upgrade Phorum to a new version?
A4: Follow Phorum’s official upgrade guides, which typically involve downloading the newer version, backing up your current installation, and following migration steps.