Code Monkey home page Code Monkey logo

deploydjango's Introduction

DeployDjango

Install libs

sudo apt-get install -y python3-pip python3-venv build-essential libssl-dev libffi-dev python3-dev python3-wheel

*** Additional libs

sudo apt-get install -y git libpq-dev

Create and activate virtual enviroment

python3 -m venv my_env
source my_env/bin/activate

Clone repository from github.com

git clone ...

Set PostgreSQL

Installation

sudo apt install postgresql postgresql-contrib
postgres service start
sudo -u postgres psql

Set postgres for Django

ALTER ROLE myprojectuser SET client_encoding TO 'utf8';
ALTER ROLE myprojectuser SET default_transaction_isolation TO 'read committed';
ALTER ROLE myprojectuser SET timezone TO 'UTC';

Create role

sudo -u postgres psql
CREATE DATABASE yourdbname;
CREATE USER youruser WITH ENCRYPTED PASSWORD 'yourpass';
GRANT ALL PRIVILEGES ON DATABASE yourdbname TO youruser;

Configure PostgreSQL to allow remote connection

By default PostgreSQL is configured to be bound to "localhost". To view all open ports we should execute ss -nlt on command line. We recieve an output like this:

Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:11211         0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:3737          0.0.0.0:*               LISTEN

As we can see above port 5432 is bound to 127.0.0.1. It means any attempt to connect to the postgresql server from outside the machine will be refused. In order to fix this issue we need to find postgresql.conf.

sudo find / -name "postgresql.conf" | head -1 |sudo xargs -o vim

Replace line

listen_addresses = 'localhost'

with

listen_addresses = '*'

Now restart postgresql server.

sudo service postgresql restart

Configuring pg_hba.conf

Find and open pg_hba.conf file:

sudo find / -name "pg_hba.conf"|sudo xargs -o vim

Add following entry at the very end

host    all             all              0.0.0.0/0                       md5
host    all             all              ::/0                            md5

Restart postgresql server

sudo service postgresql restart

Some guides:

deploydjango's People

Contributors

igiyazov avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.