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:
Much thanks in advance:
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
OK I have found the answer - I needed to allow python to be executed by apache:
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 APACHE_RUN_USER=www-data export APACHE_RUN_GROUP=www-data
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.