Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Masonite  profile imageJoseph Mancuso
Joseph Mancuso forMasonite

Posted on

     

Deploying Masonite to PythonAnywhere

Introduction

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 toPythonAnywhere 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 modeExit 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 modeExit fullscreen mode

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

/sites  masonite/  tutorial/  blog/
Enter fullscreen modeExit fullscreen mode

Installing Masonite

If you just want to install a fresh application then you can go ahead and follow the normaldocumentation 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 thecraft new command.

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

https://github.com/MasoniteFramework/masonite
Enter fullscreen modeExit fullscreen mode

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

/var/www/sites$git clone https://github.com/MasoniteFramework/masoniteCloning into'masonite'...remote: Counting objects: 1898,done.remote: Compressing objects: 100%(57/57),done.......
Enter fullscreen modeExit fullscreen mode

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

/var/www/sites$lsmasonite
Enter fullscreen modeExit 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$cdmasonite/var/www/sites/masonite$virtualenv-p python3 venv
Enter fullscreen modeExit fullscreen mode

Notice we did acd into our freshly created masonite project and created a virtual environment. This command is usingpython3 (thevirtualenv defaults to Python 2.7 and Masonite requires 3.4+). Thevenv 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 thecraft install command like we normally do.

/var/www/sites/masonite$sourcevenv/bin/activate(venv) /var/www/sites/masonite$craftinstallCollectingwaitress==1.1.0(from-r requirements.txt(line 1))  Using cached https://files.pythonhosted.org/packages/ee/af/ac32a716d64e56561ee9c23ce45ee2865d7ac4e0678b737d2f5ee49b5fd6/waitress-1.1.0-py2.py3-none-any.whlCollecting 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 https://files.pythonhosted.org/packages/85/9f/b76a51bb851fa25f7a162a16297f4473c67ec42dd55e4f7fc5b43913a606/python_dotenv-0.8.2-py2.py3-none-any.whl......Key added to your .env file:1KmdwFryf71PGKYm6NBoFXRHHlqqE0=
Enter fullscreen modeExit 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 thewsgi.py 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 ourwsgi.py file into this code. Since we're using git we can grab it right from our GitHub repo. If you made no modifications to yourwsgi.py file you can use the default one here:https://github.com/MasoniteFramework/masonite/blob/master/wsgi.py

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 avenv directory in our project directory. So let's just append on avenv to the directory we've been adding:

Success!

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 ".pythonanywhere.com". This will open up our web app!

Top comments(5)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
alchermd profile image
John Alcher
Writing software for fun and profit.
  • Location
    Philippines
  • Work
    Software Engineer @ Iress
  • Joined

Oh nice, it gives aLaravel-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!

CollapseExpand
 
josephmancuso profile image
Joseph Mancuso
Creator of the Masonite FrameworkNY Software Developer.
  • Location
    New York
  • Work
    Software Developer at Rothco
  • Joined

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

CollapseExpand
 
alchermd profile image
John Alcher
Writing software for fun and profit.
  • Location
    Philippines
  • Work
    Software Engineer @ Iress
  • Joined

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
Creator of the Masonite FrameworkNY Software Developer.
  • Location
    New York
  • Work
    Software Developer at Rothco
  • Joined

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

CollapseExpand
 
jigarmistry24 profile image
Jigar Mistry
  • Joined

This is working as expected. Nice !

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

The Modern and Developer Centric Python Web Framework

More fromMasonite

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp