Setting up WordPress and Flask on Apache2

Im learning flask and got the “hello world” tutorial to work as I was able to access it from the internet. I then installed wordpress and soon learned that both couldn’t be accessible from example.com with my current configuration. Right now, I’m only able to access wordpress. I tried changing flask to things like www.example.com/flask/ but was not able to access the test page.

My config files for flask and apache2 are as follows:

Read More

app:

from flask import Flask

app = Flask(__name__)

@app.route('/')
def homepage():
    return "Flask works?"


if __name__ == "__main__":
    app.run()

conf:

#Listen 80
ServerName www.example.com

<VirtualHost *:80>

    ServerAdmin webmaster@localhost
    #ServerName example.com

    WSGIDaemonProcess flask user=www-data group=www-data threads=5 python-path=/var/www/FlaskApp

    WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
    <Directory "/var/www/FlaskApp/">
        WSGIProcessGroup flaskapp
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

wsgi:

#! /usr/bin/python

import sys
import logging

logging.basicConfig(stream=sys.stderr)
sys.path.insert(0, "/var/www/FlaskApp/")

from FlaskApp import app as application
application.secret_key = "secretstuff"

Then I installed WordPress and realized that they were both on port 80. As a result, I couldn’t reach my Flask test page.

  1. Should Flask and WordPress be on different ports?
  2. How would I go about configuring apache2 to allow me to “access flask” via flask.example.com?
  3. I’ve read that I possibly need to adjust my host file. Is this true?

I realize that this may be an obvious fix to some of you out there. Nevertheless, I’m a novice and stuck. Any and all help is appreciated.

Thanks

Related posts

Leave a Reply

2 comments

  1. Aside from a couple of mistakes in the code I corrected ( wasn’t pointed correctly), the main issue was changing

    app.run()
    

    to

    app.run(host='0.0.0.0')
    

    No clue if this is a secure thing to do or not…

  2. Use Apache Name-based. In /etc/apache2/sites-available:

    flaskapp.conf:

    <VirtualHost *:80>
        ServerName  flaskapp.yoursite.com
    
        WSGIDaemonProcess flaskapp user=wilson group=wilson threads=5
        WSGIScriptAlias / /path/to/flaskapp.wsgi
    
        <Directory /path/to/flaskapp/>
            WSGIProcessGroup flaskapp
            WSGIApplicationGroup %{GLOBAL}
            Require all granted
        </Directory> 
    </VirtualHost>
    

    wordpress.conf:

    <VirtualHost *:80>
        ServerName  blog.yoursite.com
    
        DocumentRoot /path/to/wordpress
    
        <Directory /path/to/wordpress/>
            Options FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>
    </VirtualHost>
    

    Reload apache confs:

    a2ensite flaskapp.conf
    a2ensite wordpress.conf
    service apache2 reload