Create a forum with phpBB3 on Debian

In this guide, we will show you how to install and configure the latest version of the phpBB3 platform on Debian 11 to create a free online forum website.

phpBB3 is a powerful and flexible open-source bulletin board software platform written primarily in the PHP programming language and commonly used on Linux with Apache/Nginx web servers, PHP, and the MySQL/MariaDB database management system, also known as the LAMP or LEMP stack.

The phpBB3 online forum software platform is widely used online for online forums and discussion boards.

Requirements

  • Debian 11 minimal installation on a bare metal server machine or on a virtual private server
  • sudo root privileges for a local or remote account, or direct access to the root account
  • A static IP address configured for one of your system's network cards
  • A private or public domain name, depending on your deployment, with the correct DNS records for web services. If you don't have a valid or registered domain name, you can install and access the site using your server's IP address
  • If you want to use the website registration, topic moderation and other features of the forum, you should have a running mail server on your premises, properly configured and providing remote access to its IMAP and SMTP services

Prerequisites

Before you start installing and configuring phpBB3t from your own server's sources, you must ensure that the system meets all the software requirements for compiling and installing the application.

The first step is to update your system's repositories and software packages by running the following command with root privileges.

su -
apt update
apt upgrade

The next step is to run the following command to install some necessary utilities to manage your system from the command line further.

apt install wget bash-completion zip unzip

After the system has been fully upgraded and the necessary utilities to manage your server have been installed, set up the name for your system by running the following command. Replace your hostname variable accordingly.

hostnamectl set-hostname www.myforum.com

Check the hostname of the machine and the hosts file by running the following commands.

hostnamectl
cat /etc/hostname
hostname –s
hostname –f

Finally, you will need to restart the Debian server so that the kernel updates and hostname changes are applied correctly.

systemctl reboot

phpBB3 is a web-based CMS bulletin platform written in the PHP server-side programming language. In order to run the application's PHP file scripts, a web server such as the Apache HTTP server and a PHP interpreter must be installed and operational in the system.

To install the Apache web server and PHP interpreter along with all the necessary PHP modules that the application needs to run properly, enter the following command in your server console

apt install apache2 libapache2-mod-php7.4 php7.4 php7.4-gd php7.4-opcache php7.4-json php7.4-mbstring php-imagick php7.4-xml

After installing Apache and PHP, verify that the web server is running and listening for network connections on port 80 by entering the following command with root privileges.

netstat –tlpn

If the netstat network utility is not installed by default on your Debian system, run the following command to install it.

apt install net-tools

From the netstat command output, you can see that the Apache web server is listening for incoming network connections on port 80. You can also use the ss command for the same task, which is automatically installed in Debian.

ss- tulpn

If you have a firewall enabled in your system, such as the UFW firewall application, you should add a new rule to allow HTTP traffic through the firewall by typing the following command.

ufw allow WWW

or

ufw allow 80/tcp

If you are using iptables raw rules to manage the firewall rules on your Debian server, add the following rule to allow incoming traffic on port 80 to allow visitors to browse the online store

apt-get install -y iptables-persistent
iptables -I INPUT -p tcp --destination-port 80 -j ACCEPT
iptables -I INPUT -p tcp --destination-port 22 -j ACCEPT
netfilter-persistent save
systemctl restart netfilter-persistent
systemctl status netfilter-persistent
systemctl enable netfilter-persistent.service

Next, enable the following Apache modules that the application needs to run properly and apply them by typing the following command

a2enmod rewrite
systemctl restart apache2

Finally, test if the default Apache web page can be displayed in your clients' browsers by calling the IP address of your Debian machine or the FQDN of your domain or server using the HTTP protocol, as shown in the following figure. If you do not know the IP address of your machine, you can run the ifconfig or ip a commands to find out the IP address of your server.

http://your_domain.tld

To install and access the phpBB3 web administration panel and frontend website using the HTTPS protocol that secures traffic for your clients, enter the following command to enable the Apache web server SSL module and SSL site configuration file

a2enmod ssl
a2ensite default-ssl.conf

Next, open the Apache default SSL site configuration file with a text editor and enable the URL rewrite rules by inserting the following lines of code after the DocumentRoot directive, as shown in the following example:

nano /etc/apache2/sites-enabled/default-ssl.conf

Excerpt from the SSL site configuration file:

<Directory /var/www/html>
  Options +FollowSymlinks
  AllowOverride All
  Require all granted
</Directory>

Also, change the VirtualHost line to look like the following excerpt:

      <VirtualHost *:443>

Close the SSL Apache file and open the /etc/apache2/sites-enabled/000-default.conf file for editing and add the same URL rewrite rules as for the SSL configuration file. Add the lines of code after the DocumentRoot statement, as shown in the following example.

<Directory /var/www/html>
  Options +FollowSymlinks
  AllowOverride All
  Require all granted
</Directory>

Finally, you restart the Apache daemon to apply all the rules configured so far and visit your domain using the HTTP protocol. Since you are using the self-signed certificate pairs automatically issued by Apache during installation, which are not trusted by the browser, an error warning should be displayed in the browser.

systemctl restart apache2

https://yourdomain.tld

Accept the warning to accept the untrusted certificate and continue to be redirected to the default Apache website, as shown in the following image.

If the UFW firewall application blocks incoming network connections to the HTTPS port, you should add a new rule to allow HTTPS traffic through the firewall by entering the following command.

ufw allow ‘WWW Full’

or

ufw allow 443/tcp

If iptables is the default firewall application installed to protect your Debian system at the network level, add the following rule to allow incoming traffic through port 443 in the firewall to allow visitors to browse your domain name.

iptables -I INPUT -p tcp --destination-port 443 -j ACCEPT
netfilter-persistent save
systemctl restart netfilter-persistent
systemctl status netfilter-persistent

In the next step, we need to make some more changes to the PHP default configuration file to ensure that the following PHP variables are enabled and the PHP timezone setting is configured correctly and matches the geographic location of your system. Open the /etc/php/7.4/apache2/php.ini file for editing and make sure the following lines are set. Also, create a backup of the PHP configuration file first.

cp /etc/php/7.4/apache2/php.ini{,.backup}
nano /etc/php/7.4/apache2/php.ini

Find, edit, and change the following variables in the php.ini configuration file:

file_uploads = On
default_charset = UTF-8
memory_limit = 128M
max_execution_time = 18000
upload_max_filesize = 100M
date.timezone = Europe/London

Increase the upload_max_file_size variable to support large file attachments, and replace the time.zone variable according to your physical time by consulting the list of timezones provided by the PHP Docs at the following link http://php.net/manual/en/timezones.php

If you want to increase the loading speed of your web pages via the OPCache plugin available for PHP7, add the following OPCache settings to the end of the PHP interpreter configuration file below the [opcache] statement:

opcache.enable=1 
opcache.enable_cli=1 
opcache.interned_strings_buffer=8 
opcache.max_accelerated_files=10000 
opcache.memory_consumption=128 
opcache.save_comments=1
opcache.revalidate_freq=1

Close the php.ini configuration file and check the end of the PHP configuration file to see if the variables were added correctly by typing the following command

tail /etc/php/7.0/apache2/php.ini

After you have made all the changes described above, restart the Apache daemon to apply the new changes by entering the following command.

systemctl restart apache2

Finally, create a PHP info file by running the following command, and verify that the PHP time zone is configured correctly by accessing the PHP info file in a browser at the following URL, as shown in the following figure. Scroll down to the Date setting to verify the PHP timezone configuration.

echo '<?php phpinfo(); ?>'| tee /var/www/html/info.php

https://domain.tld/info.php

The phpBB3 web application stores various configurations, such as users, sessions, contacts, products, catalogs and others, in an RDBMS database. This tutorial will configure the phpBB3 forum application to use the MariaDB database as a backend. Enter the following command to install the MariaDB database and the PHP module needed to access the mysql database

apt install mariadb-server php7.4-mysql mariadb-client

After installing MariaDB, verify that the daemon is running and listening for connections on localhost, port 3306, by running the netstat command.

netstat –tlpn | grep mysql

Then log in to the MySQL console and secure the MariaDB root account by entering the following commands

mysql -h localhost
Welcome to MariaDB Monitor.  Commands end with ; or \g.
Your MariaDB connection identifier is 2

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to delete the current input statement.

MariaDB [(none)]> Use mysql;
Read table information to complete table and column names
You can use this function for a faster start with -A

Database modified
MariaDB [mysql]>

update user set plugin='' where user='root';
Query OK, 1 line affected (0.00 sec)
Rows matched: 1  Modified: 1  Warnings: 0

MariaDB [mysql]> flush permissions;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> exit
Bye

In the next step, you secure MariaDB by running the script mysql_secure_installation included in the installation packages from the Debian Stretch repositories. While running the script, it asks a series of questions to secure the MariaDB database, such as: changing the MySQL root password, removing anonymous users, disabling remote root logins, and deleting the test database. Run the script using the following command and make sure you answer yes to all questions to secure the MySQL daemon fully. Use the following excerpt from the script as a guide.

mysql_secure_installation


If the password is provided, the login process to the MySQL console should be granted, as shown in the command example:

mysql -h localhost -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection identifier is 15
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to delete the current input statement.
MariaDB [(none)]> exit
Bye

Next, log in to the MariaDB database console, create a database for the application and a user with a password that will be used to manage the application database by entering the following commands. Replace the database name, user, and password accordingly.

mysql –u root -p
MariaDB [(none)]> create database myphpbb;
MariaDB [(none)]> grant all privileges on myphpbb.* to 'phpbb_user'@'localhost' identified by 'password1234';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit

To apply all the changes made so far, restart MySQL and the Apache daemons and verify that the daemons are running by entering the following commands.

systemctl restart mysql apache2
systemctl status mysql apache2

Install phpBB

Once all the system requirements for installing the forum application are met, visit the official phpBB3 download page at https://www.phpbb.com/downloads/ and get the latest compressed zip package into your system using the following command.

wget https://www.phpbb.com/files/release/phpBB-3.2.1.zip
--2017-12-04 19:43:17--  https://www.phpbb.com/files/release/phpBB-3.2.1.zip
Resolution www.phpbb.com (www.phpbb.com)... 140.211.15.244
Connection to www.phpbb.com (www.phpbb.com)|140.211.15.244|:443... Established
HTTP request sent, awaiting response.... 200 OK
Length: 7767156 (7.4M) [application/zip]
Save in: ‘phpBB-3.2.1.zip’

phpBB-3.2.1.zip                100%[=================================================>]   7.41M  2.12MB/s    in 3.5s

After completing the zip archive download, unzip the phpBB3 zip archive file to your current working directory and list the unzipped files using the following commands. Also, remove the index.html file installed by default by the Apache web server from the webroot path and delete the info.php file created earlier.

extract phpBB-3.2.1.zip
ls
rm /var/www/html/index.html
rm /var/www/html/info.php

The installation files for phpBB3 are located in your current working directory in the phpBB3/ directory. Issue the ls command to list the files in that directory. Copy the entire contents of the unzipped directory to the root of your web server by running the following command. Also, make sure you copy the hidden .htaccess file to the webroot path.

cp -rf phpBB3/* /var/www/html/
cp -rf phpBB3/.htaccess /var/www/html/

Next, run the following commands to grant the Apache runtime user full write permissions to the web root path. Use the ls command to list the permissions for the application's installed files in the /var/www/html/ directory.

chown -R www-data:www-data /var/www/html/
ls –al /var/www/html/

Next, proceed with installing the phpBB3 forum application by opening a browser and clicking on the IP address or domain name of your server or the FQDN of the server using the HTTPS protocol. On the first installation screen, the phpBB3 installer will display an introductory message containing general information about the platform. Click on the Install tab at the top to start the installation process, as shown in the example below.

https://yourdomain.tld

Next, the installer will check your system requirements and display a welcome message with a list of databases phpBB3 supports. To start the web configuration, click the Install button in the screenshot below.

On the next screen, add an administrator username and administrator account email address, and set a secure password for the forum administrator account. When you are done, click the "Submit" button to continue.

On the next installation screen, select MySQL with the MySQLi extension as the database type and specify the MySQL database server address, port number, username and password needed to access the phpBB3 database, as well as the database name created for the phpBB3 installation. Also, add a prefix for the database table and click the Next button to proceed to the next installation screen. Use the following screenshot as a guide for configuring this step.

Next, set the "Cookie" and "Force Server URL" options to NO, use https:// as the server protocol, check the "Domain Name" variable, use 443 as the server port, and the script path pointing to your server's webroot tree (“/”). Click the Submit button to complete this installation step, as shown in the following image.

On the next screen, you can select the "Enable board-wide emails" option and the SMTP server details of your forum website. This step assumes that a domain mail server has been properly configured and commissioned at your site. If you don't have a mail server configured for your domain yet, select the "Disable board-wide emails" and "Don't use SMTP server for emails" option and click "Submit."

On the next installation screen, you will choose the default language for your website forum, the title of the board, and a brief description of the board. Once you've completed this step, click the Submit button to start the installation process.

The installation process is completed after the database structure is imported and all forum settings are written to the application configuration file. The installer will display a Take me to the APC link, which you can use to access the phpBB3 Backed Administration Cool Panel to manage your online bulletin board.

Before logging into your forum's admin panel, go back to the server console and enter the following commands to delete the installation directory and secure phpBB3 system configuration file.

rm -rf /var/www/html/install/
chown root:root /var/www/html/configure.php

To manage your forum, click on the Take me to the APC link to access the forum admin backend, as shown in the following image.

You can also visit the forum control panel by navigating to the /adm/ URL link to your server IP address or domain name using the HTTPS protocol. Use the credentials you set during installation to log in to the backend of the forum, as shown in the screenshot below.

https://yourdomain.tld/adm/

To visit the front-end of your online forum application, navigate to your server IP address or domain name using the HTTPS protocol. The frontend main page of your forum should display correctly in the browser.

https://yourdomain.tld

To force visitors to visit the front-end web page of the forum and securely access the back-end interface using the HTTPS protocol, which encrypts traffic between the server and client browsers, return to your server's terminal and edit the .htaccess file located in the root directory of your web page document by entering the following command.

nano /var/www/html/.htaccess

Below in the file, you can change the native PHP server settings with the configurations below. Modify the PHP settings to fit your own server resources and configurations.

.htaccess file excerpt:

# Change PHP settings
php_value session.use_trans_sid 0
php_value register_globals 1
php_value upload_max_filesize 100M
php_value post_max_size 100M

Finally, add the following rules to the .htaccess file to automatically redirect domain traffic to HTTPS.

# Redirect to HTTPS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]
Options -Indexes
</IfModule>

That’s all! You have successfully installed and configured the phpBB3 bulletin board application in Debian 9.2. However, since the Apache HTTP server uses self-signed certificates to encrypt traffic between the server and visitors' browsers, a warning message is always generated and displayed in their browsers. This warning is bad for SEO and your forum's reputation. In this case, you should buy a certificate issued by a trusted certificate authority or get a free pair of certificates from Let’s Encrypt CA.

You can find more custom configurations for the phpBB3 application on the documentation page at the following address:  https://www.phpbb.com/support/docs/en/