> On 14 Jun 2018, at 6:06 pm, Rajeev Jain <[email protected]> wrote:
> 
> Enabling WSGI on Apache2/Ubuntu16.04 is a very popular configuration. It 
> should not be this difficult.

It was complicated by starting out with trying to use Anaconda Python. That has 
confused things along the way.

> What python version do you want me to use?

Since there is a system package for Python 3.6, use it.

> Where do you want it installed?

You already have it installed.

> Please tell me precisely what steps to follow to get this running?

I already explained the steps.

Since though Python 3.6 does appear to be available as a system package, since 
you are having trouble with using pip install method, see if there is also a 
system Python 3.6 package for mod_wsgi.

Disable the mod_wsgi module using:

    a2dismod wsgi

Make a copy of the wsgi.load file just in case need it later. Then remove the 
wsgi.load file.

For good measure make sure you uninstall mod_wsgi for Python 2 in case it is 
still installed.

    apt-get uninstall libapache2-mod-wsgi

Ensure you remove any stuff you put in /usr/lib/apache2/modules previously for 
mod_wsgi:

-rwxr-xr-x 1 root root 974744 Jun 13 14:45 
mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so*
lrwxrwxrwx 1 root root     45 Jun 13 14:47 mod_wsgi.so -> 
mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so*
-rw-r--r-- 1 root root 207952 Jan 25  2016 mod_wsgi.so-3.5

Then run:

    apt-get install libapache2-mod-wsgi-py3

This should install mod_wsgi for Python 3 using system package.

Run ldd on the mod_wsgi module in /usr/lib/apache2/modules/ to make sure what 
Python version it is linking to.

Enable mod_wsgi.

    a2enmod wsgi

This has taken you back to stock standard system packages.

Check that wsgi.conf still has:

    WSGIRestrictEmbedded on

Everything in virtualhost.conf should be same as what I told you to use 
previously. Remember my follow comment about setting python-path as well as 
python-home.

Graham

> Please send me the following 2 files correctly and fully populated:
> 
> - wsgi.conf
> - virtualhost.conf
> 
> I'll revisit this in the morning.
> 
> thanks,
> —Rajeev
> 
> 
> On Jun 14, 2018, at 12:12 AM, Graham Dumpleton <[email protected] 
> <mailto:[email protected]>> wrote:
> 
> Check your wsgi.load contents is correct. Ie., current output of running:
> 
>     mod_wsgi-express module-config
> 
> for version installed in system Python 3.6.
> 
> Check that mods-enabled is symlink to it and not copy with wrong value.
> 
> The error indicates module wasn't loaded.
> 
>> On 14 Jun 2018, at 5:09 pm, 'Rajeev Jain' via modwsgi 
>> <[email protected] <mailto:[email protected]>> wrote:
>> 
>> did that and tried to restart the server. getting an error:
>> 
>> sudo service apache2 restart
>> Job for apache2.service failed because the control process exited with error 
>> code. See "systemctl status apache2.service" and "journalctl -xe" for 
>> details.
>> rajeev@cubi-ubuntu:/var/www/FlaskApp/FlaskApp$ systemctl status 
>> apache2.service
>> ● apache2.service - LSB: Apache2 web server
>>    Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
>>   Drop-In: /lib/systemd/system/apache2.service.d
>>            └─apache2-systemd.conf
>>    Active: failed (Result: exit-code) since Thu 2018-06-14 00:03:05 PDT; 8s 
>> ago
>>      Docs: man:systemd-sysv-generator(8)
>>   Process: 5405 ExecStop=/etc/init.d/apache2 stop (code=exited, 
>> status=0/SUCCESS)
>>   Process: 5531 ExecStart=/etc/init.d/apache2 start (code=exited, 
>> status=1/FAILURE)
>> 
>> Jun 14 00:03:05 cubi-ubuntu apache2[5531]:  * The apache2 configtest failed.
>> Jun 14 00:03:05 cubi-ubuntu apache2[5531]: Output of config test was:
>> Jun 14 00:03:05 cubi-ubuntu apache2[5531]: AH00526: Syntax error on line 5 
>> of /etc/apache2/sites-enabled/FlaskApp.conf:
>> Jun 14 00:03:05 cubi-ubuntu apache2[5531]: Invalid command 
>> 'WSGIDaemonProcess', perhaps misspelled or defined by a module not included 
>> in the server configuration
>> Jun 14 00:03:05 cubi-ubuntu apache2[5531]: Action 'configtest' failed.
>> Jun 14 00:03:05 cubi-ubuntu apache2[5531]: The Apache error log may have 
>> more information.
>> Jun 14 00:03:05 cubi-ubuntu systemd[1]: apache2.service: Control process 
>> exited, code=exited status=1
>> Jun 14 00:03:05 cubi-ubuntu systemd[1]: Failed to start LSB: Apache2 web 
>> server.
>> Jun 14 00:03:05 cubi-ubuntu systemd[1]: apache2.service: Unit entered failed 
>> state.
>> Jun 14 00:03:05 cubi-ubuntu systemd[1]: apache2.service: Failed with result 
>> 'exit-code’.
>> 
>> 
>> /etc/apache2/sites-available$ cat FlaskApp.conf 
>> <VirtualHost *:83>
>>     ServerName flaskapp.com <http://flaskapp.com/>
>> 
>>     WSGIDaemonProcess flaskapp.com <http://flaskapp.com/> python-home=/usr
>>     WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi 
>> process-group=flaskapp.com <http://flaskapp.com/> application-group=%{GLOBAL}
>> 
>>     <Directory /var/www/FlaskApp/>
>>     <Files flaskapp.wsgi>
>>     Require all granted
>>     </Files>
>>     </Directory>
>> </VirtualHost>
>> 
>> 
>> Do you see anything wrong?
>> 
>> —Rajeev
>> 
>> 
>> On Jun 13, 2018, at 11:52 PM, Graham Dumpleton <[email protected] 
>> <mailto:[email protected]>> wrote:
>> 
>> Do:
>> 
>>     pip uninstall mod_wsgi
>> 
>> Repeat until says not installed.
>> 
>> Then reinstall it.
>> 
>> Run 'ldd' on the mod_wsgi .so file that is built to see what Python shared 
>> library it is finding.
>> 
>> The installed version is possibly compiled against Anaconda Python somehow.
>> 
>> Also do a complete Apache stop and start, rather than reload. There is also 
>> a chance the Anaconda Python library hasn't unloaded from Apache properly.
>> 
>> Graham
>> 
>>> On 14 Jun 2018, at 4:28 pm, Rajeev Jain <[email protected] 
>>> <mailto:[email protected]>> wrote:
>>> 
>>> here is updated flask.wsgi
>>> 
>>> 
>>> here is error.log
>>> [Wed Jun 13 23:23:03.445837 2018] [wsgi:error] [pid 4758] 
>>> ModuleNotFoundError: No module named 'math'
>>> [Wed Jun 13 23:23:15.854525 2018] [wsgi:error] [pid 4758] VERSION 3.6.5 
>>> |Anaconda, Inc.| (default, Apr 29 2018, 16:17:00) 
>>> [Wed Jun 13 23:23:15.854556 2018] [wsgi:error] [pid 4758] [GCC 7.2.0]
>>> [Wed Jun 13 23:23:15.854563 2018] [wsgi:error] [pid 4758] 
>>> [Wed Jun 13 23:23:15.854581 2018] [wsgi:error] [pid 4758] PREFIX /usr
>>> [Wed Jun 13 23:23:15.854599 2018] [wsgi:error] [pid 4758] PATH 
>>> ['/var/www/FlaskApp/', '/var/www/FlaskApp/', '/var/www/FlaskApp', 
>>> '/usr/lib/python36.zip', '/usr/lib/python3.6', 
>>> '/usr/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/dist-packages', 
>>> '/usr/lib/python3/dist-packages']
>>> [Wed Jun 13 23:23:15.856916 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57696] mod_wsgi (pid=4758): Failed to exec Python script file 
>>> '/var/www/FlaskApp/flaskapp.wsgi'.
>>> [Wed Jun 13 23:23:15.856949 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57696] mod_wsgi (pid=4758): Exception occurred processing WSGI 
>>> script '/var/www/FlaskApp/flaskapp.wsgi'.
>>> [Wed Jun 13 23:23:15.857057 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57696] Traceback (most recent call last):
>>> [Wed Jun 13 23:23:15.857091 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57696]   File "/var/www/FlaskApp/flaskapp.wsgi", line 11, in 
>>> <module>
>>> [Wed Jun 13 23:23:15.857095 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57696]     from FlaskApp import app as application
>>> [Wed Jun 13 23:23:15.857100 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57696]   File "/var/www/FlaskApp/FlaskApp/__init__.py", line 2, 
>>> in <module>
>>> [Wed Jun 13 23:23:15.857103 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57696]     from flask import Flask
>>> [Wed Jun 13 23:23:15.857108 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57696]   File 
>>> "/usr/local/lib/python3.6/dist-packages/flask/__init__.py", line 17, in 
>>> <module>
>>> [Wed Jun 13 23:23:15.857110 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57696]     from werkzeug.exceptions import abort
>>> [Wed Jun 13 23:23:15.857115 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57696]   File 
>>> "/usr/local/lib/python3.6/dist-packages/werkzeug/__init__.py", line 151, in 
>>> <module>
>>> [Wed Jun 13 23:23:15.857117 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57696]     __import__('werkzeug.exceptions')
>>> [Wed Jun 13 23:23:15.857122 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57696]   File 
>>> "/usr/local/lib/python3.6/dist-packages/werkzeug/exceptions.py", line 67, 
>>> in <module>
>>> [Wed Jun 13 23:23:15.857124 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57696]     from werkzeug._internal import _get_environ
>>> [Wed Jun 13 23:23:15.857129 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57696]   File 
>>> "/usr/local/lib/python3.6/dist-packages/werkzeug/_internal.py", line 15, in 
>>> <module>
>>> [Wed Jun 13 23:23:15.857131 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57696]     from datetime import datetime, date
>>> [Wed Jun 13 23:23:15.857135 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57696]   File "/usr/lib/python3.6/datetime.py", line 8, in 
>>> <module>
>>> [Wed Jun 13 23:23:15.857138 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57696]     import math as _math
>>> [Wed Jun 13 23:23:15.857150 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57696] ModuleNotFoundError: No module named 'math'
>>> [Wed Jun 13 23:23:30.077689 2018] [wsgi:error] [pid 4758] VERSION 3.6.5 
>>> |Anaconda, Inc.| (default, Apr 29 2018, 16:17:00) 
>>> [Wed Jun 13 23:23:30.077714 2018] [wsgi:error] [pid 4758] [GCC 7.2.0]
>>> [Wed Jun 13 23:23:30.077720 2018] [wsgi:error] [pid 4758] 
>>> [Wed Jun 13 23:23:30.077729 2018] [wsgi:error] [pid 4758] PREFIX /usr
>>> [Wed Jun 13 23:23:30.077745 2018] [wsgi:error] [pid 4758] PATH 
>>> ['/var/www/FlaskApp/', '/var/www/FlaskApp/', '/var/www/FlaskApp/', 
>>> '/var/www/FlaskApp', '/usr/lib/python36.zip', '/usr/lib/python3.6', 
>>> '/usr/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/dist-packages', 
>>> '/usr/lib/python3/dist-packages']
>>> [Wed Jun 13 23:23:30.080656 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57698] mod_wsgi (pid=4758): Failed to exec Python script file 
>>> '/var/www/FlaskApp/flaskapp.wsgi'.
>>> [Wed Jun 13 23:23:30.080701 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57698] mod_wsgi (pid=4758): Exception occurred processing WSGI 
>>> script '/var/www/FlaskApp/flaskapp.wsgi'.
>>> [Wed Jun 13 23:23:30.080846 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57698] Traceback (most recent call last):
>>> [Wed Jun 13 23:23:30.080893 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57698]   File "/var/www/FlaskApp/flaskapp.wsgi", line 11, in 
>>> <module>
>>> [Wed Jun 13 23:23:30.080907 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57698]     from FlaskApp import app as application
>>> [Wed Jun 13 23:23:30.080916 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57698]   File "/var/www/FlaskApp/FlaskApp/__init__.py", line 2, 
>>> in <module>
>>> [Wed Jun 13 23:23:30.080921 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57698]     from flask import Flask
>>> [Wed Jun 13 23:23:30.080927 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57698]   File 
>>> "/usr/local/lib/python3.6/dist-packages/flask/__init__.py", line 17, in 
>>> <module>
>>> [Wed Jun 13 23:23:30.080931 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57698]     from werkzeug.exceptions import abort
>>> [Wed Jun 13 23:23:30.080937 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57698]   File 
>>> "/usr/local/lib/python3.6/dist-packages/werkzeug/__init__.py", line 151, in 
>>> <module>
>>> [Wed Jun 13 23:23:30.080941 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57698]     __import__('werkzeug.exceptions')
>>> [Wed Jun 13 23:23:30.080947 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57698]   File 
>>> "/usr/local/lib/python3.6/dist-packages/werkzeug/exceptions.py", line 67, 
>>> in <module>
>>> [Wed Jun 13 23:23:30.080951 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57698]     from werkzeug._internal import _get_environ
>>> [Wed Jun 13 23:23:30.080957 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57698]   File 
>>> "/usr/local/lib/python3.6/dist-packages/werkzeug/_internal.py", line 15, in 
>>> <module>
>>> [Wed Jun 13 23:23:30.080961 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57698]     from datetime import datetime, date
>>> [Wed Jun 13 23:23:30.080967 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57698]   File "/usr/lib/python3.6/datetime.py", line 8, in 
>>> <module>
>>> [Wed Jun 13 23:23:30.080971 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57698]     import math as _math
>>> [Wed Jun 13 23:23:30.080988 2018] [wsgi:error] [pid 4758] [remote 
>>> 127.0.0.1:57698] ModuleNotFoundError: No module named 'math'
>>> 
>>> How is Anaconda being picked up?
>>> 
>>> Can we check PATH setting for Apache boot ?
>>> 
>>> 
>>> On Jun 13, 2018, at 11:17 PM, Graham Dumpleton <[email protected] 
>>> <mailto:[email protected]>> wrote:
>>> 
>>>     print('VERSION', sys.version)
>>>     print('PREFIX', sys.prefix)
>>>     print('PATH', sys.path)
>>> 
>>> 
>>> -- 
>>> 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] 
>>> <mailto:[email protected]>.
>>> To post to this group, send email to [email protected] 
>>> <mailto:[email protected]>.
>>> Visit this group at https://groups.google.com/group/modwsgi 
>>> <https://groups.google.com/group/modwsgi>.
>>> For more options, visit https://groups.google.com/d/optout 
>>> <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] 
>> <mailto:[email protected]>.
>> To post to this group, send email to [email protected] 
>> <mailto:[email protected]>.
>> Visit this group at https://groups.google.com/group/modwsgi 
>> <https://groups.google.com/group/modwsgi>.
>> For more options, visit https://groups.google.com/d/optout 
>> <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] 
>> <mailto:[email protected]>.
>> To post to this group, send email to [email protected] 
>> <mailto:[email protected]>.
>> Visit this group at https://groups.google.com/group/modwsgi 
>> <https://groups.google.com/group/modwsgi>.
>> For more options, visit https://groups.google.com/d/optout 
>> <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] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> Visit this group at https://groups.google.com/group/modwsgi 
> <https://groups.google.com/group/modwsgi>.
> For more options, visit https://groups.google.com/d/optout 
> <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] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> Visit this group at https://groups.google.com/group/modwsgi 
> <https://groups.google.com/group/modwsgi>.
> For more options, visit https://groups.google.com/d/optout 
> <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