[Django]-Django could not connect to server: Permission denied Is the server running on host and accepting TCP/IP connections on port remote host

9👍

Based on your description this has something to do with the Apache and it’s permissions to access the database. You didn’t mention which OS you use but if it is running SELinux the default rules prevent apache from connecting to db. If this is the case you can temporarily enable it by running:

setsebool httpd_can_network_connect_db

Here are more detailed instructions.

👤Lycha

5👍

To make changes persistent across reboots (tested on Centos):

setsebool -P httpd_can_network_connect_db on

read more here

0👍

Tested on CentOs.

service httpd stop

service postgresql stop

setsebool -P httpd_can_network_connect 1

service httpd start

service postgresql start

0👍

Giving the wrong authentication credentials to the Django application can lead to this problem. In order to solve it, you can follow these steps:

  1. Check that Postgres is installed:

    apt show postgresql

  2. Check that PostgreSQL is running:

    sudo service postgresql status

  3. Check that you can actually connect to PostgreSQL

    sudo su - postgres

  4. Once in user postgres run the command interface

    psql

  5. Check the connection info by running:

    \conninfo

In my case, I installed Postgres long ago and just forgot access information like username, password, name of database or port access.

Leave a comment