Skip to content
This repository was archived by the owner on Sep 25, 2024. It is now read-only.

Setting The App Up

Ben C edited this page Nov 11, 2021 · 16 revisions

THIS PAGE IS A WORK IN PROGRESS

Preface

This is a pretty long process and easy to mess up, so make sure you know how to use IIS and python beforehand

Dependencies

You'll need to install the following:

  • Git: To download the app
  • Python 3.9: To run the app
  • MySQL Server: To act as the database
  • IIS: To host the site
  • ActiveDirectory (can be on a different server): To authenticate with

Setting up the project folder

First and foremost, you need to download the code, navigate to the folder where you want the code to be downloaded and run the following:

git clone https://github.com/Bwc9876/CodeReview.git
cd CodeReview

This will download the app.
Next up, you'll want to create a python virtual environment to run the app in, you can do this by running the following:

python -m venv venv

This will create a new folder named "venv" in the app directory.
Now that we made the virtual environment, we need to activate it, this is done by running:

./venv/Scripts/activate.ps1

Now you should see (venv) in the current line, this indicated the environment was activated successfully.
Now we need to install dependencies, this is done by running:

pip install -r requirements.txt

In addition, run the following to install wfastcgi, which we use to host the app on IIS

pip install wfastcgi

Now we have our dependencies installed.

Setting up the environment

Now we'll need to setup environment variables, look at the environment variables section of the README for more info on what each one does.
Now, create a new file in the CodeReview folder named "env.ps1".
Fill it out in this format, replacing "KEY" with the environment variable's name and VALUE with it's value.

$Env:KEY=VALUE

Make a new line for each environment variable.
We have now set up our environment variables.

Database

Now you'll need to install MySQL server to the system, you'll need the "MySQL Server" and "MySQL Workbench" components.
After you've installed the server, create a user on it that has full permissions.
Put the username and password in the DATABASE_USERNAME and DATABASE_PASSWORD environment variables respectively.
Then, create a database and make sure to name it "codereview".
Make sure the user you configured also has full permissions on the database.

Database Migrations

Next up, we'll set up our newly created database, start off by opening a new powershell window and navigating to the CodeReview folder and executing the following.

./venv/Scripts/activate.ps1
./env.ps1

Now, run the following to set up the database.

python manage.py migrate

This will create the necessary tables for the app.

Static files

Before closing the powershell window from the database section, run the following to copy static files to the proper folder.

python manage.py collectstatic

Say yes to any warnings about overriding old files.
We've now set up our static files.

wfastcgi

Next up, you'll need to open an administrator powershell window in the CodeReview folder.

python ./venv/Scripts/wfastcgi-enable.py

This will output a string that looks like this:

C:/path/to/CodeReview/venv/bin/python.exe|C:/path/to/CodeReview/venv/lib/site-packages/wfastcgi.py

Note that if you need quotes (either of the paths have spaces), you'll need to replace them with the xml quote escape: ".
Save this string as you'll need it in the next step.

web.config

Next you'll need to create a file named "web.config" in the CodeReview folder, and fill it out with the following

  <configuration>
  <system.webServer>
    <handlers>
      <add name="Python FastCGI"
           path="*"
           verb="*"
           modules="FastCgiModule"
           scriptProcessor="paste the string from the wfastcgi step here"
           resourceType="Unspecified"
           requireAccess="Script" />
    </handlers>
  </system.webServer>

  <appSettings>
    <!-- Required settings -->
    <add key="WSGI_HANDLER" value="CodeReview.wsgi.application" />
    <add key="PYTHONPATH" value="C:\path\to\CodeReview" />
    <add key="DJANGO_SETTINGS_MODULE" value="CodeReview.settings" />

    <!-- Optional settings -->
    <add key="WSGI_LOG" value="C:\Logs\code_review.txt" />
    <add key="WSGI_RESTART_FILE_REGEX" value=".*((\.py)|(\.config))$" />
    <add key="APPINSIGHTS_INSTRUMENTATIONKEY" value="__instrumentation_key__" />    
    <add key="WSGI_PTVSD_SECRET" value="__secret_code__" />
    <add key="WSGI_PTVSD_ADDRESS" value="ipaddress:port" />
  </appSettings>
</configuration>

IIS

Now we'll finally add the IIS website, navigate to IIS and click "New Site", when asked for the physical path, enter the path to the CodeReview folder.

IIS Static files

Next we need to setup static files on the site, right click the site and click "Add virtual directory", set the path of it to your STATIC_DIR environment variable. This will enable IIS to host static files.

Complete

Setup has now been completed, you can start the site from IIS and access it with the port you configured.

Clone this wiki locally