Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Mayur Pande
PLUS
Mayur Pande
Courses Plus Student 11,711 Points

How to deploy a flask app to a live ubuntu server

I am going crazy trying to figure out how to deploy a flask app to a web sever. I have followed all the instructions and it is still not working.

I do not have a domain so I am only accessing it through the ip address.

So far my wsgi file looks like this;

#!/usr/bin/python3
import sys
activate_this = '/var/www/WebScraper/WebScraper/venv/bin/activate_this.py'
with open(activate_this) as file_:
        exec(file_.read(), dict(__file__=activate_this))
sys.path.insert(0,'/var/www/WebScraper/')


from WebScraper import app as application

and my enabled site apache file looks like this;

<VirtualHost *:80>
                ServerName xx.xxx.xxx.xxx

                WSGIDaemonProcess /var/www/WebScraper/WebScraper user='user' group='group' threads=5
                WSGIScriptAlias / /var/www/WebScraper/webscraper.wsgi
                <Directory /var/www/WebScraper/WebScraper/>
                        WSGIProcessGroup WebScraper
                        WSGIApplicationGroup %{GLOBAL}
                        Order deny,allow
                        Allow from all
                </Directory>



</VirtualHost>

my directory structure looks like this;

|--------WebScraper
|----------------WebScraper
|-----------------------static
|-----------------------templates
|-----------------------venv
|-----------------------__init__.py
|----------------webscraper.wsgi

Sorry for the hassle but can you see anything obviously wrong? Kenneth Love

1 Answer

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Mayur;

Are you getting any errors or warnings anywhere, log files, command line, etc.?

Is the Ubuntu server (version ??) self standing or is it through a cloud service like AWS?

Have you tried restarting the Apache (version ??) service? Are there any messages that come from that process?

Have you tried swapping the Order parameters to allow, deny? Take a look here under Order Directive for settings.

Post back with further information or if you are still stuck.

Mayur Pande
Mayur Pande
Courses Plus Student 11,711 Points

Hi Ken Alger

So the errors I am getting are;

[Thu Mar 30 09:28:25.164574 2017] [wsgi:warn] [pid 10914] mod_wsgi: Compiled for Python/3.5.1+.
[Thu Mar 30 09:28:25.164639 2017] [wsgi:warn] [pid 10914] mod_wsgi: Runtime using Python/3.5.2.
[Thu Mar 30 09:28:25.165554 2017] [mpm_prefork:notice] [pid 10914] AH00163: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[Thu Mar 30 09:28:25.165564 2017] [core:notice] [pid 10914] AH00094: Command line: '/usr/sbin/apache2'
[Thu Mar 30 09:33:06.146081 2017] [mpm_prefork:notice] [pid 10914] AH00171: Graceful restart requested, doing restart
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.0.0.4. Set the 'ServerName' directive globally to suppress this message
[Thu Mar 30 09:33:06.551229 2017] [wsgi:warn] [pid 10914] mod_wsgi: Compiled for Python/3.5.1+.
[Thu Mar 30 09:33:06.551234 2017] [wsgi:warn] [pid 10914] mod_wsgi: Runtime using Python/3.5.2.
[Thu Mar 30 09:33:06.551416 2017] [mpm_prefork:notice] [pid 10914] AH00163: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[Thu Mar 30 09:33:06.551423 2017] [core:notice] [pid 10914] AH00094: Command line: '/usr/sbin/apache2

The ubuntu server is 16.04. My friend bought it from some place in China I think. All he gave me was the ssh@xx.xxx.xxx.xx and the password.

I have tried checking the status of the apache2, and it is running, green light.

Also as you suggested I swapped the orders parameters, but still getting those errors.

It seemed so simple when I set it up locally on my local host, but when actually trying to upload it to a live server there are some many differences/difficulties!