Brian, check out /var/log/apache2/error.log to see the errors and let us 
know what is in there. 

I'm having the exact same challenge as you (trying to configure flask + 
apache + anaconda + mod_wsgi on an ubuntu EC2 instance). 

On Monday, May 8, 2017 at 1:59:16 PM UTC-3, Brian wrote:
>
> Thank you Graham. 
>
> Any recs on testing and/or debugging a 500 internal server error when I 
> try to hit the site? I'm assuming that it's in the configuration so I'm 
> going to add full details of the process and config files below. 
>
> All commands ran:
>
> ## build conda environment
>
> conda create --name test1.0 python==3.6.1 pandas jupyter requests flask
>
>
> ## activate conda environment 
>
> source activate test1.0
>
>  
>
> ## get apache2
>
> sudo apt-get install apache2
>
> sudo apt-get install apache2-dev
>
>
> ## get mod_wsgi
>
> #sudo apt-get install libapache2-mod-wsgi
>
> pip install mod_wsgi
>
>
> ## force load Anaconda's shared library
>
> mod_wsgi-express module-config
>
>
> ## enable mod_wsgi
>
> sudo a2enmod wsgi 
>
>
> ## get git 
>
> sudo apt-get install git
>
>
> ## create config for apache to know about wsgi and flask app
>
> touch /etc/apache2/sites-available/FlaskApp.conf
>
>
> ## disable default config
>
> sudo a2dissite 000-default
>
>
> ## provide new config
>
> sudo a2ensite FlaskApp.conf
>
>
> ## start/restart apache
>
> sudo service apache2 restart
>
> Contents of FlaskApp.conf:
>
> <VirtualHost *:80>
>
>                 ServerName <IPv4 PUBLIC IP>
>
>                 ServerAdmin ubuntu@<IPv4 PUBLIC IP>.
> us-west-2.compute.amazonaws.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>
>
> Location of flask app and .wsgi file*.*
>
> (test1.0) ubuntu:/var/www$ tree
>
> *.*
>
> ├── *FlaskApp*
>
>    ├── *FlaskApp*
>
>    │   ├── __init__.py
>
>    │   ├── *static*
>
>    │   └── *templates*
>
>    └── flaskapp.wsgi
>
> Contents of flaskapp.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 = '<secret>'
>
> Contents of __init__.py:
>
> from flask import Flask
>
> app = Flask(__name__)
>
> @app.route("/")
>
> def hello():
>
>     return "Hello World (flask via conda env)!"
>
> if __name__ == "__main__":
>
>     app.run()
>
> When visiting the site, I get a 500 internal server error. I likely messed 
> up something with the config. Any help is greatly appreciated.
>
> Best,
> -Brian
>
> On Sunday, May 7, 2017 at 6:32:18 PM UTC-6, Graham Dumpleton wrote:
>>
>> In the first instance you should ensure things work with a WSGI hello 
>> world, no Flask framework. This ensures setup with Anaconda Python is okay, 
>> which sometimes doesn't always work because of stupid things Anaconda 
>> Python does which breaks the ability to use it in embedded systems.
>>
>> As to deploying Flask, the Flask documentation has details:
>>
>> * http://flask.pocoo.org/docs/0.12/deploying/mod_wsgi/
>>
>> Also ensure you read:
>>
>> * 
>> http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html
>>
>> so you are setting up any Python virtual environment correctly as guides 
>> for frameworks often don't suggest the preferred method, or simply don't 
>> address it.
>>
>> Graham
>>
>> On 7 May 2017, at 8:00 AM, Brian Lehman <[email protected]> wrote:
>>
>> Thanks Graham. So everything is installed. Being brand new to this world, 
>> I'm looking for a tutorial to (and please forgive me as I'm likely using 
>> the wrong terminology) see how to tell Apache to use mod_wsgi to run my 
>> flask app. I'm guessing that I need to change some config files in Apache 
>> to use my conda environment and then write some .wsgi file? However, I'm 
>> seeing quite a few different threads on this subject. Any advice is greatly 
>> appreciated.   
>>
>> ## get apache2
>> sudo apt-get install apache2
>> sudo apt-get install apache2-dev
>>
>> ## get mod_wsgi
>> pip install mod_wsgi
>>
>> #force load Anaconda's shared library
>> mod_wsgi-express module-config
>>
>> ## start/restart apache
>> sudo service apache2 restart 
>>
>> On Thursday, May 4, 2017 at 4:22:08 PM UTC-6, Graham Dumpleton wrote:
>>>
>>> As per instructions in:
>>>
>>>     https://pypi.python.org/pypi/mod_wsgi
>>>
>>> You need to ensure you have the 'dev' packages for Apache installed.
>>>
>>> If you are running Debian or Ubuntu Linux with Apache 2.4 system 
>>> packages, regardless of which Apache MPM is being used, you would need both:
>>>
>>>     apache2
>>>     apache2-dev
>>>
>>> Note that if using Anaconda Python, after having installed mod_wsgi with 
>>> pip, ensure you run:
>>>
>>>     mod_wsgi-express module-config
>>>
>>> to show the configuration you need to include in the system Apache if 
>>> you intend manually configuring it for mod_wsgi, instead of using 
>>> 'mod_wsgi-express start-server'.
>>>
>>> This is necessary as Anaconda Python can require extra configuration 
>>> directives to force load its shared library. That command should output the 
>>> appropriate lines, although just check that the generated line for LoadFile 
>>> directive actually points at a valid path. Seen one report where for 
>>> Anaconda Python the path it generated was wrong and it had to be changed.
>>>
>>> Graham
>>>
>>> On 5 May 2017, at 2:54 AM, Brian Lehman <[email protected]> wrote:
>>>
>>> Good day. When I try to pip install mod_wsgi inside of an anaconda env 
>>> called test1.0 on an aws ec2 instance w/ ubuntu, I get the folowing error. 
>>> Any suggestions?
>>>
>>> (test1.0) ubuntu$ python --version 
>>>
>>> Python 3.6.1 :: Continuum Analytics, Inc.
>>>
>>> (test1.0) ubuntu$ 
>>>
>>> (test1.0) ubuntu$ 
>>>
>>> (test1.0) ubuntu$ pip install mod_wsgi
>>>
>>> Collecting mod_wsgi
>>>
>>>   Using cached mod_wsgi-4.5.15.tar.gz
>>>
>>>     Complete output from command python setup.py egg_info:
>>>
>>>     Traceback (most recent call last):
>>>
>>>       File "<string>", line 1, in <module>
>>>
>>>       File "/tmp/pip-build-80walwu3/mod-wsgi/setup.py", line 164, in 
>>> <module>
>>>
>>>         'missing Apache httpd server packages.' % APXS)
>>>
>>>     RuntimeError: The 'apxs' command appears not to be installed or is 
>>> not executable. Please check the list of prerequisites in the documentation 
>>> for this package and install any missing Apache httpd server packages.
>>>     
>>>
>>>     ----------------------------------------
>>>
>>> Command "python setup.py egg_info" failed with error code 1 in 
>>> /tmp/pip-build-80walwu3/mod-wsgi/
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "modwsgi" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at https://groups.google.com/group/modwsgi.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>>
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "modwsgi" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at https://groups.google.com/group/modwsgi.
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Reply via email to