Repository navigation
Setting The App Up
This is a pretty long process and easy to mess up, so make sure you know how to use IIS and python beforehand
Throughout this tutorial we'll use the command python, however on some machines this command can point to the wrong version of python and you may need to use python3 in place of it.
To determine if you need to use python3, run the following:
$ python --versionIf this outputs a number that starts with 2 (ex: 2.7), you'll need to use the python3 command instead.
You'll need to install the following:
- Git: To download the app
- Python 3.10: To run the app
- Pipenv: To manage packages
- MySQL Server: To act as the database
- IIS: To host the site
- ActiveDirectory (can be on a different machine): To authenticate with
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 CodeReviewThis will download the app.
Install pipenv if you haven't:
$ python -m pip install pipenvNext up, you'll want to create a pipenv environment:
$ pipenv installNow that we made the virtual environment, we need to activate it, this is done by running:
$ pipenv shellNow you should see "(venv)" in the current line, this indicates the environment was activated successfully.
Now we have our dependencies installed.
Now we'll need to setup environment variables, look at the environment variables page for more info on what each one does.
Now, create a new file in the CodeReview folder named ".env".
Fill it out in this format, replacing KEY with the environment variable's name and VALUE with it's value.
KEY=VALUE
Make a new line for each environment variable.
We have now set up our environment variables.
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.
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.
$ pipenv shellNow, run the following to set up the database.
$ python manage.py migrateThis will create the necessary tables for the app.
Before closing the powershell window from the database section, run the following to copy static files to the proper folder.
$ python manage.py collectstaticSay yes to any warnings about overriding old files.
We've now set up our static files.
Next up, you'll need to open an administrator powershell window in the CodeReview folder.
$ pipenv run wfastcgi-enableThis 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.
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>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.
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.
Now that everything is configured, it's recommended you run tests ensure everything is working correctly.
Start off by opening a new powershell window in the CodeReview folder and running the following:
$ pipenv shellThen (making sure that IIS is stopped beforehand), run:
$ python run_tests.pyIf the tests pass, you should see something like the following:
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
..............................................................................................................
----------------------------------------------------------------------
Ran 110 tests in 10.167s
OK
Destroying test database for alias 'default'...
If the tests do not pass, check your configuration to ensure it's correct. If you have issues, create a new issue with the help label
Setup has now been completed, you can start the site from IIS and access it with the port you configured.
Made By Ben C
Report An Issue