Install Flarum on an Ubuntu 14.04 VPS

install-flarum-on-an-ubuntu-14-04-vpsIn this article, we will explain how to install Flarum on an Ubuntu 14.04 VPS with MariaDB, PHP-FPM and Nginx. Flarum is an open-source forum software with a focus on simplicity written in PHP on top of the Laravel framework. This guide should work on other Linux VPS systems as well but was tested and written for an Ubuntu 14.04 VPS.

Login to your VPS via SSH

ssh user@vps_IP

Update the system and install necessary packages

[user]$ sudo apt-get update && sudo apt-get -y upgrade
[user]$ sudo apt-get install software-properties-common git nano

Install MariaDB 10.0

To add the MariaDB repository to your sources list and install the latest MariaDB server, run the following commands:

[user]$ sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
[user]$ sudo add-apt-repository 'deb http://ftp.osuosl.org/pub/mariadb/repo/10.0/ubuntu trusty main'
[user]$ sudo apt-get update
[user]$ sudo apt-get install -y mariadb-server

When the installation is complete, run the following command to secure your installation:

[user]$ mysql_secure_installation

Next, we need to create a database for the Flarum installation.

[user]$ mysql -uroot -p
MariaDB [(none)]> CREATE DATABASE flarum;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON flarum.* TO 'flarum'@'localhost' IDENTIFIED BY 'strongpassword';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> \q

Install PHP, composer and required PHP modules

To install the latest stable version of PHP version 7 and all necessary modules, run:

[user]$ sudo add-apt-repository -y ppa:ondrej/php-7.0
[user]$ sudo apt-get update
[user]$ 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

Composer is a dependency manager for PHP with which you can install packages. Composer will pull in all the required libraries and dependencies you need for your project.

[user]$ curl -sS https://getcomposer.org/installer | php
[user]$ sudo mv composer.phar /usr/local/bin/composer

Install Flarum

Create a root directory for your Flarum forum using the following command:

[user]$ mkdir -p ~/myFlarum.org/public_html

Run the composer create-project command to create a new Flarum installation:

[user]$ composer create-project flarum/flarum ~/myFlarum.org/public_html --stability=beta

PHP-FPM configuration

Create a new PHP-FPM pool for your user:

[user]$ sudo nano /etc/php/7.0/fpm/pool.d/your_user.conf
[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 = /

Do not forget to change your_user with your username.

Restart PHP-FPM:

[user]$ sudo service php7.0-fpm restart

Install and configure Nginx

Ubuntu 14.04 comes with Nginx version 1.4, to install the latest stable version of Nginx version 1.8, run:

[user]$ sudo add-apt-repository -y ppa:nginx/stable
[user]$ sudo apt-get update
[user]$ sudo apt-get -y install nginx

Generate a self signed ssl certificate:

[user]$ sudo mkdir -p /etc/nginx/ssl
[user]$ cd /etc/nginx/ssl
[user]$ sudo openssl genrsa -des3 -passout pass:x -out flarum.pass.key 2048
[user]$ sudo openssl rsa -passin pass:x -in flarum.pass.key -out flarum.key
[user]$ sudo rm flarum.pass.key
[user]$ sudo openssl req -new -key flarum.key -out flarum.csr
[user]$ sudo openssl x509 -req -days 365 -in flarum.csr -signkey flarum.key -out flarum.crt

If you don’t want to get warnings associated with self-signed SSL Certificates, you can purchase a trusted SSL certificate.

Next, create a new Nginx server block:

[user]$ sudo nano /etc/nginx/sites-available/myFlarum.org
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;
}

Do not forget to change your_user with your username.

Activate the server block by creating a symbolic link :

[user]$ sudo ln -s /etc/nginx/sites-available/myFlarum.org /etc/nginx/sites-enabled/myFlarum.org

Test the Nginx configuration and restart nginx:

[user]$ sudo nginx -t
[user]$ sudo service nginx restart

Open https://myFlarum.org/ in your favorite web browser and you should see the Flarum install screen. On this page you’ll need to enter the database details you created earlier and Flarum admin details.

That’s it. You have successfully installed Flarum on your Ubuntu 14.04 VPS. For more information about how to manage your Flarum installation, please refer to the official Flarum documentation.


Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to setup this for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

2 thoughts on “Install Flarum on an Ubuntu 14.04 VPS”

  1. Hi – followed the tutorial above (very well done!). But, here’s the issue I’m facing – my site now just shows the welcome to nginx message.

    Background: Ubuntu VM on Microsoft Azure

    Questions:

    1) Is myflarum.org actually a domain name or should represent the domain name? You do mention to go to https:// myFlarum.org

    In my case, the domain is flarumvt.cloudapp.net so should I be using this? Does it matter?

    2) I actually created folder myFlarum.org as in the tutorial but after restarting nginx I only see welcome at http:// flarumvt.cloudapp.net

    Any thoughts?

    Reply

Leave a Comment