How to install FileRun on Ubuntu 20 with NGINX

For an alternative using Apache, use this tutorial.

In this tutorial, we will install a FileRun instance on an Ubuntu 20 server running NGINX, PHP and MariaDB. We will also configure the server with an SSL certificate and install any third-party software FileRun might make use of, so that you can enjoy all FileRun features on a secure server.

Step 1: Update Software Packages

Before we install the LEMP stack, it's a good practice to update repository and software packages by running the following commands on your Ubuntu 20 OS.

 1sudo apt update
 2sudo apt upgrade

Step 2 --- Install Nginx Web Server

Nginx is a high-performance web server and very popular these days. It also can be used as a reverse proxy and caching server. Enter the following command to install Nginx Web server.

 1sudo apt install nginx

After it's installed, we can enable Nginx to auto-start at boot time by running the following command.

 1sudo systemctl enable nginx

Then start Nginx with this command:

 1sudo systemctl start nginx

Opening the IP/hostname/domain of your server in the browser, should show the NGINX welcome page:

Step 3 - Install MariaDB Database Server

Now that we have our web server up and running, it is time to install a database server. This server will be managing the FileRun database which holds the application settings, the users settings and information about your files.

With two simple commands the database server MariaDB will be installed and running:

 1sudo apt install mariadb-server mariadb-client

If it's not running, start it with this command:

 1sudo systemctl start mariadb

To enable MariaDB to automatically start at boot time, run

 1sudo systemctl enable mariadb

Now run the post installation security script.

 1sudo mysql_secure_installation

The prompt will ask you for your current MariaDB root password. Since you just installed MariaDB, you won't have one, so leave it blank by pressing ENTER. Then the prompt will help you set a password:

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorization.

Set root password? [Y/n] y
New password: PASSWORD
Re-enter new password: PASSWORD
Password updated successfully!
Reloading privilege tables..
 ... Success!

For the rest of the questions, you should simply hit the ENTER key through each prompt to accept the default values. This will remove some sample users and databases, disable remote root logins, and load these new rules, so that MariaDB immediately respects the changes we have made.

Setting Up FileRun's Database

The MariaDB server should be now ready for creating our FileRun database and the user account which will access it.

To get started, log into MySQL with the root account:

 1sudo mysql

While you can name your FileRun database whatever you prefer, we will be using the name filerun for this example.

 1CREATE DATABASE filerun;

Next, create a separate MySQL user account that will manage the newly created database. Creating one-function databases and accounts is a good idea from a management and security standpoint. As with the naming of the database, choose a username that you prefer. We chose to go with the name filerun for this guide.

 1CREATE USER 'filerun'@'localhost' IDENTIFIED BY 'YOUR-DB-PASSWORD';

Note: Be sure to put an actual password where the command states: YOUR-DB-PASSWORD

Now grant all privileges to the user on the newly created database:

 1GRANT ALL ON filerun.* TO 'filerun'@'localhost';

With the user assigned access to the database, perform the flush-privileges operation to ensure that the running instance of MySQL knows about the recent privilege assignment:

 1FLUSH PRIVILEGES;

This concludes the configuration of MySQL, therefore we will quit the session by typing:

 1exit

Make a note of the database name filerun, the username filerun and the password YOUR-DB-PASSWORD as we will need this information again shortly.

Step 5 --- Install PHP 7.4

Enter the following command to install PHP 7.4 and the extensions needed by FileRun.

 1sudo apt install php7.4 php7.4-fpm php7.4-mysql php7.4-cli php7.4-common php7.4-json php7.4-opcache  php7.4-mbstring php7.4-xml php7.4-zip php7.4-gd php7.4-curl php7.4-gd php7.4-ldap php7.4-imagick

Step 6 --- Install PHP ionCube extension

One last PHP extension which needs manual installation is ionCube:

Download the package (Linux 64 bit):

 1sudo wget https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz

And extract it

 1sudo tar -xzf ioncube_loaders_lin_x86-64.tar.gz -C /usr/lib/php

Now, let's load PHP with the downloaded extension:

 1sudo vim /etc/php/7.4/fpm/conf.d/00-ioncube.ini

And paste the following inside:

 1zend_extension = /usr/lib/php/ioncube/ioncube_loader_lin_7.4.so

With the ionCube extension installed, let's create a file which will automatically get appended by PHP to its configuration. This will include all the settings needed by FileRun.

 1sudo vim /etc/php/7.4/fpm/conf.d/filerun.ini

Paste the following inside the created file:

 1expose_php              = Off
 2error_reporting         = E_ALL & ~E_NOTICE
 3display_errors          = Off
 4display_startup_errors  = Off
 5log_errors              = On
 6ignore_repeated_errors  = Off
 7allow_url_fopen         = On
 8allow_url_include       = Off
 9variables_order         = "GPCS"
10allow_webdav_methods    = On
11memory_limit            = 128M
12max_execution_time      = 300
13output_buffering        = Off
14output_handler          = ""
15zlib.output_compression = Off
16zlib.output_handler     = ""
17safe_mode               = Off
18register_globals        = Off
19magic_quotes_gpc        = Off
20upload_max_filesize     = 20M
21post_max_size           = 20M
22enable_dl               = Off
23disable_functions       = ""
24disable_classes         = ""
25session.save_handler     = files
26session.use_cookies      = 1
27session.use_only_cookies = 1
28session.auto_start       = 0
29session.cookie_lifetime  = 0
30session.cookie_httponly  = 1
31date.timezone            = "UTC"

Note: You can find the latest FileRun recommended PHP settings here.

Finally, let's restart PHP-FPM:

 1sudo systemctl restart php7.4-fpm

Enable auto-start at boot time.

 1sudo systemctl enable php7.4-fpm

Check status:

 1systemctl status php7.4-fpm

The output will read active (running). If the above command doesn't immediately quit after running. You need to press q to make it quit.

Step 7: Configure NGINX with PHP

Create an Nginx Server Block. An NGINX server block is like a virtual host in Apache. We will not use the default server block because it's inadequate to run PHP code and if we modify it, it becomes a mess. So remove the default symlink in sites-enabled directory by running the following command. (It's still available as /etc/nginx/sites-available/default.)

 1sudo rm /etc/nginx/sites-enabled/default

Then create a brand new server block file under /etc/nginx/conf.d/ directory.

 1sudo vim /etc/nginx/conf.d/default.conf

Paste the following inside:

server {
  listen 80;
  listen [::]:80;
  server_name _;
  root /var/www/html/;
  index index.php index.html;

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

  location ~ [^/]\.php(/|$) {
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    if (!-f $document_root$fastcgi_script_name) {
        return 404;
    }

   
    include fastcgi_params;
    include snippets/fastcgi-php.conf;

    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_pass unix:/run/php/php7.4-fpm.sock;
  }

 # A long browser cache lifetime can speed up repeat visits to your page
  location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
       access_log        off;
       log_not_found     off;
       expires           360d;
  }

  # disable access to hidden files
  location ~ /\.ht {
      access_log off;
      log_not_found off;
      deny all;
  }
}

Then test the NGINX configuration:

 1sudo nginx -t

If the test is successful, reload NGINX:

 1sudo systemctl reload nginx

Your server now meets all the requirements, and we can proceed with installing FileRun.

Step 8 --- Installing FileRun

Clean the default files from the root folder of your webserver (/var/www/html/):

 1cd /var/www/html/
 2sudo rm index.nginx-debian.html

Download FileRun:

Download the FileRun installation zip archive from the FileRun client account: https://my.filerun.com

Install unzip:

 1sudo apt-get install unzip

Extract the downloaded FileRun archive:

 1sudo unzip FileRun.zip

Make the HTTP server the owner of the folder so that it can make change:

 1sudo chown -R www-data:www-data /var/www/html/

Open your browser and point it to http://YOUR-SERVER-IP

From here, you just have to follow the web installer, which will help you get FileRun running with just a few clicks.

From here you just have to follow the installer, which will help you get FileRun running with just a few clicks:

FileRun installer welcome
screen FileRun installer welcome screen

Click Next to proceed. Review the server requirements check and make sure there is no red error message:

FileRun server requirements
check FileRun server requirements check

Click Next to proceed with the database connection setup:

FileRun database connection
setup FileRun database connection setup

You will be presented with the following screen, letting you know that FileRun has been successfully installed:

FileRun successful
installation FileRun successful installation

Warning: Make sure you made a copy of the username and password displayed on the screen, before proceeding. The password is being randomly generated at this step. Do not use the password from this tutorial screenshot, it won't work on your install.

Click Next to open FileRun. You should see the login page:

FileRun login
page FileRun login page

The form should be prefilled, so you can just hit Sign in.

Securing the FileRun installation

Read more about this here.

Sign in as FileRun superuser, open the control panel and select the Software update option, click the Check for updates and install eventual available updates. This will make sure you are running the latest available FileRun version.

The permissions of the FileRun application files should not allow PHP (or any other web server application) to make changes to them:

 1sudo chown -R root:root /var/www/html

The system/data FileRun folder is the only folder where PHP needs write access.

 1sudo chown -R www-data:www-data /var/www/html/system/data

Now let's set the FileRun superuser's home folder. It is important that the home folder path is pointing to a folder which is located outside the public area of your web server (ie. outside /var/www/html). You could create a folder /files and store all the FileRun files in there:

 1sudo mkdir /files
 2sudo chown www-data:www-data /files

Installing Vips, ImageMagick, FFmpeg, LibreOffice

Coming soon..

Conclusion

You have now successfully deployed FileRun on a Ubuntu 20 server with NGINX and PHP 7.4. It's time to upload your files, photos, music or work documents and start sharing.