Home PostgreSQL Raising the Django stack on MS Windows

Raising the Django stack on MS Windows

by admin

Raising the Django stack on MS Windows
This article will provide detailed instructions on installing and configuring Apache, Python, and PostgreSQLprograms to make Django project work on MS Windows.Django already includes a simplified development server for local code testing, but for production-related tasks a more secure and powerful web server is required. We will set up mod_wsgi to communicate with our project and configure Apacheas a gateway to the outside world.
It is worth noting that the installation and setup will be done in MS Windows 10 with 32-bit. Also 32 bit response will be universal and will work on 64 bit architecture. If you need 64 bit installation repeat the same steps for 64 bit program distributions, the sequence of actions will be identical.
We will use Severcart as our Django project. It is designed to manage the movement of cartridges, accounting for printing equipment and supply and service contracts. Installation of all programs and modules will be made in the directory C:severcart. The location is not important.

Python

The first step is to download and install Python from the Python website. We choose Windows as the operating system and the 32-bit version. As of this writing, the current version is 3.9.0rc2.
After downloading the installation file, right-click on the installation file and select "Run as administrator". You should see the screen below
Raising the Django stack on MS Windows
Check the "Install launcher for add user (recomended)" and "Add Python 3.9 to PATH" boxes and click "Customize installation".
Raising the Django stack on MS Windows
Check "pip", "py launcher", "for all users (requires elevation)" and click "Next".
Raising the Django stack on MS Windows
Select all input fields as in the picture above and click on "Install".
Raising the Django stack on MS Windows
To verify that the installation was successful, open cmd and type python. If the installation was successful, you should see a prompt like the one below
Raising the Django stack on MS Windows

Install mod_wsgi

Download the compiled package with mod_wsgi from the website
www.lfd.uci.edu/~gohlke/pythonlibs The module acts as an intermediary between the Apache server and the Django project. The latest package will be named mod_wsgi-4.7.1-cp39-cp39-win32.whl. Note that the package is compiled for 32 bit Windows CPython version 3.9. Also note that the obvious installation of the pip install mod_wsgi module will most likely fail because the Visual Studio C++ compiler is required during the installation process. Installing a whole compiler for one Python package on Windows is not a good idea.
Install the module using the standard pip package manager in cmd or powershell:

pip install -U mod_wsgi-4.7.1-cp39-cp39-win32.whl

Raising the Django stack on MS Windows

Apache

Download the distribution kit from the website https://www.apachelounge.com/download/
The most recent version of the Web server is Apache 2.4.46 win32 VS16. You will also need the pre-installed "Visual C++ Redistributable for Visual Studio 2019 x86" package to run the program.
Unpack the Apache distribution package into the directory C:severcartApache24, then change line number 37 in your

Define SRVROOT "C:/severcart/Apache24"

Verify that Apache is working by running

C:/severcart/Apache24/bin> httpd.exe

As a result should see in a browser at the address 127.0.0.1 "It works!" line.
Raising the Django stack on MS Windows
Install the Apache service by running the command line as Administrator with the instruction :

C:severcartApache24bin> httpd.exe -k install -n "Apache24"

Next, connect the mod_wsgi module to Apache. To do this at the command line let’s execute the instruction

C:{Windowssystem32> mod_wsgi-express module-config

As a result, the standard output will print the lines :

LoadFile "c:/severcart/python/python39.dll"LoadModule wsgi_module "c:/severcart/python/lib/site-packages/mod_wsgi/server/mod_wsgi.cp39-win32.pyd"WSGIPythonHome "c:/severcart/python"

Create file C:{severcartApache24confextrahttpd-wsgi.conf and copy there the lines printed above.
Connect the new configuration to the main httpd.conf file
Include conf/extra/httpd-wsgi.conf
Save changes, restart Apache services

Net stop Apache24Net start Apache24

PostgreSQL

Install PostgreSQL taken from the site https://postgrespro.ru/windows The current version of the software product is 12. The advantages of the Russian distribution from the canonical one are presented on the same site.
Raising the Django stack on MS Windows
Raising the Django stack on MS Windows
Raising the Django stack on MS Windows
Raising the Django stack on MS Windows
Raising the Django stack on MS Windows
Raising the Django stack on MS Windows
Raising the Django stack on MS Windows
Raising the Django stack on MS Windows
Raising the Django stack on MS Windows
Raising the Django stack on MS Windows
The installation steps are presented above and need no comment. Installation is extremely easy.
Create a database in postgres to store Django project data structures

C:severcartpostgresqlbin> psql -h 127.0.0.1 -U postgres -WCREATE DATABASE severcart WITH ENCODING='UTF8' OWNER=postgres CONNECTION LIMIT=-1 template=template0;

Raising the Django stack on MS Windows
The database is created. Now we deploy Django project.

Installing the web application

To do this, download the zip archive from the website https://www.severcart.ru/downloads/ and unzip it into C:severcartapp directory
Raising the Django stack on MS Windows
Change the main configuration file C:{severcartappconfsettings_prod.py to specify database connection details
Raising the Django stack on MS Windows
The Python dictionary DATABASES contains database connection details. Read more about how to set this up here https://docs.djangoproject.com/en/3.1/ref/databases/#connecting-to-the-database
Install Python significance packages to run applications inside Django project

C:severcartapptkinstaller> python install.py

Raising the Django stack on MS Windows
During the script will initialize the database tables, constants, indexes, etc., and will be prompted to create a user on whose behalf the work in the program will be done.
Connect Django application to the Apache server by adding the configuration file
httpd-wsgi.conf with the following text

Alias /static "c:/severcart/app/static"Alias /media "c:/severcart/app/media"<Directory "c:/severcart/app/static"># for Apache 2.4Options Indexes FollowSymLinksAllowOverride NoneRequire all granted</Directory><Directory "c:/severcart/app/media"># for Apache 2.4Options Indexes FollowSymLinksAllowOverride NoneRequire all granted</Directory>WSGIScriptAlias / "c:/severcart/app/conf/wsgi_prod.py"WSGIPythonPath "c:/severcart/python/"<Directory "c:/severcart/app/conf/"><Files wsgi_prod.py>Require all granted</Files></Directory>

Reboot the Apache service and test the application
Raising the Django stack on MS Windows
That’s all for now. Thank you for finishing this.
In the following article we will create a self-extracting installation archive in InnoSetup to quickly deploy a Django project to the customer’s computer. For those who want to repeat all the steps on Yandex.Disk All distributions used are downloaded.

You may also like