In this tutorial, we will install a FileRun instance on an Ubuntu 16 server running Apache, MySQL and PHP 7. 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.

Prerequisites

Before you begin this tutorial you'll need an Ubuntu 16 server, with Apache, MySQL and PHP.

Please follow this tutorial to set the prerequisites up: How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04

Step 1 — Setting Up FileRun's Database

The MySQL database server is now configured and we can proceed with creating our FileRun database and the user account which will access it.

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

mysql -u root -p  

Enter the password you set for the MySQL root user when you installed the server.

FileRun requires a separate database for storing its data. While you can call this database whatever you prefer, we will be using the name filerun for this example.

CREATE 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.

GRANT ALL ON filerun.* to 'filerun'@'localhost' IDENTIFIED BY 'YOUR-DB-PASSWORD';  

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

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:

FLUSH PRIVILEGES;  

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

exit  

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 2 — Configuring PHP

The following command will install the PHP modules needed by FileRun:

sudo apt-get install php-mbstring php-zip php-curl php-gd php-ldap php-xml  

One last module which needs manual install is ionCube.

Please follow this tutorial to get ionCube installed: How To Install ionCube on Ubuntu 16.04




Introduction

ionCube is a PHP module extension that loads encrypted PHP files and speeds up webpages. It is often required for PHP-based applications. In this tutorial, we will install ionCube on a Ubuntu 16.04 server.

Prerequisites

To follow this tutorial, you will need:

  • One Ubuntu 16.04 server with a sudo non-root user and firewall, which you can set up by following this initial server setup tutorial.
  • A web server with PHP installed, like Apache or Nginx. Follow the steps for installing the web server itself, updating the firewall, and installing PHP.
 

Step 1 — Choosing the Right ionCube Version

It is important that the version of ionCube you choose matches your PHP version, so first, you need to know:

  • The version of PHP our web server is running, and
  • If it is 32-bit or 64-bit.

If you have a 64-bit Ubuntu server, you are probably running 64-bit PHP, but let's make sure. To do so, we'll use a small PHP script to retrieve information about our server's current PHP configuration.

Create a file called info.php file in the root directory of your web server (likely /var/www/html, unless you've changed it) using nano or your favorite text editor.

  • sudo nano /var/www/html/info.php

Paste the following inside the file, then save and close it.

info.php
<?php
phpinfo();

After saving the changes to the file, visit http://your_server_ip/info.php in your favorite browser. The web page you've opened should look something like this:

Ubuntu 16.10 default PHP info

From that page, look at the header at the top where it says PHP Version. In this case, we're running 7.0.8. Then, look at the System line. If it ends with x86_64, you're running 64-bit PHP; if it ends with i686, it's 32-bit.

With this information, you can proceed with the download and installation.

Step 2 — Setting Up ionCube

Visit the ionCube download page and find the appropriate download link based on your OS. In our example, we need the this 64-bit Linux version. Copy the tar.gz link on the site and download the file.

Next, extract the archive.

  • tar xvfz ioncube_loaders_lin_x86-64.tar.gz

This creates a directory named ioncube which contains various files for various PHP versions. Choose the right folder for your PHP version. In our example, we need the file PHP version 7.0, which is ioncube_loader_lin_7.0.so. We will copy this file to the PHP extensions folder.

To find out the path of the extensions folder, check the http://your_server_ip/info.php page again and search for extension_dir.

extension_dir PHP configuration directive

In this example, it's /usr/lib/php/20151012, so copy the file there:

  • sudo cp ioncube/ioncube_loader_lin_7.0.so /usr/lib/php/20151012/

For PHP to load the extension, we need to add it to the PHP configuration. We can do it in the main php.ini PHP configuration file, but it's cleaner to create a separate file. We can set this separate file to load before other extensions to avoid possible conflicts.

To find out where we should create the custom configuration file, look at http://your_server_ip/info.php again and search for Scan this dir for additional .ini files.

Additional PHP configuration files

So, we'll create a file named 00-ioncube.ini inside the /etc/php/7.0/apache2/conf.d directory. The 00 at the beginning of the filename ensures this file will be loaded before other PHP configuration files.

  • sudo nano /etc/php/7.0/apache2/conf.d/00-ioncube.ini

Paste the following loading directive, then save and close the file.

00-ioncube.ini
zend_extension = "/usr/lib/php/20151012/ioncube_loader_lin_7.0.so"

For the above change to take effect, we will need to restart the web server.

If you are using Apache, run:

  • sudo systemctl restart apache2.service

If you are using Nginx, run:

  • sudo systemctl restart nginx

You may also need to restart php-fpm, if you're using it.

  • sudo systemctl restart php7.0-fpm.service

Finally, let's make sure that the PHP extension is installed and enabled.

Step 3 — Verifying the ionCube Installation

Back on the http://your_server_ip/info.php page, refresh the page and search for the "ionCube" keyword. You should now see with the ionCube PHP Loader (enabled):

ionCube installed

That confirms that the PHP ionCube extension is loaded on your server.

It can be a bit of a security risk to keep the info.php script, as it allows potential attackers to see information about your server, so remove it now.

  • sudo rm /var/www/html/info.php

You can also safely remove the extra downloaded ionCube files which are no longer necessary.

  • sudo rm ioncube_loaders_lin_x86-64.tar.gz
  • sudo rm -rf ioncube_loaders_lin_x86-64

ionCube is now fully set up and functional.




With ionCube 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.

sudo nano /etc/php/7.0/apache2/conf.d/filerun.ini  

Paste the following inside the created file:

expose_php              = Off  
error_reporting         = E_ALL & ~E_NOTICE  
display_errors          = Off  
display_startup_errors  = Off  
log_errors              = On  
ignore_repeated_errors  = Off  
allow_url_fopen         = On  
allow_url_include       = Off  
variables_order         = "GPCS"  
allow_webdav_methods    = On  
memory_limit            = 128M  
max_execution_time      = 300  
output_buffering        = Off  
output_handler          = ""  
zlib.output_compression = Off  
zlib.output_handler     = ""  
safe_mode               = Off  
register_globals        = Off  
magic_quotes_gpc        = Off  
upload_max_filesize     = 20M  
post_max_size           = 20M  
enable_dl               = Off  
disable_functions       = ""  
disable_classes         = ""  
session.save_handler     = files  
session.use_cookies      = 1  
session.use_only_cookies = 1  
session.auto_start       = 0  
session.cookie_lifetime  = 0  
session.cookie_httponly  = 1  
date.timezone            = "UTC"  

Note: You can find the latest FileRun recommended PHP settings here: http://docs.filerun.com/php_configuration

Finally, we need to restart Apache for the changes to take effect:

sudo systemctl restart apache2  

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

Step 3 — Installing FileRun

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

cd /var/www/html/  
sudo rm index.html  
sudo rm info.php  

Download FileRun:

sudo wget -O FileRun.zip http://www.filerun.com/download-latest  

Install unzip:

sudo apt-get install unzip  

Extract the downloaded FileRun archive:

sudo unzip FileRun.zip  

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

sudo 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

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

FileRun server requirements check

Click Next to proceed with the database connection setup:

  • Type in the Database name you used at the step 2 of this tutorial: filerun
  • Type in the MySQL userfilerun
  • Type in the Passwordset_database_password
  • Then click Next

FileRun database connection setup

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

FileRun successfull 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

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

Step 4 — Securing the FileRun installation

As soon as you sign into FileRun you will be prompted to change the password. Although the automatically generated password is quite secure, it's still a good idea to set your own.

Warning: The FileRun superuser is the only account not protected against brute force login attacks, so it is very important that you set a password that cannot be guessed by a computer. Set a long password, containing also uppercase letters, digits and symbols.

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:

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

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

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

By default, the superuser's home folder is located inside /var/www/html/system/data/ folder. It is important that you edit the user account, from the FileRun control panel, and set the home folder path 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:

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

Connect to the MySQL server as root again:

mysql -u root -p  

Update the configured MySL user account and remove the ALTER and DROPprivileges.

REVOKE ALTER, DROP ON filerun.* FROM 'filerun'@'localhost';  
FLUSH PRIVILEGES;  

Note: You will need to add these permissions back before you will be installing any FileRun software update in the future. To do that, connect again to the database server and runt the following commands:

GRANT  ALTER, DROP ON filerun.* TO 'filerun'@'localhost';  
FLUSH PRIVILEGES;  
exit;  

Installing ImageMagick and FFmpeg

For generating thumbnails for image files, photography files and even PDF documents, install ImageMagick like this:

sudo apt-get install imagemagick  

And enable it inside FileRun from the control panel, under the System configuration > Files > Image preview section, using the path /usr/bin/convert.

For generating thumbnails for video files install FFmpeg like this:

sudo apt-get install ffmpeg  

And enable it inside FileRun from the control panel, under the System configuration > Files > Image preview section, using the path /usr/bin/ffmpeg.

Installing a SSL certificate with Let's Encypt

This is highly recommended, to improve the security of your data and also to allow to access the FileRun API which the mobile apps use.

To proceed, please follow this tutorial: How To Secure Apache with Let's Encrypt on Ubuntu 16.04

Additional Apache Configuration

Enabling mod_rewrite

mod_rewrite is an Apache module used for URL manipulations. FileRun needs this for certain features, such as opening an Microsoft Office file directly in your local program, without downloading it first.

sudo a2enmod rewrite  

This will activate the module or alert you that the module is already in effect. To put these changes into effect, restart Apache:

sudo service apache2 restart  
Enabling .htaccess

A .htaccess file allows us to have custom configuration, defined per folder, without having to edit the Apache main configuration files.

By default, Apache prohibits using an .htaccess file, so first you need to allow changes to the file. Open the default Apache configuration file using nano or your favorite text editor.

sudo nano /etc/apache2/apache2.conf  

Inside that file, you will find the block <Directory /var/www/>. Inside of that block, make sure AllowOverride is set to All.

<Directory /var/www/>  
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>  

Save and close the file. To put these changes into effect, restart Apache.

sudo systemctl restart apache2  

Conclusion

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

For more information on FileRun features and settings, visit http://docs.filerun.com