@mnivoliez Blog

Paperwork, a self-hosted Evernote


Beware! This article aims to people who knows linux, command line, mysql, php and nginx.

Hello!

Today we are going to talk about Paperwork!

"What is it?"

Paperwork is a tool to manage notes. In other words, it is like Evernote but at home.

"OK, How do we install it?"

To install Paperwork, open a terminal and enter these commands while being root:

  1. Install php and mysql:
    // ubuntu
    apt-get update
    apt-get install mysql-server php5-mysql  nginx php5-fpm curl wget git php5-cli php5-gd php5-mcrypt nodejs
  2. Make the initial configuration of mysql:
    /usr/bin/mysql_secure_installation
  3. Activate mcrypt in php by modifying /etc/php5/fpm/php.ini and /etc/php5/cli/php.ini:
    extension=mcrypt.so
  4. Install composer:
    curl -sS https://getcomposer.org/installer | php
    mv composer.phar /usr/local/bin/composer
  5. Go to folder /var/www where we are going to set up Paperwork:
    cd /var/www/
  6. Clone Paperwork and enter in it:
    git clone https://github.com/twostairs/paperwork.git
    cd ./paperwork/frontend/
  7. log into mysql and add a new user user with a base for Paperwork:
    mysql -u root -p
    DROP DATABASE IF EXISTS paperwork;
    CREATE DATABASE IF NOT EXISTS paperwork DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
    GRANT ALL PRIVILEGES ON paperwork.* TO 'paperwork'@'localhost' IDENTIFIED BY 'paperwork' WITH GRANT OPTION;
    FLUSH PRIVILEGES;
    quit
  8. Copy default configuration in order to let Paperwork connect to database:
    cp app/storage/config/default_database.json app/storage/config/database.json
  9. Use the script provided by Paperwork to fill up the database:
    php artisan migrate
  10. Give www-data rights to the folder where Paperwork is (beware, on some systems the user isn't www-data but http):
    chown www-data:www-data -R /var/www/
  11. Add nginx configuration:
    vim /etc/nginx/sites-available/paperwork.domain.com
    server {
            listen   80;
            # listen 443 ssl;
    
        root /var/www/paperwork/frontend/public;
        index index.php index.html index.htm;
    
        server_name example.com;
    
        # server_name example.com;
        # ssl_certificate /etc/nginx/ssl/server.crt;
        # ssl_certificate_key /etc/nginx/ssl/server.key;
    
        location / {
                try_files $uri $uri/ /index.php;
        }
    
        error_page 404 /404.html;
    
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
              root /usr/share/nginx/www;
        }
    
        # pass the PHP scripts to FastCGI server listening on the php-fpm socket
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
    
        }
    

    }

    ln -s /etc/nginx/sites-avalaible/paperwork.domain.com /etc/nginx/sites-enable/paperwork.domain.com
    
  12.  Add a file setup to avoid Paperwork configuration failure:
    sudo -u www-data touch app/storage/config/setup
  13.  Install nodejs:
    curl -sL https://deb.nodesource.com/setup_7.x |  bash -
    apt-get install -y nodejs
    
  14. Install bower and gulp globally:
    npm install -g gulp bower
  15.  Install Paperwork dependencies:
    sudo -u www-data npm install
    sudo -u www-data bower install
    sudo -u www-data gulp
  16. Restart nginx et php:
    service nginx restart
    service php5-fpm restart

And voilà! You got Paperwork running on port 80.

-- Mathieu