Dennis Ollhoff @ nyxb.nexus

Xenforo 2 on Ubuntu 22.04

Nov 14, 2023 · 10min

This guide walks you through the process of installing XenForo 2, a popular community forum software, on Ubuntu 22.04. Before proceeding, ensure you have a LEMP (Linux, Nginx, MySQL, PHP) stack installed. If you haven’t set up a LEMP stack yet, refer to my previous post on LEMP stack on Ubuntu 22.04.

Prerequisites

  • A server running Ubuntu 22.04
  • A LEMP stack installed
  • Access to a terminal or command-line interface
  • Basic knowledge of Linux and MySQL

Step 1: Update Your System

Start by updating your system to ensure all existing packages are up to date:

sudo apt update
sudo apt upgrade

Step 2: Install Required PHP Extensions

XenForo 2 requires certain PHP extensions to function properly. Install the necessary extensions using the following commands:

sudo apt install php-mysqli php-gd php-json php-curl php-xml php-zip -y

This will install the MySQLi, GD (with JPEG support), cURL, and XML handling (DOM and SimpleXML) PHP extensions.

Note: The extensions PCRE, SPL, iconv, and ctype are usually included in the standard PHP installation.

Step 3: Download XenForo 2

  1. Purchase and download the latest version of XenForo 2 from the official XenForo website.
  2. Upload the downloaded ZIP file to your server.
  3. Unzip the XenForo files in your desired directory, for example, /var/www/html/

Uploading the ZIP File to Your Server

To upload the ZIP file, you can use an SFTP client like FileZilla, or the scp command from the command line for Unix-based systems or Windows Subsystem for Linux (WSL).

Using FileZilla (Windows/Mac/Linux):

  1. Download and install FileZilla from the official FileZilla website.
  2. Connect to your server using the server’s IP address, SSH username, and password (or SSH key).
  3. Navigate to the local directory where the XenForo ZIP file is located.
  4. Drag and drop the file into the desired directory on your server.

Using scp (Unix-based/WSL):

  1. Open a terminal on your local machine.
  2. Navigate to the directory where the XenForo ZIP file is located.
  3. Use the scp command to transfer the file to your server:
scp path/to/xenforo.zip username@your_server_ip:/path/to/server/directory

Replace path/to/xenforo.zip with the path to your XenForo ZIP file, username with your SSH username, your_server_ip with your server’s IP address, and /path/to/server/directory with the directory on your server where you want to upload the file.

Unzipping the XenForo Files

After uploading the ZIP file to your server, you need to unzip it in your desired directory. Here’s how:

  1. SSH into your server:
ssh username@your_server_ip
  1. Navigate to the directory where you uploaded the XenForo ZIP file.
  2. Use the unzip command to extract the files. If unzip is not installed, you can install it using sudo apt install unzip.
sudo apt install unzip
unzip xenforo.zip -d /var/www/html

Replace xenforo.zip with the name of your ZIP file and /var/www/html with your desired directory.

Setting Correct Permissions

After unzipping, you should set the correct permissions for the XenForo directory:

sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html

This sets the owner to www-data (the default web server user on Ubuntu) and sets the appropriate permissions for the files and directories.

Step 4: Create a MySQL Database

XenForo requires a database to store its data. Create a MySQL database and user for XenForo:

login to MySQL:

sudo mysql

Create a database and user:

CREATE DATABASE xenforo_db;
CREATE USER 'xenforo_user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON xenforo_db.* TO 'xenforo_user'@'localhost';
FLUSH PRIVILEGES;
exit

Remember to replace xenforo_db, xenforo_user, and password with your preferred database name, username, and password.

Step 5: Configure DNS Records

Before installing the SSL certificate, configure the DNS records with your domain registrar:

  1. A Record: This points your domain to your server’s IP address.

    • Name: @
    • Type: A
    • Value: Your_Server_IP
    • TTL: 3600 or as per your registrar’s default setting
  2. CNAME Record: This is for the 'www' version of your domain.

    • Name: www
    • Type: CNAME
    • Value: example.com (Replace with your domain)
    • TTL: 3600 or as per your registrar’s default setting

Replace Your_Server_IP with the IP address of your server and example.com with your actual domain name.

Wait for the DNS changes to propagate, which can take anywhere from a few minutes to 48 hours.

Step 6: Configure Nginx for XenForo

Create a new Nginx server block or edit an existing one for your XenForo site:

sudo nano /etc/nginx/sites-available/xenforo

Add the following configuration:

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com; # Replace with your domain name

    root /var/www/html; # Replace with your XenForo directory
    index index.php index.html index.htm;

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; # Change to match your PHP version
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Remember to replace example.com and /var/www/html with your actual domain name and XenForo directory.

Adjust Maximum File Upload Size in Nginx

To allow file uploads of up to 1 GB, you need to increase the client_max_body_size in Nginx:

  1. Open your Nginx configuration file:
sudo nano /etc/nginx/nginx.conf

or your specific site configuration:

sudo nano /etc/nginx/sites-available/xenforo
  1. Add or modify the client_max_body_size directive:
http {
   ...
   client_max_body_size 1024M;
   ...
}
  1. Save and close the file.
  2. Test the Nginx configuration for errors:
sudo nginx -t

This will allow your Nginx server to handle file uploads up to 1 GB.

Enable the Nginx Configuration

Enable your Nginx configuration and restart Nginx:

sudo ln -s /etc/nginx/sites-available/xenforo /etc/nginx/sites-enabled/
sudo systemctl restart nginx

Step 7: Install Let’s Encrypt SSL Certificate

Use Certbot to install a free SSL certificate from Let’s Encrypt:

  1. Install Certbot and its Nginx plugin:
sudo apt install certbot python3-certbot-nginx -y
  1. Obtain and install the SSL certificate:
sudo certbot --nginx -d example.com -d www.example.com

Replace example.com and www.example.com with your domain name.

  1. Certbot will modify your Nginx configuration to use the SSL certificate and set up automatic renewal.

Verify SSL Configuration

After configuring SSL, it’s a good idea to test your SSL configuration:

  1. Visit your website using https://example.com and ensure that it loads correctly.
  2. You can also use online tools like SSL Labs’ SSL Test to check your SSL certificate and configuration.

Step 8: Final Steps and Testing

  1. Restart Nginx: Ensure all your configurations are correctly loaded:
sudo systemctl restart nginx
  1. Test Your Site: Now, navigate to your website using your domain name. You should be able to access XenForo through a secure HTTPS connection.

  2. XenForo Setup: Complete the XenForo installation by following the on-screen instructions when you first visit your forum’s URL.

Tips If you want to install addons via zip archive you have to edit:
sudo nano /var/www/html/src/config.php

and enter $config['enableAddOnArchiveInstaller'] = true; there.

Conclusion

You have now successfully set up XenForo 2 on Ubuntu 22.04 with a secure SSL certificate from Let’s Encrypt. Your forum is now accessible via HTTPS, and your SSL certificate will automatically renew.

> comment on mastodon / twitter
>
CC BY-NC-SA 4.0 2023-PRESENT © Dennis Ollhoff