it-guide

Deploy to PythonAnywhere Without Web UI (SSH + Git + WSGI Reload)

jacky

Deploy to PythonAnywhere Without Web UI (SSH + Git + WSGI Reload)

When using PythonAnywhere, it can be tedious to open the web UI every time, apply your source code changes, and click the Reload button. In fact, you can deploy code and reload your web app without opening the web page at all, using only SSH and rsync.

In this post, I will cover the following process:

  • Log in to your PythonAnywhere server with SSH using your password
  • Apply updated source code with Git
  • Reload WSGI to reflect changes immediately

1. Connect to the server with SSH

PythonAnywhere provides SSH access by default. You can connect from your terminal with the following command:

ssh USERNAME@ssh.pythonanywhere.com

After entering your password, you will be connected to the server.

Your default home directory will usually look like this:

/home/USERNAME

2. Check your project location

For example, let’s assume your project structure looks like this:

/home/USERNAME/myproject
└── mysite
    └── wsgi.py

Move to your project directory:

cd myproject

3. Apply your code changes

If you have already moved into the project folder and your Git setup is ready, you will usually see the current branch name in parentheses in your shell prompt.

Use git pull to bring the latest code from the remote repository. Before doing that, make sure you have already pushed your local changes to the remote repository from your local machine. I will skip the basic Git explanation here.

If you want to explicitly specify the remote name and branch, you can use something like git pull origin master or git pull origin main.

~/myproject (master)$ git pull

4. Check the WSGI file

PythonAnywhere reloads your web app based on a specific WSGI file.

To check the available files:

ls /var/www/

You will usually see something like the following. If you have connected a custom domain, there may be a WSGI file for that domain as well. In my case, I reload the WSGI file connected to my domain. Replace the filename below with the one that matches your setup.

USERNAME_pythonanywhere_com_wsgi.py
kitle_xyz_wsgi.py

5. Reload the web app (the key step)

This command does the same thing as the Reload button in the web UI.

touch /var/www/USERNAME_pythonanywhere_com_wsgi.py

Or:

touch /var/www/kitle_xyz_wsgi.py

This updates the file’s modified time and triggers PythonAnywhere to reload your web app.

6. Verify the reload

You can check whether the file’s modified time has changed:

ls -l /var/www/USERNAME_pythonanywhere_com_wsgi.py

Example:

-rw-rw-r-- 1 USERNAME registered_users ... Mar 10 13:16 USERNAME_pythonanywhere_com_wsgi.py

If the timestamp has changed to the current time, the reload has been triggered.

Another simple way to verify it is to make a small visible change in your code, then refresh the website in your browser and check whether the change has been applied.

Summary

You can deploy to PythonAnywhere without opening the web page by following these steps:

  1. Connect through SSH and update your source code
  2. Reload the app by touching the WSGI file

This allows you to deploy entirely from the terminal without using the web UI.

Save even a little time, deploy faster, and keep things simple.