top of page

By Alaina Ahuja       April 27th 2020

This article explains step by step how to deploy a Python Flask application on an Apache webserver on Mac. The diagram below explains how the Apache server will work with our code:

Diagram2.png

Step #1: Installing Flask

 Type this command in your terminal to install flask:

Installing flask on mac

Step #2:

Installing mod_wsgi

Type this command in your terminal to install mod_wsgi :

mod_wsgi installing command.png

Step #3:

Creating a flask application

Create a .py file for your flask application. Let's name it "Hello_Flsk.py". We also need to make a folder for this file(I named mine "Alaina_Code"). Now enter the following code into your .py file:

Flask app code

Step #4:

Creating a WSGI file

Make Sure Your .py and .wsgi files are both in the same folder

In order for the Apache server to understand the code in Hello_Flsk.py, we need to make a .wsgi file. Let's name this file Flsk_Config.wsgi. Put this file in the folder we made in the last step and enter in the following code:

WSGI code to configure flask on Apache mac

Here, instead of '/Alaina_Code/FlaskFirstAPI' you would enter the folder path where you are keeping your .py and .wsgi files.

Step #5:

Editing and working with httpd.conf

We finally need Apache to recognize the WSGI file We wrote. Apache's config file(httpd.conf) should be available at this at this path:'/etc/apache2'  open it and enter in the following:

Make sure to double-check if this .so file is on your computer. If it isn't, mod_wsgi wasn't installed correctly.

code to put in Apache on mac
Part_2.png
Part_2.png
code to put in Apache on mac

Now, you should be able to run your program. To test it, type into your browser:

​

http://localhost/flasktest/Hello

​

You should get a message like this:

If you're having trouble getting to httpd.conf, you can right-click on finder, and choose the option "go to folder". There, if you enter the path, you can find any hidden folders that may not be visible otherwise. For a more detailed description, see this article:

https://alainaahuja5.wixsite.com/gotofolderonmac

​

Python flask app deployed on Apache mac

If you have any questions or comments, feel free to type them in right here!

bottom of page