How to Setup Flarum with Nginx on Ubuntu Linux

|

,

|

Flarum is a beta, next-generation, open-source forum software running on PHP LAMP or LEMP stack for quick forum setup. This tutorial provides a step-by-step guide to installing Flarum on Ubuntu 16.04 / 17.10 or 18.04 with Nginx, MariaDB, and PHP 7.1 support. The process includes installing Nginx HTTP Server, MariaDB Database Server, and PHP 7.1-FPM,…

Flarum is a new (still in beta), next-generation open-source forum software built on PHP LAMP or LEMP stack. It’s simple to set up and use and makes online discussions fun. Individuals and web admins can use Flarum to set up communities in minutes to stay in touch with groups of people or ideas.

This brief tutorial will show students and new users an easy way to get Flarum working on Ubuntu 16.04 / 17.10 and 18.04 with Nginx, MariaDB, and PHP 7.1 support.

If you’re looking for a feature-rich, efficient, free community forum platform, you may want to consider Flarum.

Install Nginx HTTP Server

Nginx HTTP Server is the second most popular web server in use. Install it since Flarum needs it.

To install Nginx HTTP on the Ubuntu server, run the commands below.

sudo apt update
sudo apt install nginx

After installing Nginx, the commands below can be used to stop, start and enable the Nginx service to always start up with the server boots.

sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service

To test the Nginx setup, open your browser and browse to the server hostname or IP address, and you should see the Nginx default test page as shown below. When you see that, then Nginx is working as expected.

http://localhost

Install MariaDB Database Server

MariaDB database server is a great place to start when looking at open-source database servers for Magento. To install MariaDB run the commands below.

sudo apt-get install mariadb-server mariadb-client

After installing MariaDB, the commands below can stop, start and enable the MariaDB service to start up when the server boots.

Run these on Ubuntu 16.04 LTS

sudo systemctl stop mysql.service
sudo systemctl start mysql.service
sudo systemctl enable mysql.service

Run these on Ubuntu 17.10 and 18.04 LTS

sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

After that, run the commands below to secure the MariaDB server by creating a root password and disallowing remote root access.

sudo mysql_secure_installation

When prompted, answer the questions below by following the guide.

  • Enter current password for root (enter for none): Just press the Enter
  • Set root password? [Y/n]: Y
  • New password: Enter password
  • Re-enter new password: Repeat password
  • Remove anonymous users? [Y/n]: Y
  • Disallow root login remotely? [Y/n]: Y
  • Remove test database and access to it? [Y/n]:  Y
  • Reload privilege tables now? [Y/n]:  Y

Restart MariaDB server

Type the commands below to log into the MariaDB server to test if MariaDB is installed.

sudo mysql -u root -p

Then type the password you created above to sign on. If successful, you should see MariaDB welcome message.

Install PHP 7.1-FPM and Related Modules.

PHP 7.1 may not be available on Ubuntu default repositories. To install it, you must get it from third-party repositories.

Run the commands below to add the below third party repository to upgrade to PHP 7.1-FPM

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php

Then update and upgrade to PHP 7.1-FPM

sudo apt update

Next, run the commands below to install PHP 7.1-FPM and related modules.

sudo apt install php7.1-fpm php7.1-common php7.1-mbstring php7.1-xmlrpc php7.1-soap php7.1-mysql php7.1-gd php7.1-xml php7.1-cli php7.1-zip

After installing PHP 7.1, run the commands below to open Nginx’s PHP default config file.

sudo nano /etc/php/7.1/fpm/php.ini

Then save the changes on the following lines below in the file. The value below is an ideal setting to apply in your environment.

file_uploads = On
allow_url_fopen = On
memory_limit = 256M
upload_max_filesize = 100M
cgi.fix_pathinfo = 0
max_execution_time = 360
date.timezone = America/Chicago

After making the change above, please save the file and close it.

After installing PHP and related modules, you must restart Nginx to reload PHP configurations.

To restart Nginx, run the commands below

sudo systemctl restart nginx.service

Create Magento Database

Once you’ve installed all the packages that Magento can function, continue below to start configuring the servers. First, run the commands below to create a blank Magento database.

To log on to the MariaDB database server, run the commands below.

sudo mysql -u root -p

Then create a database called a forum.

CREATE DATABASE flarum;

Create a database user called flarumuser with a new password

CREATE USER 'flarumuser'@'localhost' IDENTIFIED BY 'new_password_here';

Then grant the user full access to the database.

GRANT ALL ON flarum.* TO 'flarumuser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;

Finally, save your changes and exit.

FLUSH PRIVILEGES;
EXIT;

Download Flarum Files

Flarum utilizes Composer to manage its dependencies and extensions. So, before installing Flarum, you must install Composer on your machine. To do that, run the commands below.

sudo apt install curl git
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

Then follow up with the commands below to download Flarum files

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

Next, run the commands below to change the root folder permissions.

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

Configure Nginx Flarum Site

Finally, configure the Nginx configuration file for Flarum. This file will control how users access Flarum content. Run the commands below to create a new configuration file called forum.

sudo nano /etc/nginx/sites-available/flarum

Then copy and paste the content below into the file and save it. Replace the highlighted line with your domain name and directory root location.

server {
    listen 80;
    listen [::]:80;
    root /var/www/html/flarum;
    index  index.php index.html index.htm;
    server_name  example.com;

    location / {
        try_files $uri $uri/ /index.php?$query_string;        
    }
  
    location ~ \.php$ {
       include snippets/fastcgi-php.conf;
       fastcgi_pass             unix:/var/run/php/php7.1-fpm.sock;
       fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

}

Save the file and exit.

After configuring the VirtualHost above, please enable it by running the commands below.

Enable the Flarum Site

Run the commands below to enable the Flarum site.

sudo ln -s /etc/nginx/sites-available/flarum /etc/nginx/sites-enabled/

After configuring the VirtualHost above, please enable it by running the commands below, then restart the Nginx server.

sudo systemctl restart nginx.service

Next, open your browser and browse to the server hostname or IP address.

http://example.com

You should see the Flarum setup wizard

Follow the wizard and install Flarum.

~enjoy!

You may also like the post below:

Like this:



3 responses to “How to Setup Flarum with Nginx on Ubuntu Linux”

  1. Sergey Avatar
    Sergey

    root@ubuntu_server:~# sudo mkdir /var/www/html/flarum
    root@ubuntu_server:~# cd /var/www/html/flarum
    root@ubuntu_server:/var/www/html/flarum# sudo composer create-project flarum/flarum . –stability=beta
    Do not run Composer as root/super user! See https://getcomposer.org/root for details
    Installing flarum/flarum (v0.1.0-beta.7)
    – Installing flarum/flarum (v0.1.0-beta.7): Downloading (100%)
    Created project in .
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
    Your requirements could not be resolved to an installable set of packages.

    Problem 1
    – flarum/flarum-ext-akismet v0.1.0-beta.3 requires tijsverkoyen/akismet ^1.1 -> satisfiable by tijsverkoyen/akismet[1.1.0, 1.1.1].
    – flarum/flarum-ext-akismet v0.1.0-beta.5 requires tijsverkoyen/akismet ^1.1 -> satisfiable by tijsverkoyen/akismet[1.1.0, 1.1.1].
    – flarum/flarum-ext-akismet v0.1.0-beta.6 requires tijsverkoyen/akismet ^1.1 -> satisfiable by tijsverkoyen/akismet[1.1.0, 1.1.1].
    – tijsverkoyen/akismet 1.1.1 requires ext-curl * -> the requested PHP extension curl is missing from your system.
    – tijsverkoyen/akismet 1.1.0 requires ext-curl * -> the requested PHP extension curl is missing from your system.
    – Installation request for flarum/flarum-ext-akismet ^0.1.0 -> satisfiable by flarum/flarum-ext-akismet[v0.1.0-beta.3, v0.1.0-beta.5, v0.1.0-beta.6].

    To enable extensions, verify that they are enabled in your .ini files:
    – /etc/php/7.1/cli/php.ini
    – /etc/php/7.1/cli/conf.d/10-mysqlnd.ini
    – /etc/php/7.1/cli/conf.d/10-opcache.ini
    – /etc/php/7.1/cli/conf.d/10-pdo.ini
    – /etc/php/7.1/cli/conf.d/15-xml.ini
    – /etc/php/7.1/cli/conf.d/20-calendar.ini
    – /etc/php/7.1/cli/conf.d/20-ctype.ini
    – /etc/php/7.1/cli/conf.d/20-dom.ini
    – /etc/php/7.1/cli/conf.d/20-exif.ini
    – /etc/php/7.1/cli/conf.d/20-fileinfo.ini
    – /etc/php/7.1/cli/conf.d/20-ftp.ini
    – /etc/php/7.1/cli/conf.d/20-gd.ini
    – /etc/php/7.1/cli/conf.d/20-gettext.ini
    – /etc/php/7.1/cli/conf.d/20-iconv.ini
    – /etc/php/7.1/cli/conf.d/20-json.ini
    – /etc/php/7.1/cli/conf.d/20-mbstring.ini
    – /etc/php/7.1/cli/conf.d/20-mysqli.ini
    – /etc/php/7.1/cli/conf.d/20-pdo_mysql.ini
    – /etc/php/7.1/cli/conf.d/20-phar.ini
    – /etc/php/7.1/cli/conf.d/20-posix.ini
    – /etc/php/7.1/cli/conf.d/20-readline.ini
    – /etc/php/7.1/cli/conf.d/20-shmop.ini
    – /etc/php/7.1/cli/conf.d/20-simplexml.ini
    – /etc/php/7.1/cli/conf.d/20-soap.ini
    – /etc/php/7.1/cli/conf.d/20-sockets.ini
    – /etc/php/7.1/cli/conf.d/20-sysvmsg.ini
    – /etc/php/7.1/cli/conf.d/20-sysvsem.ini
    – /etc/php/7.1/cli/conf.d/20-sysvshm.ini
    – /etc/php/7.1/cli/conf.d/20-tokenizer.ini
    – /etc/php/7.1/cli/conf.d/20-wddx.ini
    – /etc/php/7.1/cli/conf.d/20-xmlreader.ini
    – /etc/php/7.1/cli/conf.d/20-xmlrpc.ini
    – /etc/php/7.1/cli/conf.d/20-xmlwriter.ini
    – /etc/php/7.1/cli/conf.d/20-xsl.ini
    – /etc/php/7.1/cli/conf.d/20-zip.ini
    You can also run `php –ini` inside terminal to see which files are used by PHP in CLI mode.
    root@ubuntu_server:/var/www/html/flarum#

  2. myusuf Avatar
    myusuf

    These instructions do not work for flarum beta 8. You must update this article for beta 8 version.

Leave a Reply to goze Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.