Knowledgebase

Install phpBB with a LAMP Stack on Ubuntu 20.04 Print

  • 0

Introduction

phpBB is one of the oldest open source forum software that is still actively developed today. This guide explains how to install phpBB with Apache, MariaDB, and PHP on Ubuntu 20.04 and set up HTTPS with a free Let's Encrypt TLS certificate.

Prerequisites

Make sure to replace phpbb.example.com in the code examples with your server's fully qualified domain name or IP address.

1. Install Software Packages

phpBB requires the following software:

  • A web server such as Apache.
  • A SQL database system such as MariaDB.
  • PHP 7.1.3 up to and including PHP 7.4.
  • The following PHP modules:
    • json, mbstring, and xml
    • (optional) gd

Your LAMP server comes with Apache 2.4, MariaDB 10.3, and PHP 7.4 pre-installed, so you only need to install the necessary PHP modules.

  1. Log in to the server as a non-root sudo user via SSH.

  2. Install the required modules.

     $ sudo apt -y install php7.4-gd php7.4-json php7.4-mbstring php7.4-xml

For production use, you should disable the pre-installed Xdebug module, as it reduces PHP performance.

  1. Open the Xdebug module configuration file.

     $ sudo nano /etc/php/7.4/mods-available/xdebug.ini
  2. Put ; before the zend_extension=xdebug.so directive, as shown.

     ;zend_extension=xdebug.so
  3. Save the file and exit.

2. Configure Time Zone

Your LAMP server is pre-configured with the UTC timezone. If you want to use a different timezone, follow these instructions.

  1. List all the time zones that the operating system supports. Use the Up / Down keys to move through the list, and press Q to exit.

     $ timedatectl list-timezones
  2. Copy an appropriate time zone from the list, for example, America/New_York. Then update the system with that time zone.

     $ sudo timedatectl set-timezone America/New_York
  3. Edit the PHP-FPM configuration file to tell PHP to use the new time zone.

     $ sudo nano /etc/php/7.4/fpm/pool.d/www.conf
  4. Find the date.timezone directive, then change its value from UTC to your time zone, as shown.

     php_admin_value[date.timezone] = America/New_York
  5. Save the configuration file and exit.

  6. Check the new configuration.

     $ sudo php-fpm7.4 -t

3. Create a Database

  1. Connect to the MariaDB command line as the MariaDB root user.

     $ sudo mariadb
  2. Create a new dbname database for phpBB.

     MariaDB [(none)]> CREATE DATABASE dbname;
  3. Create a MariaDB user named dbuser and grant it all privileges to the dbname database. Replace dbpassword with a strong password.

     MariaDB [(none)]> GRANT ALL PRIVILEGES on dbname.* to 'dbuser'@'localhost' IDENTIFIED BY 'dbpassword';
     MariaDB [(none)]> FLUSH PRIVILEGES;
  4. Exit the MariaDB command line.

     MariaDB [(none)]> exit

4. Install phpBB

  1. Download the source code archive from GitHub to the home directory.

     $ cd ~
     $ wget https://github.com/phpbb/phpbb/archive/refs/tags/release-3.3.4.tar.gz

    At the time of writing, the latest stable version of phpBB is 3.3.4. But, of course, you can always visit the phpBB releases page to get the latest version.

  2. Extract the archive.

     $ tar xzf release-3.3.4.tar.gz
  3. Change the working directory to the public code directory.

     $ cd phpbb-release-3.3.4/phpBB
  4. The extracted directory already has the composer.phar program. Use it to install dependencies.

     $ ../composer.phar install --no-dev -o
  5. Sync the public code directory to the /var/www/html document root directory and delete all existing files there.

     $ sudo rsync -a --delete ./ /var/www/html
  6. Make www-data the owner of /var/www/html so that Apache and PHP can access the directory.

     $ sudo chown -R www-data:www-data /var/www/html
  7. Delete the downloaded archive and the extracted directory.

     $ cd ~
     $ rm -fr phpbb-release-3.3.4/ release-3.3.4.tar.gz

5. Configure Apache

  1. Open the default virtual host configuration file.

     $ sudo nano /etc/apache2/sites-enabled/http.conf

    Any string that begins with # is a comment.

  2. Paste the following directives below the <VirtualHost *:80> line.

     <Directory /var/www/html/cache/*>
         Require all denied
     </Directory>
     <Directory /var/www/html/cache>
         Require all denied
     </Directory>
    
     <Directory /var/www/html/files/*>
         Require all denied
     </Directory>
     <Directory /var/www/html/files>
         Require all denied
     </Directory>
    
     <Directory /var/www/html/includes/*>
         Require all denied
     </Directory>
     <Directory /var/www/html/includes>
         Require all denied
     </Directory>
    
     <Directory /var/www/html/phpbb/*>
         Require all denied
     </Directory>
     <Directory /var/www/html/phpbb>
         Require all denied
     </Directory>
    
     <Directory /var/www/html/store/*>
         Require all denied
     </Directory>
     <Directory /var/www/html/store>
         Require all denied
     </Directory>
    
     <Directory /var/www/html/vendor/*>
         Require all denied
     </Directory>
     <Directory /var/www/html/vendor>
         Require all denied
     </Directory>

    These directives prevent users from accessing sensitive files.

  3. Find the ServerName directive, remove the leading # character, and change its value to your server's fully qualified domain name or IP address, as shown.

     ServerName phpbb.example.com
  4. Save the configuration file and exit.

  5. Check the new configuration. Make sure you see Syntax OK in the output.

     $ sudo apache2ctl configtest
  6. Disable the default HTTPS configuration.

     $ sudo a2dissite https.conf
  7. Reload Apache to activate the new configuration.

     $ sudo systemctl reload apache2.service

6. (Optional) Configure HTTPS

If you own a valid domain name, you can set up HTTPS for your phpBB website at no cost. You can get a free TLS certificate from Let's Encrypt with their Certbot program.

  1. Follow the Install Certbot section of this Rcs guide to install Certbot with Snap.

  2. Run Certbot to get and install a Let's Encrypt certificate for Apache. Replace admin@phpbb.example.com with your email if needed.

     $ sudo certbot --apache --redirect -d phpbb.example.com -m admin@phpbb.example.com --agree-tos --no-eff-email
  3. Certbot has also set up a systemd timer to renew this certificate automatically. Run the following command to verify the timer is active.

     $ systemctl list-timers | grep 'certbot\|ACTIVATES'

Now your phpBB website can get an "A" rating on the SSL Labs test.

7. Complete the Setup

  1. Restart the server.

     $ sudo reboot

    Wait a moment for the operating system to boot.

  2. Open your browser and type in the http://phpbb.example.com URL.

  3. The phpBB installation page appears. Click the INSTALL tab, then click the Install button.

  4. The Administrator configuration form appears. Enter the administrator username, email, and password of your choice, then click the Submit button.

  5. The Database configuration form appears.

    • For the Database type option, select MySQL with MySQLi Extension.
    • For the Database server hostname or DSN option, enter localhost.
    • For the Database server port option, leave it empty.
    • For the Database username, Database password, and Database name options, enter the corresponding values you created in Section 3.
    • For the Prefix for tables in database option, accept the default value.

    Then click the Submit button.

  6. Accept all the default values for the remaining forms, and click the Submit button.

  7. Once completed, click the ACP link to access Administration Control Panel (ACP). ACP provides all kinds of settings for you to customize most of your phpBB features. For more details, read the phpBB Administration Guide.

  8. Log in to the server as a non-root sudo user via SSH again.

  9. Delete the unnecessary docs directory.

     $ sudo rm -fr /var/www/html/docs
  10. Prevent unintended changes to the config.php file.

    $ sudo chmod 644 /var/www/html/config.php
    $ sudo chown root:root /var/www/html/config.php
  11. Delete the install directory to activate phpBB.

    $ sudo rm -fr /var/www/html/install

You have successfully installed phpBB. Now your forum is ready to serve visitors.

References

To learn more about phpBB, please see these resources:

Introduction phpBB is one of the oldest open source forum software that is still actively developed today. This guide explains how to install phpBB with Apache, MariaDB, and PHP on Ubuntu 20.04 and set up HTTPS with a free Let's Encrypt TLS certificate. Prerequisites Deploy an Ubuntu 20.04 server with the LAMP stack. Follow Rcs's best practices guides to create a sudo user and update the Ubuntu server. (Optional) Configure the Ubuntu firewall with ports 80, 443, and 22 open. Make sure to replace phpbb.example.com in the code examples with your server's fully qualified domain name or IP address. 1. Install Software Packages phpBB requires the following software: A web server such as Apache. A SQL database system such as MariaDB. PHP 7.1.3 up to and including PHP 7.4. The following PHP modules: json, mbstring, and xml (optional) gd Your LAMP server comes with Apache 2.4, MariaDB 10.3, and PHP 7.4 pre-installed, so you only need to install the necessary PHP modules. Log in to the server as a non-root sudo user via SSH. Install the required modules. $ sudo apt -y install php7.4-gd php7.4-json php7.4-mbstring php7.4-xml For production use, you should disable the pre-installed Xdebug module, as it reduces PHP performance. Open the Xdebug module configuration file. $ sudo nano /etc/php/7.4/mods-available/xdebug.ini Put ; before the zend_extension=xdebug.so directive, as shown. ;zend_extension=xdebug.so Save the file and exit. 2. Configure Time Zone Your LAMP server is pre-configured with the UTC timezone. If you want to use a different timezone, follow these instructions. List all the time zones that the operating system supports. Use the UP / DOWN keys to move through the list, and press Q to exit. $ timedatectl list-timezones Copy an appropriate time zone from the list, for example, America/New_York. Then update the system with that time zone. $ sudo timedatectl set-timezone America/New_York Edit the PHP-FPM configuration file to tell PHP to use the new time zone. $ sudo nano /etc/php/7.4/fpm/pool.d/www.conf Find the date.timezone directive, then change its value from UTC to your time zone, as shown. php_admin_value[date.timezone] = America/New_York Save the configuration file and exit. Check the new configuration. $ sudo php-fpm7.4 -t 3. Create a Database Connect to the MariaDB command line as the MariaDB root user. $ sudo mariadb Create a new dbname database for phpBB. MariaDB [(none)]> CREATE DATABASE dbname; Create a MariaDB user named dbuser and grant it all privileges to the dbname database. Replace dbpassword with a strong password. MariaDB [(none)]> GRANT ALL PRIVILEGES on dbname.* to 'dbuser'@'localhost' IDENTIFIED BY 'dbpassword'; MariaDB [(none)]> FLUSH PRIVILEGES; Exit the MariaDB command line. MariaDB [(none)]> exit 4. Install phpBB Download the source code archive from GitHub to the home directory. $ cd ~ $ wget https://github.com/phpbb/phpbb/archive/refs/tags/release-3.3.4.tar.gz At the time of writing, the latest stable version of phpBB is 3.3.4. But, of course, you can always visit the phpBB releases page to get the latest version. Extract the archive. $ tar xzf release-3.3.4.tar.gz Change the working directory to the public code directory. $ cd phpbb-release-3.3.4/phpBB The extracted directory already has the composer.phar program. Use it to install dependencies. $ ../composer.phar install --no-dev -o Sync the public code directory to the /var/www/html document root directory and delete all existing files there. $ sudo rsync -a --delete ./ /var/www/html Make www-data the owner of /var/www/html so that Apache and PHP can access the directory. $ sudo chown -R www-data:www-data /var/www/html Delete the downloaded archive and the extracted directory. $ cd ~ $ rm -fr phpbb-release-3.3.4/ release-3.3.4.tar.gz 5. Configure Apache Open the default virtual host configuration file. $ sudo nano /etc/apache2/sites-enabled/http.conf Any string that begins with # is a comment. Paste the following directives below the line. Require all denied Require all denied Require all denied Require all denied Require all denied Require all denied Require all denied Require all denied Require all denied Require all denied Require all denied Require all denied These directives prevent users from accessing sensitive files. Find the ServerName directive, remove the leading # character, and change its value to your server's fully qualified domain name or IP address, as shown. ServerName phpbb.example.com Save the configuration file and exit. Check the new configuration. Make sure you see Syntax OK in the output. $ sudo apache2ctl configtest Disable the default HTTPS configuration. $ sudo a2dissite https.conf Reload Apache to activate the new configuration. $ sudo systemctl reload apache2.service 6. (Optional) Configure HTTPS If you own a valid domain name, you can set up HTTPS for your phpBB website at no cost. You can get a free TLS certificate from Let's Encrypt with their Certbot program. Follow the Install Certbot section of this Rcs guide to install Certbot with Snap. Run Certbot to get and install a Let's Encrypt certificate for Apache. Replace admin@phpbb.example.com with your email if needed. $ sudo certbot --apache --redirect -d phpbb.example.com -m admin@phpbb.example.com --agree-tos --no-eff-email Certbot has also set up a systemd timer to renew this certificate automatically. Run the following command to verify the timer is active. $ systemctl list-timers | grep 'certbot\|ACTIVATES' Now your phpBB website can get an "A" rating on the SSL Labs test. 7. Complete the Setup Restart the server. $ sudo reboot Wait a moment for the operating system to boot. Open your browser and type in the http://phpbb.example.com URL. The phpBB installation page appears. Click the INSTALL tab, then click the Install button. The Administrator configuration form appears. Enter the administrator username, email, and password of your choice, then click the Submit button. The Database configuration form appears. For the Database type option, select MySQL with MySQLi Extension. For the Database server hostname or DSN option, enter localhost. For the Database server port option, leave it empty. For the Database username, Database password, and Database name options, enter the corresponding values you created in Section 3. For the Prefix for tables in database option, accept the default value. Then click the Submit button. Accept all the default values for the remaining forms, and click the Submit button. Once completed, click the ACP link to access Administration Control Panel (ACP). ACP provides all kinds of settings for you to customize most of your phpBB features. For more details, read the phpBB Administration Guide. Log in to the server as a non-root sudo user via SSH again. Delete the unnecessary docs directory. $ sudo rm -fr /var/www/html/docs Prevent unintended changes to the config.php file. $ sudo chmod 644 /var/www/html/config.php $ sudo chown root:root /var/www/html/config.php Delete the install directory to activate phpBB. $ sudo rm -fr /var/www/html/install You have successfully installed phpBB. Now your forum is ready to serve visitors. References To learn more about phpBB, please see these resources: phpBB User Guide phpBB Knowledge Base

Was this answer helpful?
Back

Powered by WHMCompleteSolution