How to Install Flarum in Ubuntu 14.04 VPS

In this article, we will explain to you How to Install Flarum on Ubuntu 14.04 VPS.

Flarum is free, open-source forum software with a focus on simplicity. You can use Flarum to easily set up a discussion forum for your website.Flarum may be minimalistic, but it’s also highly extensible. In fact, most of the features that ship with Flarum are actually Extensions! This approach makes Flarum extremely customizable. A user can disable any features they don’t use on their forum and install other Extensions to make a forum perfect for their use-case.

You will need one VPS Server with Ubuntu 14.04 OS installed on it.

To install Flarum you need to have root access.

Update your server system.
sudo apt-get update
sudo apt-get -y upgrade

After, install the packages that Flarum require.
sudo apt-get install software-properties-common git nano

Install MySQL Server

Now you need to install MariaDB server. To install it run these commands one by one:
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
Add MariaDB repository:
sudo add-apt-repository 'deb http://ftp.osuosl.org/pub/mariadb/repo/10.0/ubuntu trusty main'
Update the system:
sudo apt-get update
And install it:
sudo apt-get install -y mariadb-server

Now secure your MySQL installation by running this command:
mysql_secure_installation

After, create a new database for Flarum.
mysql -u root -p

CREATE DATABASE flarum;
GRANT ALL PRIVILEGES ON flarum.* TO 'flarum'@'localhost' IDENTIFIED BY 'yourpassword';
FLUSH PRIVILEGES;
quit

Install PHP 7.0

Now install PHP 7.0 and required modules.

sudo add-apt-repository -y ppa:ondrej/php-7.0

Update your server system.

sudo apt-get update

And install PHP and required PHP modules.
sudo apt-get -y install php7.0-fpm php7.0-cli php7.0-gd php7.0-mysql php7.0-mcrypt php-pear php7.0-curl

After installing, run those commands to install composer.
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

Install Flarum

Now it’s time to install Flarum. First, create root directory for Flarum
mkdir -p ~/myFlarum.org/public_html

Run the composer to create a new Flarum installation
composer create-project flarum/flarum ~/myFlarum.org/public_html --stability=beta

Now create a new file for your user
Notice: Do not forget to change your_username with your preferred username
sudo nano /etc/php/7.0/fpm/pool.d/your_user.conf
And add the lines
[your_user]
user = your_user
group = your_user
listen = /var/run/php-fpm-your_user.sock
listen.owner = your_user
listen.group = your_user
listen.mode = 0666
pm = ondemand
pm.max_children = 5
pm.process_idle_timeout = 10s
pm.max_requests = 200
chdir = /

Save the changes and restart PHP-FPM
sudo service php7.0-fpm restart

Install Nginx

Now you need to install Nginx.

To install it first add nginx repository
sudo add-apt-repository -y ppa:nginx/stable
Update the system:
sudo apt-get update
And install it:
sudo apt-get -y install nginx

Generate SSL certificate

After, generate a self-signed SSL certificate:
Run commands one by one.

Create SSL directory in nginx and go into the directory:
sudo mkdir -p /etc/nginx/ssl
cd /etc/nginx/ssl

After this generate signed SSL certificate:
sudo openssl genrsa -des3 -passout pass:x -out flarum.pass.key 2048
In next:
sudo openssl rsa -passin pass:x -in flarum.pass.key -out flarum.key
After, remove flarum.pass.key
sudo rm flarum.pass.key
Create a new flarum key
sudo openssl req -new -key flarum.key -out flarum.csr
And finish it by running this command:
sudo openssl x509 -req -days 365 -in flarum.csr -signkey flarum.key -out flarum.crt
Next, you need to create Nginx block.
sudo nano /etc/nginx/sites-available/myFlarum.org
After, add lines:

server {

listen 443;
server_name myFlarum.org;
index
root /home/your_user/myFlarum.org/public_html;

ssl on;
ssl_certificate /etc/nginx/ssl/flarum.crt;
ssl_certificate_key /etc/nginx/ssl/flarum.key;
ssl_session_timeout 5m;
ssl_ciphers ‘AES128+EECDH:AES128+EDH:!aNULL’;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;

access_log /var/log/nginx/flarum.access.log;
error_log /var/log/nginx/flarum.error.log;

location / {
try_files $uri $uri/ /index.php?$query_string;
}

location /api {
try_files $uri $uri/ /api.php?$query_string;
}

location /admin {
try_files $uri $uri/ /admin.php?$query_string;
}

location /flarum {
deny all;
return 404;
}

location ~* \.html$ {
expires -1;
}

location ~* \.(css|js|gif|jpe?g|png)$ {
expires 1M;
add_header Pragma public;
add_header Cache-Control “public, must-revalidate, proxy-revalidate”;
}

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm-your_user.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}

location ~ /\.ht {
deny all;
}
}

server {
listen 80;
server_name myFlarum.org;

add_header Strict-Transport-Security max-age=2592000;
rewrite ^ https://$server_name$request_uri? permanent;
}

Notice: Change your_user with your real username.

Now enable the Nginx block that you created.
sudo ln -s /etc/nginx/sites-available/myFlarum.org /etc/nginx/sites-enabled/myFlarum.org

Restart the Nginx:
sudo service nginx restart

Open your server like https://yourdomain.com or https://yourIPadress in the preferred web browser.
Follow the wizard installation and setup the database in the wizard.

Now you have successfully installed Flarum in Ubuntu 14.04.

Enjoy!
Flarum - Interface

Register for free account now.