Загрузка...

Integrate PostgreSQL with Django on AWS EC2 | Setup PostgreSQL Database for Django Project

Learn how to integrate a PostgreSQL database with your Django project on an AWS EC2 server! This tutorial covers installing PostgreSQL, configuring the database settings in Django, creating and migrating database tables, and ensuring a secure connection. Perfect for developers looking to use PostgreSQL as a production database for their Django applications on AWS. Watch now to master PostgreSQL integration with Django on EC2!

sudo apt install postgresql postgresql-contrib -y

sudo systemctl start postgresql
sudo systemctl enable postgresql
sudo systemctl status postgresql

sudo -i -u postgres
psql

CREATE DATABASE testproject;
CREATE USER django WITH PASSWORD 'mypassword';
ALTER ROLE django SET client_encoding TO 'utf8';
ALTER ROLE django SET default_transaction_isolation TO 'read committed';
ALTER ROLE django SET timezone TO 'UTC';
GRANT ALL PRIVILEGES ON DATABASE testproject TO django;

\q
exit

sudo nano /etc/postgresql/14/main/postgresql.conf
listen_addresses = '*'

sudo nano /etc/postgresql/14/main/pg_hba.conf
host all all 0.0.0.0/0 md5

sudo systemctl restart postgresql

Go to AWS Console → EC2 → Security Groups.
Select the Security Group for your EC2 instance.
Click Edit inbound rules.
Add Rule:

Type: PostgreSQL
Protocol: TCP
Port Range: 5432
Source: 0.0.0.0/0

update in setting.py page

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'testproject',
'USER': 'django',
'PASSWORD': 'mypassword',
'HOST': '13.49.225.87',
'PORT': '5432',
}
}

source /home/ubuntu/djangoone/venv/bin/activate
pip install psycopg

sudo systemctl restart gunicorn
sudo systemctl restart nginx
python manage.py migrate

#Django #PostgreSQL #AWS #AWSEC2 #DjangoDatabase #DjangoTutorial #PythonDjango #AWSCloud #WebDevelopment #DatabaseIntegration

Видео Integrate PostgreSQL with Django on AWS EC2 | Setup PostgreSQL Database for Django Project канала TeluguPy
Страницу в закладки Мои закладки
Все заметки Новая заметка Страницу в заметки