Install Paperwork on Ubuntu

install paperwork

In this article, we will explain how to install Paperwork on an Ubuntu 16.04 VPS with MariaDB, PHP-FPM and Nginx. Paperwork is an open-source, self-hosted alternative to services like Evernote, Microsoft OneNote or Google Keep and it is built on top of Laravel 4.2. This guide should work on other Linux VPS systems as well but was tested and written for an Ubuntu 16.04 VPS.

1. Login to your VPS via SSH

ssh user@vps_IP

2. 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 curl

3. Install MariaDB 10.1

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

[user]$ sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
[user]$ sudo add-apt-repository 'deb [arch=amd64,i386] http://ftp.osuosl.org/pub/mariadb/repo/10.1/ubuntu xenial main'
s[user]$ sudo apt-get update
[user]$ sudo apt-get install -y mariadb-server

4. Secure the Installation

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

[user]$ mysql_secure_installation

5. Create a New Database

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

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

6. Install PHP, Composer and required PHP modules

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

[user]$ sudo apt-get -y install php-fpm php-cli php-json php-curl php-gd php-mysql php-mcrypt php-mbstring

The following commands will set the PHP memory limit to 512MB, change the values of upload_max_filesize and post_max_size to 200M and set the timezone to UTC.

[user]$ sudo sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/7.0/fpm/php.ini
[user]$ sudo sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/7.0/fpm/php.ini
[user]$ sudo sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=1/" /etc/php/7.0/fpm/php.ini
[user]$ sudo sed -i "s/upload_max_filesize = .*/upload_max_filesize = 200M/" /etc/php/7.0/fpm/php.ini
[user]$ sudo sed -i "s/post_max_size = .*/post_max_size = 200M/" /etc/php/7.0/fpm/php.ini

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

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 = /run/php/php7.0-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

7. Install Node.Js

We will install the latest nodejs package from the nodesource repository.

[user]$ curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
[user]$ sudo apt-get install -y nodejs

Once Node is installed, install the gulp and bower packages globally using NPM.

[user]$ sudo npm install -g gulp bower

8. Install Paperwork

Create a root directory for your Paperwork using the following command:

[user]$ mkdir -p ~/myPaperwork.com/public_html

Clone the project repository from GitHub:

[user]$ git clone https://github.com/twostairs/paperwork.git ~/myPaperwork.com/public_html

Change to public_html the directory:

[user]$ cd  ~/myPaperwork.com/public_html/frontend

9. Install all PHP dependencies

Install all PHP dependencies using composer

[user]$ composer install

Create a “database.json” file by copying the “default_database.json” file:

[user]$ cp app/storage/config/default_database.json app/storage/config/database.json

Enter your MySQL credentials into the database.json file:

[user]$ nano  app/storage/config/database.json
{
    "driver": "mysql",
    "database": "paperwork",
    "host": "localhost",
    "username": "paperwork",
    "password": "strong_password",
    "port": 3306
}

and run the following command to migrate the database:

[user]$ php artisan migrate

install all npm dependencies

[user]$ npm install

install bower dependencies and run gulp to build the assets

[user]$ bower install
[user]$ gulp

10. Install and configure Nginx

To install the latest stable version of Nginx available on the Ubuntu repositories, run:

[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 paperwork.pass.key 2048
[user]$ sudo openssl rsa -passin pass:x -in paperwork.pass.key -out paperwork.key
[user]$ sudo rm paperwork.pass.key
[user]$ sudo openssl req -new -key paperwork.key -out paperwork.csr
[user]$ sudo openssl x509 -req -days 365 -in paperwork.csr -signkey paperwork.key -out paperwork.crt

[user]$ sudo openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
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/myPaperwork.com
server {
    listen 443 ssl http2;
    server_name myPaperwork.com;
    root /home/your_user/myPaperwork.com/public_html/frontend/public;
    index index.php index.html index.htm;

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

    ssl on;
    ssl_certificate     /etc/nginx/ssl/paperwork.crt;
    ssl_certificate_key /etc/nginx/ssl/paperwork.key;
    ssl_dhparam  /etc/nginx/ssl/dhparam.pem;

    ssl_session_timeout 5m;
    ssl_ciphers  EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

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

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php7.0-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 myPaperwork.com;

    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/myPaperwork.com /etc/nginx/sites-enabled/myPaperwork.com

11. Restart Web Server and Test

Test the Nginx configuration and restart nginx:

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

Open http://myPaperwork.com/ in your favorite web browser and you should see the Paperwork install screen. On this page you’ll need to enter the database details you created earlier, and create an admin user.

That’s it. You have successfully installed Paperwork on your Ubuntu 16.04 VPS.


Of course you don’t have to do any of this if you use one of our 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, on how to Install Paperwork on Ubuntu,  please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

Leave a Comment