Home / How To / How to install Flarum Forum on Ubuntu 20.04

How to install Flarum Forum on Ubuntu 20.04



Flarum is a free, open source and next generation forum application that helps you build your own online discussion forum. It is written in PHP, simple, fast and easy to distribute. It provides a flexible architecture, powerful APT add-ons and all the features you need to run a successful community. Flarum looks and feels good out of the box. The user interface is streamlined so you can spend less time clicking and more time talking.

In this tutorial we will explain how to install Flarum forum with Apache and Let’s Encrypt SSL on the Ubuntu 20.04 server.

Conditions

  • A server running Ubuntu 20.04.
  • A valid domain name pointed to your server’s IP.
  • A root password is configured on the server.

Getting Started

First, it is recommended that you update your system packages to the latest version. You can update them with the following command:

apt-get update -y

Once all packages have been updated, you can proceed to the next step.

Install LAMP Server

Flarum is written in PHP, runs on the web server and uses MySQL / MariaDB as a database backend. So you need to install the LAMP stack in your system. You can install it with the following command:

apt-get install apache2 mariadb-server php7.4 libapache2-mod-php7.4 php7.4-common php7.4-mbstring php7.4-xmlrpc php7.4-soap php7.4-mysql php7.4-gd php7.4-xml php7.4-curl php7.4-cli php7.4-zip php7.4-tokenizer wget unzip curl git -y

After installing all the packages, edit the php.ini file and adjust some settings:

nano /etc/php/7.4/apache2/php.ini

Change the following lines:

file_uploads = On
allow_url_fopen = On
memory_limit = 256M
upload_max_file_size = 150M
max_execution_time = 450
date.timezone = Asia/Kolkata

Save and close the file when you are done.

Create a Flarum database

Then you need to create a database and users for Flarum. First log in to the MariaDB shell with the following command:

mysql

Once logged in, create a database and user with the following command:

MariaDB [(none)]> CREATE DATABASE flarum;
MariaDB [(none)]> CREATE USER 'flarum'@'localhost' IDENTIFIED BY 'password';

Then grant all permissions to the flarum database with the following command:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON flarum.* TO 'flarum'@'localhost';

Then flush the permissions and exit from MariaDB with the following command:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

When you are done, you can move on to the next step.

Install Composer

Then you need to install Composer in your system. Composer is a dependency manager for PHP that is used to install all dependencies required for PHP projects.

You can install the composer with the following command:

curl -s https://getcomposer.org/installer | php

You should get the following output:

All settings correct for using Composer
Downloading...

Composer (version 1.10.10) successfully installed to: /root/composer.phar
Use it: php composer.phar

Then move Composer binary to / usr / local / bin / directory with the following command:

mv composer.phar /usr/local/bin/composer

Then check the installed version of Composer with the following command:

composer -V

You should see the following output:

Composer version 1.10.10 2020-08-03 11:35:19

Install Flarum

First, create a Flarum directory inside the Apache Web directory using the following command:

mkdir /var/www/html/flarum

Then change the directory to flarum and download the latest version of Flarum with Composer as below:

cd /var/www/html/flarum
composer create-project flarum/flarum . --stability=beta

Then install all PHP dependencies with the following command:

composer install

When all dependencies are installed, change the ownership of Flarum to www-data and grant the correct permission with the following command:

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

When you are done, you can move on to the next step.

Configure Apache for Flarum

Next, you will need to create a Apache virtual host configuration file to host Flarum. You can create it with the following command:Advertisement

Advertisement

nano /etc/apache2/sites-available/flarum.conf

Add the following lines:


 ServerAdmin [email protected]
 DocumentRoot /var/www/html/flarum/public
 ServerName flarum.linuxbuz.com
 DirectoryIndex index.php
 
Options +FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
 
 ErrorLog /var/log/apache2/flarum-error_log
 CustomLog /var/log/apache2/flarum-access_log common

Save and close the file when you are done. Then activate the Flarum virtual host and the Apache rewrite module with the following command:

a2ensite flarum
a2enmod rewrite

Finally, restart the Apache service to apply the changes:

systemctl restart apache2

You can also verify the Apache status with the following command:

systemctl status apache2

You should get the following output:

? apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2020-08-23 09:57:11 UTC; 2min 44s ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 27164 (apache2)
      Tasks: 6 (limit: 2353)
     Memory: 12.3M
     CGroup: /system.slice/apache2.service
             ??27164 /usr/sbin/apache2 -k start
             ??27165 /usr/sbin/apache2 -k start
             ??27166 /usr/sbin/apache2 -k start
             ??27167 /usr/sbin/apache2 -k start
             ??27168 /usr/sbin/apache2 -k start
             ??27169 /usr/sbin/apache2 -k start

Aug 23 09:57:11 ubuntu2004 systemd[1]: Starting The Apache HTTP Server...

Secure Flarum with Let’s Encrypt SSL

It is always recommended to secure your website with Let’s Encrypt free SSL. First install the Certbot Let’s Encrypt client with the following command:

apt-get install python3-certbot-apache -y

Once installed, run the following command to install Let’s Encrypt SSL for your Flarum Web site:

certbot --apache -d flarum.linuxbuz.com

You will be asked to enter your valid email address and accept the period of service as below:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for flarum.linuxbuz.com
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/flarum-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/flarum-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/flarum-le-ssl.conf

Then select whether you want to redirect HTTP traffic to HTTPS as below:

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Type 2 and press Enter to install the SSL certificate for your website. When the installation is complete, you should get the following output:Advertisement

Advertisement

Redirecting vhost in /etc/apache2/sites-enabled/flarum.conf to ssl vhost in /etc/apache2/sites-available/flarum-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://flarum.linuxbuz.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=flarum.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/flarum.linuxbuz.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/flarum.linuxbuz.com/privkey.pem
   Your cert will expire on 2020-11-21. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

Go to Flarum Forum

At this time, Flarum is installed, configured and secured with Let’s Encrypt SSL. Now open your browser and access Flarum with URL https://flarum.linuxbuz.com. You will be redirected to the following page:

Enter your forum name, database name, username, password, admin username, password, email address and click Install blow button. When the installation is complete, you will be redirected to the Flarum instrument panel as follows:

Conclusion

Congratulations! you have successfully installed the Flarum Forum with Apache and Let’s Encrypt SSL on the Ubuntu 20.04 server. Now you can easily host your own community forum with Flarum. Feel free to ask me if you have any questions.


Source link