Table of Contents

Information

Prerequisites

Download Source

sudo git clone -b 'feature' 'https://github.com/mybb/mybb.git' '/var/www/forums' && sudo chcon -R -t 'httpd_sys_rw_content_t' '/var/www/forums' && sudo chown -R 'nginx':'nginx' '/var/www/forums' && sync

Database

mysql -u 'root' -p
CREATE DATABASE mybb;
GRANT ALL PRIVILEGES ON mybb.* to 'mybb'@'localhost' IDENTIFIED BY 'x';
FLUSH PRIVILEGES;

nginx + PHP-FPM Configuration

PHP-FPM Socket

sudo -e '/etc/php-fpm.d/forums.conf' && sudo systemctl reload 'php-fpm'
[forums]
user = nginx
group = nginx

listen = /run/php-fpm/forums.sock
listen.owner = nginx
listen.group = nginx
listen.allowed_clients = 127.0.0.1

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on

php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/nginx/session

FastCGI

sudo -e '/etc/nginx/default.d/forums.conf'
location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    try_files $fastcgi_script_name =404;
    set $path_info $fastcgi_path_info;
    fastcgi_param PATH_INFO $path_info;
    include fastcgi.conf;
    fastcgi_intercept_errors on;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param HTTPS on;
    fastcgi_pass unix:/run/php-fpm/forums.sock;
}

Server Block

sudo -e '/etc/nginx/conf.d/forums.conf' && sudo systemctl reload 'nginx'
server {
    listen '443' 'ssl' 'http2';
    server_name 'forums.realmofespionage.xyz';
    root '/var/www/forums';
    index 'index.php';

    include '/etc/nginx/default.d/forums.conf';
    include '/etc/nginx/default.d/restrictions.conf';

    #access_log /var/log/nginx/forums-access.log;
    #error_log /var/log/nginx/forums-error.log;

    location / {
        rewrite ^/forum-([0-9]+)\.html$ /forumdisplay.php?fid=$1;
        rewrite ^/forum-([0-9]+)-page-([0-9]+)\.html$ /forumdisplay.php?fid=$1&page=$2;
        rewrite ^/thread-([0-9]+)\.html$ /showthread.php?tid=$1;
        rewrite ^/thread-([0-9]+)-page-([0-9]+)\.html$ /showthread.php?tid=$1&page=$2;
        rewrite ^/thread-([0-9]+)-lastpost\.html$ /showthread.php?tid=$1&action=lastpost;
        rewrite ^/thread-([0-9]+)-nextnewest\.html$ /showthread.php?tid=$1&action=nextnewest;
        rewrite ^/thread-([0-9]+)-nextoldest\.html$ /showthread.php?tid=$1&action=nextoldest;
        rewrite ^/thread-([0-9]+)-newpost\.html$ /showthread.php?tid=$1&action=newpost;
        rewrite ^/thread-([0-9]+)-post-([0-9]+)\.html$ /showthread.php?tid=$1&pid=$2;
        rewrite ^/post-([0-9]+)\.html$ /showthread.php?pid=$1;
        rewrite ^/announcement-([0-9]+)\.html$ /announcements.php?aid=$1;
        rewrite ^/user-([0-9]+)\.html$ /member.php?action=profile&uid=$1;
        rewrite ^/archive/index.php/forum-([0-9]+)\.html$ /archive/index.php?forum-$1.html;
        rewrite ^/archive/index.php/thread-([0-9]+)\.html$ /archive/index.php?thread-$1.html;
        rewrite ^/archive/index.php/forum-([0-9]+)-([0-9]+)\.html$ /archive/index.php?forum-$1-$2.html;
        rewrite ^/archive/index.php/thread-([0-9]+)-([0-9]+)\.html$ /archive/index.php?thread-$1-$2.html;
    }
}

Initial Setup

Services

Updater

Service

sudo -e '/etc/systemd/system/forums-up.service'
[Service]
User=nginx
Group=nginx
Type=oneshot
ExecStart='/usr/bin/git' -C '/var/www/forums' pull origin 'feature'
ExecStart='/usr/bin/sync'

Timer

sudo -e '/etc/systemd/system/forums-up.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'forums-up.timer' --now && sudo systemctl start 'forums-up' && sudo systemctl status 'forums-up' -l
[Unit]
Description=MyBB Git Updater
After=network-online.target
Wants=network-online.target

[Timer]
OnCalendar=*-*-* 01:55:00
Persistent=true

[Install]
WantedBy=timers.target

Backup

Database Auth

sudo -e '/var/lib/mysqlauth/mybb' && sudo chmod '600' '/var/lib/mysqlauth/mybb'
[mysqldump]
user=mybb
password=x

Service

mkdir -p ~/'backups' && sudo mkdir -p '/var/lib/mysqltmp' && sudo -e '/etc/systemd/system/forums-b.service' && sudo sed -i 's/CHANGEME/'$USER'/g' '/etc/systemd/system/forums-b.service'
[Service]
Type=oneshot
WorkingDirectory=/var/lib/mysqltmp
ExecStart='/usr/bin/mysqldump' --defaults-extra-file='/var/lib/mysqlauth/mybb' --single-transaction 'mybb' -r '/var/lib/mysqltmp/mybb.sql'
ExecStart='/usr/bin/gzip' -f '/var/lib/mysqltmp/mybb.sql'
ExecStart='/usr/bin/bash' -c '"/usr/bin/mv" "/var/lib/mysqltmp/mybb.sql.gz" "/home/CHANGEME/backups/mybb-"$$(date +%%Y-%%m-%%d)".sql.gz"'
ExecStart='/usr/bin/sync'

Timer

sudo -e '/etc/systemd/system/forums-b.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'forums-b.timer' --now && sudo systemctl start 'forums-b' && sudo systemctl status 'forums-b' -l
[Unit]
Description=MyBB Database Backup
After=mariadb.service

[Timer]
OnCalendar=*-*-* 02:00:00
Persistent=true

[Install]
WantedBy=timers.target

Backup

Server

Stop Services

sudo systemctl stop nginx php-fpm

Backup Folder

cd '/var/www' && tar -cvzf ~/'forums-manual.tar.gz' 'forums' && cd ~ && sync

Backup Database

mysqldump --defaults-extra-file='/var/lib/mysqlauth/mybb' --single-transaction 'mybb' -r '~/'mybb-manual.sql' && sync

Start Services

sudo systemctl start nginx php-fpm

Client

Transfer Files To Client

scp espionage724@192.168.1.153:~/'forums-manual.tar.gz' ~/'mybb-manual.sql' ~/'Downloads' && sync'

Restore

Client

Transfer Files To Server

scp ~/'Downloads/forums-manual.tar.gz' ~/'Downloads/mybb-manual.sql' espionage724@192.168.1.153:~

Remove Files

rm ~/'Downloads/forums-manual.tar.gz' ~/'Downloads/mybb-manual.sql' && sync

Server

Stop Services

sudo systemctl stop nginx php-fpm

Remove Previous Folder

sudo rm -Rf '/var/www/forums'

Restore MyBB Folder

cd '/var/www' && sudo tar -xvzf ~/'forums-manual.tar.gz' 'forums' && sudo chcon -R -t 'httpd_sys_rw_content_t' '/var/www/forums' && sudo chown -R 'nginx':'nginx' '/var/www/forums' && cd ~ && sync

Drop Previous Database

mysql -u 'root' -p
DROP DATABASE mybb;
FLUSH TABLES;

Re-create Databases

mysql -u 'root' -p
CREATE DATABASE mybb;

Restore Database

mysql -u 'root' -p 'mybb' < ~/'mybb-manual.sql' && sync

Reapply Permissions

mysql -u 'root' -p
GRANT ALL PRIVILEGES ON mybb.* to 'mybb'@'localhost' IDENTIFIED BY 'x';
FLUSH PRIVILEGES;

Start Services

sudo systemctl start nginx php-fpm

Remove Backups

rm -R ~/'forums-manual.tar.gz' ~/'mybb-manual.sql' && sync