How to deploy a django project on Reg.ru

Clock
16.03.2025
Clock
15.04.2025
Clock
4 minutes
An eye
128
Hearts
0
Connected dots
0
Connected dots
0
Connected dots
0

Introduction

In this article, which will be the final one for the series of articles about the search results scraper. I will show you how to deploy a site on Django, the frontend of which is written in React, on servers from the hosting provider reg.ru. I will start with the fact that you should already be registered and have paid hosting and a domain name. Everything, of course, from the hosting provider, reg.ru. I want to note that they have a very beautiful design of the admin panel and personal account.

Setting up hosting platform

After purchasing the hosting service and domain name, you will need to go to the hosting from the main page.
Then go to the control panel (computer icon)
Next, you will need to go to all sites on the dashboard (1), select the appropriate site (2) and click the change parameters button (3).
Now, about what levers and buttons you will definitely need to press. To be more specific, this means choosing the required version of Python and toggle CGI scripts on.
I want to note that if your django site is written on versions higher than 4.2, then for you (just like for me) only one version of python will do, 3.10.1. Also, if you also bought an SSL certificate, include it too.
I just want to make one remark about the interface. The order of python interpreter versions goes from the earliest to the latest, it would seem. But for some reason, version 3.10 is almost in the middle. I didn’t notice it right away. But it’s exactly what we need.
We have completed the basic hosting setup. And unlike the beget hosting provider, we won’t need to manually download and install the required version of Python and OpenSSL.

Publishing the website

Deploying a website always starts with transferring its files. They can be transferred in two ways, either through the control panel or using the scp command, through the terminal. Here I will consider only the first method, because it is stupidly simpler.
First, go to the file manager, after which you will need to go to the directory under the name of the domain name you bought. In my case, this is search-result-parser.site. All such directories are located in the www directory.
Let's download the archive with the site files and unpack it there accordingly. I'll give you the finished version of the site. There will be already files with dependencies, scripts, and settings. Just download it.

Setting up static and media files

In order for the server to be able to access our files, they must all be in the root directory of the site, that is, in my case, /www/search-result-parser.site/. You will need to change the following lines in the settings.py file to:
STATIC_URL = '/static/'
STATIC_ROOT = 'static/'

MEDIA_URL = '/media/'
MEDIA_ROOT = 'media/'
That's it.

Setting up database

To get a minimally working site, you only need to set up a database. SQLite is certainly not suitable for these purposes. You need to switch to the database that is supported by the server itself. In the case of reg.ru, this is MySQL.
You will need to replace the following lines in settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'database_name',
'USER': 'user_name',
'PASSWORD': 'database_password',
'HOST': 'localhost',
}
}
But that's not all. Right now, we're interested in the following keys in the dictionary:
  1. NAME - Database name
  2. USER - Database user name
  3. PASSWORD - Database password
All other values ​​remain as I specified them. How do I find the values ​​for them?
Go to the databases on the dashboard, create a database. By default, you'll already have a new database created. You can use it, but I'll show you how to create your own.
Fill in the required fields. You can also create a separate user for the database or use an existing one.
Now the database is successfully configured for work too.

"Install" the website

Now let's install the site, so to speak. By installation, I mean copying all static files, creating migrations for the database and writing additional scripts for layers between our site and the server itself.
In the root directory of the site, create a virtual environment, activate it and install the necessary packages via pip:
cd /www/search-result-parser.site/
/opt/python/python-3.10.1/bin/python3.10 -m venv .venv
source .venv/bin/activate
pip install -r req.txt
I want to note that if you need to use python3.10, you will have to specify the full path to the interpreter, because it is not in the environment variable $PATH. Keep this in mind.
Now we will transfer all static files, create migrations for the database, and also compile translations.
python ./Website/manage.py collectstatic
python ./Website/manage.py migrate
python ./Website/manage.py compilemessages
All static files will be moved to /www/search-result-parser.site/ (All media files will be there too). All necessary tables will also be created, just like files with translations.
The last and final step in "installing" the site will be creating a passenger-wsgi.py script with the following content.
# -*- coding: utf-8 -*-
import os, sys
sys.path.insert(0, '/var/www/u3044930/data/www/search-result-parser.site/Website')
sys.path.insert(1, '/var/www/u3044930/data/www/search-result-parser.site/.venv/lib/python3.10/site-packages')
os.environ['DJANGO_SETTINGS_MODULE'] = 'Website.settings'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Where instead of sys.path.insert(0, ..., you will have to specify the path to the root folder of your django site.
Where instead of sys.path.insert(1, ..., you will have to specify your path to the packages in the virtual environment created earlier.

Server reload

Now restart the server by creating a file .restart-app in the root directory of the site, /www/search-result-parser.site/. The servers work in such a way that every minute they check the hostings for the presence of such a file and if it is there, they restart it.

Conclusion

In this way, you can now deploy a site written in django yourself. I will say right away, in comparison with the hosting provider from beget, installation on reg.ru is much simpler and more user-friendly. And now my site about parsing search results is available to all of you. \^o^/


Comments

(0)

captcha
Send
It's empty now. Be the first (o゚v゚)ノ

Other

Similar articles


How to deploy a Django project on Beget. Full instruction.

Clock
12.05.2024
An eye
504
Hearts
0
Connected dots
0
Connected dots
0
Connected dots
0
You will know how to link a domain name, host a Django project, transfer databases, and configure a virtual environment. And other tricks.

Series of articles about creating and promoting SearchResultParser | Tim the webmaster

Clock
16.07.2024
An eye
154
Hearts
0
Connected dots
0
Connected dots
0
Connected dots
0
This is an article that is going to introduce you to my new project/webtool, SearchResultParser. Also, from this article, you can navigate to any interesting article for you. See them …

Developing frontend part of a website with React on Django | SearchResultParser p. 2

Clock
16.08.2024
An eye
222
Hearts
0
Connected dots
0
Connected dots
0
Connected dots
0
I show and tell how to develop a frontend for a site on React with a backend on django. I use MaterialUI and TailwindCSS, with source code and comments.

How to add localization for django website (python, js, templates and models) p. 5

Clock
06.02.2025
An eye
267
Hearts
0
Connected dots
0
Connected dots
0
Connected dots
0
In this article, I will show how you can add localization and translations to a Django website(i18n). We will translate Python, JS code, as well as templates and Django-models. Plus, …

Traffic analysis of the website by January and February

Clock
03.03.2025
An eye
112
Hearts
0
Connected dots
0
Connected dots
0
Connected dots
0
About what my site achieved during SEO promotion in January-February. Analysis of traffic from Google via GSC and analysis of traffic from Yandex using Yandex.Webmaster. Also provided are full statistics …

Used termins


Related questions