Skip to content

Deploying to PythonAnywhere

Zack Hable edited this page Mar 18, 2021 · 3 revisions

To deploy the site for the first time to PythonAnywhere (ie: you're setting up a dev account and want to test something remotely for some reason or replicate the "production" account).

  1. Sign up with PythonAnywhere (you should be able to use a free account)
  2. Setup a new webapp (opt for a basic Django template/site and Python 3.8+)
  3. SSH into the system (ie: ssh [email protected] for paid accounts) or use the provided console via the website (for free accounts)
  4. Remove any of the template site (ex: rm ~/mysite)
  5. Clone this repo (git clone https://github.com/CAASI-G2A/g2a-website.git)
  6. Add your web app url (Ex: user.pythonanywhere.com) and WSGI path to PPUC/def/settings.py (you can find the WSGI path from the pythonanywhere site under "Code" > "WSGI configuration file:")
  7. Setup a virtual environment for python in the user's home directory (ie: python3.8 -m venv ~/venv)
  8. Activate the virtual environment (source ~/venv/bin/activate)
  9. Install all python packages (pip3 install -r g2a-website/PPUC/requirements.txt)
  10. Set the virtual environment path in the PythonAnywhere webapp page under "Virtualenv" (ie: /home/USER/venv)
    1. You should also set the source code path too (ie: /home/USER/g2a-website)
    2. Also set the static asset paths under "Static files:":
      1. /static/ -> /home/USER/g2a-website/PPUC/PxPUC/static
      2. /static/ -> /home/USER/g2a-website/PPUC/frontend/dist
  11. Run the application setup script from the Django project directory (ie: in g2a-website/PPUC run python3 manage.py runscript -v3 setup_app)
  12. Update the default WSGI file to use the correct Django settings and NPM version (you got this path earlier from the PythonAnywhere website)
    1. Set project home to project_home = '/home/USER/g2a-website/PPUC'
    2. Change Django settings environment variable to os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'def.settings')
  13. Reload the WSGI file from the PythonAnywhere web panel
  14. Check the website now
Clone this wiki locally