Flarum is a free and open-source forum software that is written in PHP, JavaScript, and TypeScript. It is known for its minimalistic design and high extensibility through the use of extensions. In this tutorial, we will guide you through the installation process of Flarum on a Debian 11 Bullseye server. We will also cover some basic configurations of the LAMP (Linux, Apache, MariaDB, PHP) stack and the installation of PHP Composer for the Flarum web application.
Prerequisites
Before we begin, make sure that you have the following:
- A Linux server running Debian 11 Bullseye
- Root access or a non-root user with root privileges
- A domain name pointed to the server
Installing Apache2
The first step is to install the Apache2 web server on your Debian system. Update your repository package index by running the following command:
sudo apt update
Once the update is complete, install the Apache2 package by running the following command:
sudo apt install apache2 -y
After the installation is finished, start the Apache2 service and enable it to start on boot by running the following commands:
sudo systemctl start apache2 sudo systemctl enable apache2
To allow incoming HTTP and HTTPS traffic, you need to open the respective ports on your firewall. If you are using the UFW firewall, you can do this by running the following commands:
sudo ufw allow "WWW Full"
sudo ufw reload
You can verify the status of your firewall rules by running the following command:
sudo ufw status
Installing MariaDB Server
Next, we will install and configure the MariaDB database on our Debian server. Run the following command to install the MariaDB packages:
sudo apt install mariadb-server -y
Once the installation is complete, start the MariaDB service and enable it to start on boot by running the following commands:
sudo systemctl start mariadb sudo systemctl enable mariadb
To secure your MariaDB installation, run the following command and follow the on-screen instructions:
sudo mysql_secure_installation
During the configuration process, you will be prompted to set the root password and answer a series of security-related questions.
Installing PHP Packages
Flarum is a PHP-based web application, so we need to install the necessary PHP packages on our Debian server. Run the following command to install the required packages:
sudo apt install php php-common php-mysql libapache2-mod-php php-gd php-curl php-json php-xmlrpc php-intl php-bcmath php-zip php-apcu php-mbstring php-fileinfo php-xml php-soap php-tokenizer -y
After the installation is complete, we need to make some changes to the php.ini
configuration file. Open the file using a text editor of your choice:
sudo nano /etc/php/7.4/apache2/php.ini
Inside the php.ini
file, find the following lines and modify them as shown below:
memory_limit = 512M upload_max_file_size = 150M max_execution_time = 600 date.timezone = Europe/Paris
Save the file and exit the text editor. To apply the changes, restart the Apache2 service:
sudo systemctl restart apache2
Installing Composer
Composer is a dependency manager for PHP that is used to install and manage libraries for PHP applications. We will use Composer to install Flarum on our Debian server. To install Composer, run the following commands:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php');"
Move the resulting composer.phar
file to the /usr/local/bin
directory:
sudo mv composer.phar /usr/local/bin/composer
To verify that Composer is installed correctly, run the following command:
composer --version
You should see the version information for Composer printed on the screen.
Creating a Database and User for Flarum
Before we can start the installation of Flarum, we need to create a new database and user in MariaDB specifically for Flarum. To do this, log in to the MariaDB shell as the root user:
sudo mysql -u root -p
Enter your MariaDB root password when prompted. Once you are logged in, run the following SQL commands to create the database and user:
CREATE DATABASE flarumdb; CREATE USER 'flarum'@'localhost' IDENTIFIED BY 'flarumdbpassword'; GRANT ALL PRIVILEGES ON flarumdb.* TO 'flarum'@'localhost'; FLUSH PRIVILEGES;
Make sure to replace flarumdbpassword
with a strong password of your choice. Exit the MariaDB shell by typing exit
or pressing Ctrl+D
.
Setting up the Flarum Project Directory
In this step, we will download and install the Flarum source code using PHP Composer. First, create a new project directory for Flarum:
sudo mkdir -p /var/www/flarum sudo chown -R www-data:www-data /var/www/flarum sudo chmod u+rw /var/www/flarum
Next, change your working directory to /var/www/flarum
and install Flarum using Composer:
cd /var/www/flarum sudo -u www-data composer create-project flarum/flarum.
This command will download and install Flarum and all its dependencies. Once the installation is complete, you will find the Flarum source code in the /var/www/flarum
directory.
Setting up the Apache Virtual Host
To access your Flarum installation, you need to set up an Apache virtual host. Start by enabling some required Apache modules:
sudo a2enmod ssl rewrite headers
Create a new Apache virtual host configuration file for Flarum:
sudo nano /etc/apache2/sites-available/flarum.conf
Paste the following virtual host configuration into the file:
<VirtualHost *:80>
ServerName yourdomain.com
Redirect permanent / https://yourdomain.com/
</VirtualHost>
<VirtualHost *:443>
ServerAdmin test@example.com
DocumentRoot /var/www/flarum/public
ServerName yourdomain.com
Protocols h2 http/1.1
SSLEngine On
SSLCertificateFile /etc/letsencrypt/live/yourdomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/yourdomain.com/privkey.pem
<Directory /var/www/flarum/public/>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/flarum/public/>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) index.php [PT,L]
</Directory>
</VirtualHost>
Make sure to replace yourdomain.com
with your actual domain name. Save the file and exit the text editor.
Enable the virtual host configuration and test the Apache configuration for any syntax errors:
sudo a2ensite flarum.conf
sudo apachectl configtest
If there are no errors, restart the Apache2 service to apply the changes:
sudo systemctl restart apache2
Starting the Flarum Installation
To start the Flarum installation, open your web browser and navigate to https://yourdomain.com/
. You should see the Flarum installation page.
Enter the required details, such as the site title and database information. Also, provide an admin username and password for your Flarum installation. Once you have filled in all the necessary information, click on the “Install Flarum” button to begin the installation process.
After a few moments, the installation will be complete, and you will see a welcome message from Flarum. You can now access your Flarum forum and start customizing it according to your needs.
Conclusion
Congratulations! You have successfully installed Flarum on your Debian 11 Bullseye server. Flarum is now ready for you to create a vibrant online community. Make sure to explore the Flarum administration settings to further customize your forum.
If you are looking for reliable and scalable cloud hosting solutions, consider Shape.host. They offer Linux SSD VPS (Virtual Private Servers) that provide excellent performance and security for your applications. Shape.host is committed to delivering top-notch hosting services to empower businesses with efficient and secure cloud solutions.