Postgresql and apache2 mod_wsgi

  • Posted on April 11, 2014
  • ilanAsked by ilan

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.

Submit an answer

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!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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. <br> <br>What’s the output of: <br> <br>grep unix_socket /etc/postgresql/9.1/main/postgresql.conf

I’m getting the following error from apache log: <br> <br>“”“OperationalError at / <br> <br>could not connect to server: No such file or directory <br> Is the server running locally and accepting <br> connections on Unix domain socket “/tmp/.s.PGSQL.5432”? <br>”“” <br>Everything works perfectly with test server, ie: postgresql is up and running fine… in pgsql log no connection attemp recorded.

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 ?