Postgresql and apache2 mod_wsgi

April 11, 2014 1.8k views
I've done this set up a 1000 times, new to digitalocean... I've set up a server with Django/posgresql/apache/mod_wsgi... I use pyscopg2 to connect to postgresql from django. Everything works fine execept I can't connect to postgresql when running under apache/mod_wsgi. I've been successful at running django app server and connecting to app locally with lynx. So issue is isolated to mod_wsgi... I have no idea why I can't connect I'm assuming it's permission to access postgresql socket ... but not sure... postgresql socket resides in /tmp.
3 Answers
Some more details would help. Are you getting any error output that could help us run this down, a traceback or something in /var/log/apache2/error.log ?
I'm getting the following error from apache log:

"""OperationalError at /

could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Everything works perfectly with test server, ie: postgresql is up and running fine.... in pgsql log no connection attemp recorded.
That looks like a file permissions error. That would explain why you can use the Django server, but not Apache. Your user has the correct permissions to access the socket, so when you connect using the built-in Django server it works. The Apache process is running under a different user (www-data), nad it doesn't seem to have the correct permissions.

What's the output of:

grep unix_socket /etc/postgresql/9.1/main/postgresql.conf
Have another answer? Share your knowledge.