1
0
forked from blue/pica
pica/README.md

2.7 KiB

Pica - Backend for Megpie budgeting app

... some description

Prerequisites

  • fcgi
  • nlohmann_json
  • mariadb-client
  • argon2

Building

$ git clone https://git.macaw.me/blue/pica
$ cd pica
$ mkdir build
$ cd build
$ cmake ..
$ cmake --build .

Usage

Webserver

First you need a webserver. In this example I'm going to use apache.

Install apache (apache2, httpd) from your package manager.

Create a file like this in apache config dir (in my case it's /etc/httpd/conf/extra/fcgi-pica.conf)

<Location /pica>
    <IfModule mod_headers.c>
        Header set Access-Control-Allow-Origin "*"
        Header set Access-Control-Allow-Headers: "*"
    </IfModule>

    ProxyPass "unix:/run/pica/pica.sock|fcgi://localhost"
    ProxyPassReverse "http://localhost"
</Location>

Incude this file from apache config file (in my case it's /etc/httpd/conf/httpd.conf)

Include conf/extra/fcgi-pica.conf

Also you need to have 3 modules enabled:

  • proxy
  • proxy_fcgi
  • headers

Usually you need to uncomment following lines in /etc/httpd/conf/httpd.conf

LoadModule headers_module modules/mod_headers.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

In case you use debian-like distro (ubuntu) you should use a2enmod command instead:

# a2enmod proxy_fcgi

This should enable all modules, because module proxy_fcgi has module proxy as a dependency, and headers are supposed to be enabled.

Start apache

$ sudo systemctl start httpd

Database

You're also goint to need a database server. For now only MySQL/Mariadb is supported. I'm going to use Mariadb as an example.

First - install mariadb (the server!). Set it up, edit config, run whatever it asks you to run on installation. Making configurations, make sure it creates a unix socket at /run/mysqld/mysqld.sock and user running pica has permissions to write to this socket! By default it does, so, you're probably okay with default configuration.

Next you need to login to mariadb database server, usually it's done like so:

$ mariadb -u root -p

It will query your password, and then you should see mariadb propt. There you need to execute following commands:

CREATE DATABASE pica;
CREATE USER 'pica'@'localhost' IDENTIFIED BY 'pica';
GRANT ALL PRIVILEGES ON pica.* TO 'pica'@'localhost';
FLUSH PRIVILEGES;

Flushing privileges is not really needed, but it's typicaly written. After that just quit mariadb with quit; command.

Creating a directory

Next you need to create a directory for pica socket file

# mkdir /run/pica
# chown <your user> /run/pica

Running an app

At this stage we're redy to run an app

$ cd build
$ ./pica