{"id":16419507,"url":"https://github.com/devmahmud/btre_project","last_synced_at":"2025-04-23T14:31:45.115Z","repository":{"id":103953176,"uuid":"170281619","full_name":"devmahmud/btre_project","owner":"devmahmud","description":"Django real estate website project","archived":false,"fork":false,"pushed_at":"2019-02-12T08:50:11.000Z","size":2433,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-02T16:49:25.236Z","etag":null,"topics":["django","real-estate-website"],"latest_commit_sha":null,"homepage":null,"language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devmahmud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-12T08:34:20.000Z","updated_at":"2023-09-27T18:02:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"70848be3-14a3-4191-b97d-66c1e0ae379c","html_url":"https://github.com/devmahmud/btre_project","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devmahmud%2Fbtre_project","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devmahmud%2Fbtre_project/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devmahmud%2Fbtre_project/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devmahmud%2Fbtre_project/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devmahmud","download_url":"https://codeload.github.com/devmahmud/btre_project/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250451808,"owners_count":21432905,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","real-estate-website"],"created_at":"2024-10-11T07:24:38.261Z","updated_at":"2025-04-23T14:31:45.108Z","avatar_url":"https://github.com/devmahmud.png","language":"CSS","readme":"# btre_project\nDjango real estate website project\n\n\n# Deployment Instructions From Brad Traversy.\n\n# Django Deployment to Ubuntu 18.04\n\nIn this guide I will go through all the steps to create a VPS, secure it and deploy a Django application. This is a summarized document from this [digital ocean doc](https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04)\n\nAny commands with \"$\" at the beginning run on your local machine and any \"#\" run when logged into the server\n\n## Create A Digital Ocean Droplet\n\nUse [this link](https://m.do.co/c/5424d440c63a) and get $10 free. Just select the $5 plan unless this a production app.\n\n# Security \u0026 Access\n\n### Creating SSH keys (Optional)\n\nYou can choose to create SSH keys to login if you want. If not, you will get the password sent to your email to login via SSH\n\nTo generate a key on your local machine\n\n```\n$ ssh-keygen\n```\n\nHit enter all the way through and it will create a public and private key at\n\n```\n~/.ssh/id_rsa\n~/.ssh/id_rsa.pub\n```\n\nYou want to copy the public key (.pub file)\n\n```\n$ cat ~/.ssh/id_rsa.pub\n```\n\nCopy the entire output and add as an SSH key for Digital Ocean\n\n### Login To Your Server\n\nIf you setup SSH keys correctly the command below will let you right in. If you did not use SSH keys, it will ask for a password. This is the one that was mailed to you\n\n```\n$ ssh root@YOUR_SERVER_IP\n```\n\n### Create a new user\n\nIt will ask for a password, use something secure. You can just hit enter through all the fields. I used the user \"djangoadmin\" but you can use anything\n\n```\n# adduser djangoadmin\n```\n\n### Give root privileges\n\n```\n# usermod -aG sudo djangoadmin\n```\n\n### SSH keys for the new user\n\nNow we need to setup SSH keys for the new user. You will need to get them from your local machine\n\n### Exit the server\n\nYou need to copy the key from your local machine so either exit or open a new terminal\n\n```\n# exit\n```\n\nYou can generate a different key if you want but we will use the same one so lets output it, select it and copy it\n\n```\n$ cat ~/.ssh/id_rsa.pub\n```\n\n### Log back into the server\n\n```\n$ ssh root@YOUR_SERVER_IP\n```\n\n### Add SSH key for new user\n\nNavigate to the new users home folder and create a file at '.ssh/authorized_keys' and paste in the key\n\n```\n# cd /home/djangoadmin\n# mkdir .ssh\n# cd .ssh\n# nano authorized_keys\nPaste the key and hit \"ctrl-x\", hit \"y\" to save and \"enter\" to exit\n```\n\n### Login as new user\n\nYou should now get let in as the new user\n\n```\n$ ssh djangoadmin@YOUR_SERVER_IP\n```\n\n### Disable root login\n\n```\n# sudo nano /etc/ssh/sshd_config\n```\n\n### Change the following\n\n```\nPermitRootLogin no\nPasswordAuthentication no\n```\n\n### Reload sshd service\n\n```\n# sudo systemctl reload sshd\n```\n\n# Simple Firewall Setup\n\nSee which apps are registered with the firewall\n\n```\n# sudo ufw app list\n```\n\nAllow OpenSSH\n\n```\n### sudo ufw allow OpenSSH\n```\n\n### Enable firewall\n\n```\n# sudo ufw enable\n```\n\n### To check status\n\n```\n# sudo ufw status\n```\n\nWe are now done with access and security and will move on to installing software\n\n# Software\n\n## Update packages\n\n```\n# sudo apt update\n# sudo apt upgrade\n```\n\n## Install Python 3, Postgres \u0026 NGINX\n\n```\n# sudo apt install python3-pip python3-dev libpq-dev postgresql postgresql-contrib nginx curl\n```\n\n# Postgres Database \u0026 User Setup\n\n```\n# sudo -u postgres psql\n```\n\nYou should now be logged into the pg shell\n\n### Create a database\n\n```\nCREATE DATABASE btre_prod;\n```\n\n### Create user\n\n```\nCREATE USER dbadmin WITH PASSWORD 'abc123!';\n```\n\n### Set default encoding, tansaction isolation scheme (Recommended from Django)\n\n```\nALTER ROLE dbadmin SET client_encoding TO 'utf8';\nALTER ROLE dbadmin SET default_transaction_isolation TO 'read committed';\nALTER ROLE dbadmin SET timezone TO 'UTC';\n```\n\n### Give User access to database\n\n```\nGRANT ALL PRIVILEGES ON DATABASE btre_prod TO dbadmin;\n```\n\n### Quit out of Postgres\n\n```\n\\q\n```\n\n# Vitrual Environment\n\nYou need to install the python3-venv package\n\n```\n# sudo apt install python3-venv\n```\n\n### Create project directory\n\n```\n# mkdir pyapps\n# cd pyapps\n```\n\n### Create venv\n\n```\n# python3 -m venv ./venv\n```\n\n### Activate the environment\n\n```\n# source venv/bin/activate\n```\n\n# Git \u0026 Upload\n\n### Pip dependencies\n\nFrom your local machine, create a requirements.txt with your app dependencies. Make sure you push this to your repo\n\n```\n$ pip freeze \u003e requirements.txt\n```\n\nCreate a new repo and push to it (you guys know how to do that)\n\n### Clone the project into the app folder on your server (Either HTTPS or setup SSH keys)\n\n```\n# git clone https://github.com/yourgithubname/btre_project.git\n```\n\n## Install pip modules from requirements\n\nYou could manually install each one as well\n\n```\n# pip install -r requirements.txt\n```\n\n# Local Settings Setup\n\nAdd code to your settings.py file and push to server\n\n```\ntry:\n    from .local_settings import *\nexcept ImportError:\n    pass\n```\n\nCreate a file called **local_settings.py** on your server along side of settings.py and add the following\n\n- SECRET_KEY\n- ALLOWED_HOSTS\n- DATABASES\n- DEBUG\n- EMAIL\\_\\*\n\n## Run Migrations\n```\n# python manage.py makemigrations\n# python manage.py migrate\n```\n\n## Create super user\n\n```\n# python manage.py createsuperuser\n```\n\n## Create static files\n```\npython manage.py collectstatic\n```\n\n### Create exception for port 8000\n\n```\n# sudo ufw allow 8000\n```\n\n## Run Server\n\n```\n# python manage.py runserver 0.0.0.0:8000\n```\n\n### Test the site at YOUR_SERVER_IP:8000\n\nAdd some data in the admin area\n\n# Gunicorn Setup\n\nInstall gunicorn\n\n```\n# pip install gunicorn\n```\n\nAdd to requirements.txt\n\n```\n# pip freeze \u003e requirements.txt\n```\n\n### Test Gunicorn serve\n\n```\n# gunicorn --bind 0.0.0.0:8000 btre.wsgi\n```\n\nYour images, etc will be gone\n\n### Stop server \u0026 deactivate virtual env\n\n```\nctrl-c\n# deactivate\n```\n\n### Open gunicorn.socket file\n\n```\n# sudo nano /etc/systemd/system/gunicorn.socket\n```\n\n### Copy this code, paste it in and save\n\n```\n[Unit]\nDescription=gunicorn socket\n\n[Socket]\nListenStream=/run/gunicorn.sock\n\n[Install]\nWantedBy=sockets.target\n```\n\n### Open gunicorn.service file\n\n```\n# sudo nano /etc/systemd/system/gunicorn.service\n```\n\n### Copy this code, paste it in and save\n\n```\n[Unit]\nDescription=gunicorn daemon\nRequires=gunicorn.socket\nAfter=network.target\n\n[Service]\nUser=djangoadmin\nGroup=www-data\nWorkingDirectory=/home/djangoadmin/pyapps/btre_project\nExecStart=/home/djangoadmin/pyapps/venv/bin/gunicorn \\\n          --access-logfile - \\\n          --workers 3 \\\n          --bind unix:/run/gunicorn.sock \\\n          btre.wsgi:application\n\n[Install]\nWantedBy=multi-user.target\n```\n\n### Start and enable Gunicorn socket\n\n```\n# sudo systemctl start gunicorn.socket\n# sudo systemctl enable gunicorn.socket\n```\n\n### Check status of guinicorn\n\n```\n# sudo systemctl status gunicorn.socket\n```\n\n### Check the existence of gunicorn.sock\n\n```\n# file /run/gunicorn.sock\n```\n\n# NGINX Setup\n\n### Create project folder\n\n```\n# sudo nano /etc/nginx/sites-available/btre_project\n```\n\n### Copy this code and paste into the file\n\n```\nserver {\n    listen 80;\n    server_name YOUR_IP_ADDRESS;\n\n    location = /favicon.ico { access_log off; log_not_found off; }\n    location /static/ {\n        root /home/djangoadmin/pyapps/btre_project;\n    }\n    \n    location /media/ {\n        root /home/djangoadmin/pyapps/btre_project;    \n    }\n\n    location / {\n        include proxy_params;\n        proxy_pass http://unix:/run/gunicorn.sock;\n    }\n}\n```\n\n### Enable the file by linking to the sites-enabled dir\n\n```\n# sudo ln -s /etc/nginx/sites-available/btre_project /etc/nginx/sites-enabled\n```\n\n### Test NGINX config\n\n```\n# sudo nginx -t\n```\n\n### Restart NGINX\n\n```\n# sudo systemctl restart nginx\n```\n\n### Remove port 8000 from firewall and open up our firewall to allow normal traffic on port 80\n\n```\n# sudo ufw delete allow 8000\n# sudo ufw allow 'Nginx Full'\n```\n\n### You will probably need to up the max upload size to be able to create listings with images\n\nOpen up the nginx conf file\n\n```\n# sudo nano /etc/nginx/nginx.conf\n```\n\n### Add this to the http{} area\n\n```\nclient_max_body_size 20M;\n```\n\n### Reload NGINX\n\n```\n# sudo systemctl restart nginx\n```\n\n### Media File Issue\nYou may have some issues with images not showing up. I would suggest, deleting all data and starting fresh as well as removeing the \"photos\" folder in the \"media folder\"\n```\n# sudo rm -rf media/photos\n```\n\n# Domain Setup\n\nGo to your domain registrar and create the following a record\n\n```\n@  A Record  YOUR_IP_ADDRESS\nwww  CNAME  example.com\n```\n\n### Go to local_settings.py on the server and change \"ALLOWED_HOSTS\" to include the domain\n\n```\nALLOWED_HOSTS = ['IP_ADDRESS', 'example.com', 'www.example.com']\n```\n\n### Edit /etc/nginx/sites-available/btre_project\n\n```\nserver {\n    listen: 80;\n    server_name xxx.xxx.xxx.xxx example.com www.example.com;\n}\n```\n\n### Reload NGINX \u0026 Gunicorn\n\n```\n# sudo systemctl restart nginx\n# sudo systemctl restart gunicorn\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevmahmud%2Fbtre_project","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevmahmud%2Fbtre_project","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevmahmud%2Fbtre_project/lists"}