Basic Flask Web Tutorial

by: norrisemoe, 8 years ago


I have been testing running a flask webserver on my local machine which is on a private IP address. When I run the webserver whilst my virtual environment is active I see a page cannot be reached. I have followed the tutorial line by line twice with two fresh VMs. I am getting the Apache landing page on port 80 but nothing on port 5000.

As I am not running a server with public DNS my FlaskApp.conf appears as follows:

<VirtualHost *:80>
                ServerName localhost
                ServerAdmin youemail@email.com
                WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
                <Directory /var/www/FlaskApp/FlaskApp/>
                        Order allow,deny
                        Allow from all
                </Directory>
                Alias /static /var/www/FlaskApp/FlaskApp/static
                <Directory /var/www/FlaskApp/FlaskApp/static/>
                        Order allow,deny
                        Allow from all
                </Directory>
                ErrorLog ${APACHE_LOG_DIR}/error.log
                LogLevel warn
                CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>


Nmap scans show nothing running on port 5000 but I am not certain if that is due to the virtual environment.

I am not certain if the issue is that I haven't touched my index or created any files in /var/www/FlaskApp/FlaskApp/static/ which appears to be where apache is pointing in FlaskApp.conf.

I would really appreciate some help with digging into this a bit further.



You must be logged in to post. Please login or register an account.



Port 5000 is purely for the flask dev server, and it can ONLY be reached locally. Thus, with your VM, the only way to reach your website via the flask local server, you'd need to be plugged directly into that network.

-Harrison 8 years ago

You must be logged in to post. Please login or register an account.


Hi Harrison,

Thanks so much for the response. I am local to the network (behind the same router) but I cannot reach the server on port 5000 from a different machine. I am wondering if the issue could be that my ServerName is not that of a domain... I am really lost as to why it just doesn't open.

-norrisemoe 8 years ago

You must be logged in to post. Please login or register an account.


Dont know what your setup is, but Id recommend using ubuntu inside a virtual machine.  That way regardless of your host OS, your simulating a real server and makes the transition from local to production environment pretty seamless.  Check out virtualbox for free or download a VM software from the net.  Install ubuntu 16  - 64 bit in it.  Then youre going to want to configure the VM network settings to use a bridged default adapter.  This gives the VM an IP similar to your hosts ip.  Then you may need to config ubuntu to allow vm connections to be able to ssh into the VM.  (details on the config I use is here, and should be similar if using virtualbox https://www.youtube.com/watch?v=d3-MUaJF7m0 )

Next I use virtual environments for every project, using python 3.5.  
I put projects in /var/www/ and each has its own venv to keep things separate.  ie:  /var/www/site1/FlaskApp/FlaskApp/ venv  init.py static templates etc.  To create a venv, you run 'pyvenv venv'.  You have to remember to source venv/bin/activate each time.  Once activated, run pip3 install flask, and whatever packages you need.
If you want multiple projects you have to configure apache for it.  

Read the conversation here which near the bottom details how to do it.  https://groups.google.com/forum/#!topic/modwsgi/SV5uyiu6T2Y
Each project and venv is connected with a virtual host file, and served on its own domain I made up.  I configured Ubuntu resolv.conf.head file with OpenDNS servers in order to resolve my local domains, and set ubuntu server to have a static ip so it doesnt change on you (pretty easy to config).  That way you can have unlimited projects each separate from the rest, acting as its own website.  

Lastly you just edit your host OS 'hosts' file, to point to your project domain:  ie:     192.168.10.20                      site1.me

You can have 50 local websites sharing that same IP, as long as they each have a different domain and you have them configured correctly.

Again, see the mod wsgi conversation (near bottom) to see how its configured.  This way I can run as many flask and django projects as I want simultaneously, with no conflicts. Youll thank me later.

-kingfitz 8 years ago
Last edited 8 years ago

You must be logged in to post. Please login or register an account.