Denhac / ApplicationAPI

4 stars 0 forks source link

Pre-Reqs

Setup

Make sure your host is up to date first yum update

Note, on a Centos server with mysql added during the install process all I had to do was:

yum install epel-release libdbi-dbd-mysql
yum update
yum install gnucash

I'm pretty sure that gnucash ships with the python bindings these days, but your mileage may vary.

On a Ubuntu distribution, try:

sudo apt-get install mysql-server
sudo apt-get install gnucash
sudo apt-get install python-gnucash
sudo apt-get install libdbd-mysql

Flask Setup

We are using Flask as a framework to speed development and give us access to many pre-built libraries:

yum install epel-release
yum update

yum install python-pip python-ldap MySQL-python
pip install flask
pip install --upgrade pip

The Flask functions are loaded into Apache via the wsgi_mod:

yum install mod_wsgi

See more info here: http://flask.pocoo.org/docs/0.10/deploying/mod_wsgi/

Local Testing

  1. Create a user and test database. (Modify the username, database, and password if you like.) mysql -u root create database gnucash; create user 'gnucash'@'localhost' IDENTIFIED BY 'yourPasswordHere'; grant ALL privileges on gnucash.* to 'gnucash'@'localhost'; You'll have to update the connection string in scripts to reflect your password if you are connecting to the Denhac server.
  2. Restore the test data into the database. This can be done any time you want to reset. It will automatically drop existing tables and recreate the test setup. mysql gnucash -u gnucash -p < path_to_devdata.sql;
  3. Run the test script to verify connection. edit test-connection.py

Sources

The best way to learn about the python bindings are to look at the example scripts at http://svn.gnucash.org/trac/browser/gnucash/trunk/src/optional/python-bindings/example_scripts

References

1/26/16: Additional Steps found missed when moving from Dev->Prod

yum install MySQL-python dos2unix adduser apiuser

Go edit /etc/passwd to make apiuser nologin

setsebool -P httpd_can_network_connect on setenforce 0 vi /etc/selinux/config

Change SELINUX=permissive

mkdir /var/www/log chmod 777 /var/www/log touch /var/www/log/apifunctions.log chmod 666 /var/www/log/apifunctions.log