postgres access over the web

June 27, 2016 676 views
PostgreSQL Python Apache Ubuntu 16.04

We have a successful implementation of a web page hosted on another provider. We are able to access our postgres database using javascript that calls python and uses psycopg2 to create a database connection. with that provider there seems to be less restrictions on access to the DB.

On Digital Ocean
After much research I realized I had to create a specific user in the postgres DB to allow access from a linux user:

For Example postgres Database:
database db1
Schema Public
Tables: testtable (owner root)
have granted full access on all tables to user jim ( also have a linux user jim)

In linux I can su to user jim and log into the database and see table testtable.

Now...

When I attempt to run the query through the web browser it seems like the connection is failing. I have also created a postgis user called "www-data" and granted full access to the tables.

I assumed was the browser user is using as user www-data.

So...
The questions I have are:
1) Am I correct in assuming that the web calls are made by "www-data"?
2) Does it sound like Is there something I have not configured to allow DB access from web/javascript/python?

Much thanks in advance:

1 Answer

OK I have found the answer - I needed to allow python to be executed by apache:

1) Am I correct in assuming that the web calls are made by "www-data"?
Yes and this can be modified in /etc/apache2/envvars
# /etc/init.d/apache2, /etc/logrotate.d/apache2, etc.
export APACHERUNUSER=www-data
export APACHERUNGROUP=www-data

2) Does it sound like Is there something I have not configured to allow DB access from web/javascript/python?
The problem I was having was not related to postgres it was apache not being able to run python
fix by following this article: https://www.linux.com/blog/configuring-apache2-run-python-scripts

Have another answer? Share your knowledge.