DEV Community

Joseph Mancuso for Masonite

Posted on

Deploying Masonite to PythonAnywhere


PythonAnywhere is a way to develop and host your website or any other code directly from your browser without having to install software or manage your own server. It's a very good option if you want to deploy a WSGI application and it has support for Django and Flask right from the start.

In this article I'll walk through how to get your application setup on an instance of PythonAnywhere.

Create an account

This one is simple :). Head over to PythonAnywhere and create a free or paid account. Whichever you want.

The Dashboard

Once you login you'll be presented with a dashboard. In the bottom left corner of it you will see a section that looks like this:

Go ahead and click the $bash link. You'll be presented with a new bash terminal. From here you should pip install the masonite-cli so we can start using craft commands.

$ pip3 install masonite-cli --user
Enter fullscreen mode Exit fullscreen mode

Make sure you use the --user flag because you won't have sudo privileges inside this bash shell.

Setting Up The Directory

Let's go ahead and create some directories we'll be using for this project. We might want our PythonAnywhere instance be able to serve multiple applications so let's make a "sites" directory.

~ $ mkdir /var/www/sites
~ $ cd /var/www/sites
/var/www/sites $ <we should now be here>
Enter fullscreen mode Exit fullscreen mode

We make a sites directory because this might contain a structure where we can put multiple websites like:

Enter fullscreen mode Exit fullscreen mode

Installing Masonite

If you just want to install a fresh application then you can go ahead and follow the normal documentation for installing a new application. But for this tutorial we will talk about how to install an application directly from github.

For the convenience, we'll actually be installing a new application for Masonite but via the github repository and not the craft new command.

So head over to your github account and copy the github link. In this case we will be using:
Enter fullscreen mode Exit fullscreen mode

Make sure you are in the sites directory and git clone your repo:

/var/www/sites $ git clone
Cloning into 'masonite'...
remote: Counting objects: 1898, done.
remote: Compressing objects: 100% (57/57), done.
Enter fullscreen mode Exit fullscreen mode

Great! So now our repository is cloned. Doing a quick ls command should return a new file with our new repo:

/var/www/sites $ ls
Enter fullscreen mode Exit fullscreen mode

Virtual Environment

PythonAnywhere promotes the idea of putting your dependencies in a virtual environment (which is good practice). So let's get our virtual environment setup which is really easy.

/var/www/sites $ cd masonite
/var/www/sites/masonite $ virtualenv -p python3 venv
Enter fullscreen mode Exit fullscreen mode

Notice we did a cd into our freshly created masonite project and created a virtual environment. This command is using python3 (the virtualenv defaults to Python 2.7 and Masonite requires 3.4+). The venv at the end is the name of our virtual environment. Name that whatever you want.

Installing dependencies

Great. So now let's install our dependencies. First we will need to activate our virtual environment and then run the craft install command like we normally do.

/var/www/sites/masonite $ source venv/bin/activate
(venv) /var/www/sites/masonite $ craft install
Collecting waitress==1.1.0 (from -r requirements.txt (line 1))
  Using cached
Collecting masonite<=2.0.99,>=2.0 (from -r requirements.txt (line 2))
Collecting python-dotenv==0.8.2 (from masonite<=2.0.99,>=2.0->-r requirements.txt (line 2))
  Using cached
Key added to your .env file: 1KmdwFryf71PGKYm6NBoFXRHHlqqE0=
Enter fullscreen mode Exit fullscreen mode

Let those dependencies install. If installed successfully you will get a green message saying a key was appended to your .env file. Great. Now let's get out of this bash shell and on to adding our application to the PythonAnywhere dashboard.

Adding Our Web App

Go back to the dashboard and in the upper right hand side we will see a tab called "Web" like this:

Click on that and click on "Add New Web App":

You'll want to click on "Manual Configuration" at the bottom of the list.

and then click on "Python 3.6":

Once that is done click "Next" and you should be presented with a new dashboard specific to your app.

Configuring Your Web App

Code Section

If you scroll down on this new web app dashboard you'll see a "Code" section:

Remember that we put our app in a /var/www/sites/<your_project> directory so let's add that to both the source code and working directory like this image above.

Now we need to edit the file. I'm not entirely sure why they don't just default to the one in the source code but oh well. Click on that "Wsgi configuration file" link which will open up an editor.

We'll have to copy and paste our file into this code. Since we're using git we can grab it right from our GitHub repo. If you made no modifications to your file you can use the default one here:

The final product should look something like this:

Make sure you click save in the upper right hand corner

Virtualenv Section

Scroll down a bit on the web app dashboard and you should see a new section for virtual environments. We just need to tell PythonAnywhere where we created our virtual environment. Remember we just made a venv directory in our project directory. So let's just append on a venv to the directory we've been adding:


That's it! Now let's just go up to the top of the page and reload the application:

Once that's done we can view it using the link right above it that looks something like "". This will open up our web app!

Top comments (5)

alchermd profile image
John Alcher

Oh nice, it gives a Laravel-y feel after a short glance over the API. Have you contacted the PyAnywhere team for a possible "one-click install" solution for your framework? I'm sure they'd be happy to help!

josephmancuso profile image
Joseph Mancuso

Nope but I was deff thinking it when deploying the project lol. I'll try that out today!

alchermd profile image
John Alcher

They're really a helpful bunch, give us an update if ever it comes to fruition. Good luck on your framework!

Thread Thread
josephmancuso profile image
Joseph Mancuso

they said they need to revisit some old legacy angular code to remember how it works before adding Masonite to the list :)

jigarmistry24 profile image
Jigar Mistry

This is working as expected. Nice !