(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 modwsgi+u...@googlegroups.com.
To post to this group, send email to mod...@googlegroups.com.
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.
## 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
## 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
<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>
(test1.0) ubuntu:/var/www$ tree
.
├── FlaskApp
├── FlaskApp
│ ├── __init__.py
│ ├── static
│ └── templates
└── 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>'
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World (flask via conda env)!"
if __name__ == "__main__":
app.run()
[Mon May 08 16:39:11.002873 2017] [:error] [pid 31696:tid 139896253531904] [client 208.184.3.194:36413] Traceback (most recent call last):
[Mon May 08 16:39:11.002923 2017] [:error] [pid 31696:tid 139896253531904] [client 208.184.3.194:36413] File "/var/www/FlaskApp/flaskapp.wsgi", line 7, in <module>
[Mon May 08 16:39:11.002989 2017] [:error] [pid 31696:tid 139896253531904] [client 208.184.3.194:36413] from FlaskApp import app as application
[Mon May 08 16:39:11.003012 2017] [:error] [pid 31696:tid 139896253531904] [client 208.184.3.194:36413] File "/var/www/FlaskApp/FlaskApp/__init__.py", line 1, in <module>
[Mon May 08 16:39:11.003044 2017] [:error] [pid 31696:tid 139896253531904] [client 208.184.3.194:36413] from flask import Flask
[Mon May 08 16:39:11.003081 2017] [:error] [pid 31696:tid 139896253531904] [client 208.184.3.194:36413] ImportError: No module named flask<VirtualHost *:80>
ServerName <public ip>.us-west-2.compute.amazonaws.com
ServerAdmin ubuntu@ec2-<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>
WSGIDaemonProcess FlaskApp python-path=/home/ubuntu/anaconda3/envs/test1.0/lib/python3.6/site-packages
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
## 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
## Install and register the mod_wsgi module with Apache <--------------------------
sudo `which mod_wsgi-express` install-module
## get git
sudo apt-get install git
## create apache config
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
Traceback (most recent call last):
File "/var/www/FlaskApp/flaskapp.wsgi", line 7, in <module>
from FlaskApp import app as
application
File "/var/www/FlaskApp/FlaskApp/__init__.py", line 1, in <module>
from flask import Flask
ImportError: No module named flask
Wed Jun 13 00:15:55.875613 2018] [mpm_prefork:notice] [pid 5367] AH00163: Apache/2.4.18 (Ubuntu) OpenSSL/1.0.2g mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[Wed Jun 13 00:15:55.875649 2018] [core:notice] [pid 5367] AH00094: Command line: '/usr/sbin/apache2'
[Wed Jun 13 00:16:02.051821 2018] [wsgi:error] [pid 5371] [client 127.0.0.1:50318] mod_wsgi (pid=5371): Target WSGI script '/var/www/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module.
[Wed Jun 13 00:16:02.051892 2018] [wsgi:error] [pid 5371] [client 127.0.0.1:50318] mod_wsgi (pid=5371): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'.
[Wed Jun 13 00:16:02.061170 2018] [wsgi:error] [pid 5371] [client 127.0.0.1:50318] Traceback (most recent call last):
[Wed Jun 13 00:16:02.061202 2018] [wsgi:error] [pid 5371] [client 127.0.0.1:50318] File "/var/www/FlaskApp/flaskapp.wsgi", line 7, in <module>
[Wed Jun 13 00:16:02.061207 2018] [wsgi:error] [pid 5371] [client 127.0.0.1:50318] from FlaskApp import app as application
[Wed Jun 13 00:16:02.061214 2018] [wsgi:error] [pid 5371] [client 127.0.0.1:50318] File "/var/www/FlaskApp/FlaskApp/__init__.py", line 2, in <module>
[Wed Jun 13 00:16:02.061217 2018] [wsgi:error] [pid 5371] [client 127.0.0.1:50318] from flask import Flask
[Wed Jun 13 00:16:02.061234 2018] [wsgi:error] [pid 5371] [client 127.0.0.1:50318] ImportError: No module named 'flask'
user@ubuntu:/etc/apache2/mods-available$ pip install mod_wsgi
Collecting mod_wsgi
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-k87n4cm_/mod-wsgi/setup.py", line 168, 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.
On 13 Jun 2018, at 6:38 pm, Rajeev Jain <jain...@gmail.com> wrote:Your point is well taken. Its 100% the exact same situation. Same objective, appears to be a similar software setup and same exact error. No need to repeat what has already been stated.
error I'm trying to resolve:Wed Jun 13 00:15:55.875613 2018] [mpm_prefork:notice] [pid 5367] AH00163: Apache/2.4.18 (Ubuntu) OpenSSL/1.0.2g mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[Wed Jun 13 00:15:55.875649 2018] [core:notice] [pid 5367] AH00094: Command line: '/usr/sbin/apache2'
[Wed Jun 13 00:16:02.051821 2018] [wsgi:error] [pid 5371] [client 127.0.0.1:50318] mod_wsgi (pid=5371): Target WSGI script '/var/www/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module.
[Wed Jun 13 00:16:02.051892 2018] [wsgi:error] [pid 5371] [client 127.0.0.1:50318] mod_wsgi (pid=5371): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'.
[Wed Jun 13 00:16:02.061170 2018] [wsgi:error] [pid 5371] [client 127.0.0.1:50318] Traceback (most recent call last):
[Wed Jun 13 00:16:02.061202 2018] [wsgi:error] [pid 5371] [client 127.0.0.1:50318] File "/var/www/FlaskApp/flaskapp.wsgi", line 7, in <module>
[Wed Jun 13 00:16:02.061207 2018] [wsgi:error] [pid 5371] [client 127.0.0.1:50318] from FlaskApp import app as application
[Wed Jun 13 00:16:02.061214 2018] [wsgi:error] [pid 5371] [client 127.0.0.1:50318] File "/var/www/FlaskApp/FlaskApp/__init__.py", line 2, in <module>
[Wed Jun 13 00:16:02.061217 2018] [wsgi:error] [pid 5371] [client 127.0.0.1:50318] from flask import Flask
[Wed Jun 13 00:16:02.061234 2018] [wsgi:error] [pid 5371] [client 127.0.0.1:50318] ImportError: No module named 'flask'
In your step 4. Install mod_wsgi using pip. this is giving same error as the start of this thread.user@ubuntu:/etc/apache2/mods-available$ pip install mod_wsgi
Collecting mod_wsgi
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-k87n4cm_/mod-wsgi/setup.py", line 168, 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.
So you know for future. In a multi part email chain it can be difficult to go back and extract what configuration may have been used that you might be referring to. So when you ask questions you should always repeat what is occurring in your case. It is even better not to reply on a previous email chain and the history of the previous issue, which may not be the same, can just confuse things. So I am just going to ask for the configuration again.
From the command line, if you run the 'python' you want to use, what do you get when from the interpreter you do:import flaskprint(flask.__file__)
Also what do you get for:import sysprint(sys.prefix)
/home/rajeev/anaconda3
The prior configuration example in the email chain was not setting up the Python virtual environment correctly so can't be used as a guide.I need to see what is in the wsgi.load file if still using system package for mod_wsgi.
/etc/apache2/mods-enabled$ cat wsgi.load
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
notes:
1) was able to successfully pip install mod_wsgi
pip install mod_wsgi
Requirement already satisfied: mod_wsgi in ./anaconda3/lib/python3.6/site-packages (4.6.4)
2) updated softlink to use new object
/usr/lib/apache2/modules$ ll mod_wsg*
-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
tail -l /var/log/apache2/error.log
[Wed Jun 13 15:08:13.942743 2018] [mpm_prefork:notice] [pid 23851] AH00169: caught SIGTERM, shutting down
[Wed Jun 13 15:12:14.024133 2018] [ssl:warn] [pid 24110] AH01909: 198.105.244.228:443:0 server certificate does NOT include an ID which matches the server name
[Wed Jun 13 15:12:14.114890 2018] [ssl:warn] [pid 24111] AH01909: 198.105.244.228:443:0 server certificate does NOT include an ID which matches the server name
[Wed Jun 13 15:12:14.121149 2018] [mpm_prefork:notice] [pid 24111] AH00163: Apache/2.4.18 (Ubuntu) OpenSSL/1.0.2g mod_wsgi/4.6.4 Python/3.6 configured -- resuming normal operations
[Wed Jun 13 15:12:14.121185 2018] [core:notice] [pid 24111] AH00094: Command line: '/usr/sbin/apache2'
I then need to see what you may have set WSGIPythonHome, WSGIPythonPath, and general configuration for mod_wsgi in the VirtualHost, including WSGIDaemonProcess. Basically, include all what you are using in your response. I really need to see what you are using, and not what someone else used, even if you think it is the same.
/etc/apache2/mods-enabled$ cat wsgi.conf
<IfModule mod_wsgi.c>
WSGIPythonHome /home/rajeev/anaconda3
WSGIPythonPath /home/rajeev/anaconda3/lib/python3.6/site-packages
</IfModule>
<VirtualHost *:83>
ServerName flaskapp.com
WSGIDaemonProcess flaskapp.com python-path=/home/rajeev/anaconda3
WSGIProcessGroup %{GLOBAL}
WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
<Directory /var/www/FlaskApp/FlaskApp/>
Require all granted
</Directory>
</VirtualHost>
Also show anything you have added in the WSGI script file to try and activate a virtual environment, or changes you are making to sys.path.
/var/www/FlaskApp$ cat flaskapp.wsgi
#!/home/rajeev/anaconda3/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 = 'Add your secret key'
Testing:
curl -sH 'Host: flaskapp.com' localhost:83|grep title
<title>500 Internal Server Error</title>
tail -l /var/log/apache2/error.log
[Wed Jun 13 15:46:22.636400 2018] [wsgi:error] [pid 2199] [client 127.0.0.1:38068] from flask import Flask
[Wed Jun 13 15:46:22.636406 2018] [wsgi:error] [pid 2199] [client 127.0.0.1:38068] File "/home/rajeev/anaconda3/lib/python3.6/site-packages/flask/__init__.py", line 21, in <module>
[Wed Jun 13 15:46:22.636409 2018] [wsgi:error] [pid 2199] [client 127.0.0.1:38068] from .app import Flask, Request, Response
[Wed Jun 13 15:46:22.636413 2018] [wsgi:error] [pid 2199] [client 127.0.0.1:38068] File "/home/rajeev/anaconda3/lib/python3.6/site-packages/flask/app.py", line 25, in <module>
[Wed Jun 13 15:46:22.636416 2018] [wsgi:error] [pid 2199] [client 127.0.0.1:38068] from . import cli, json
[Wed Jun 13 15:46:22.636421 2018] [wsgi:error] [pid 2199] [client 127.0.0.1:38068] File "/home/rajeev/anaconda3/lib/python3.6/site-packages/flask/cli.py", line 18, in <module>
[Wed Jun 13 15:46:22.636424 2018] [wsgi:error] [pid 2199] [client 127.0.0.1:38068] import ssl
[Wed Jun 13 15:46:22.636429 2018] [wsgi:error] [pid 2199] [client 127.0.0.1:38068] File "/home/rajeev/anaconda3/lib/python3.6/ssl.py", line 101, in <module>
[Wed Jun 13 15:46:22.636432 2018] [wsgi:error] [pid 2199] [client 127.0.0.1:38068] import _ssl # if we can't import it, let the error propagate
[Wed Jun 13 15:46:22.636453 2018] [wsgi:error] [pid 2199] [client 127.0.0.1:38068] ImportError: /home/rajeev/anaconda3/lib/python3.6/lib-dynload/_ssl.cpython-36m-x86_64-linux-gnu.so: undefined symbol: SSLv2_method
/var/www/FlaskApp/FlaskApp$ python __init__.py
* Serving Flask app "__init__" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [13/Jun/2018 15:48:53] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [13/Jun/2018 15:48:53] "GET /favicon.ico HTTP/1.1" 404 -
Using browser on server (http://localhost:5000)is able to load test page
This is where I am at...
Your help is greatly appreciated. Perhaps I should consider setting a new virtual environment...
Thanks,
--Rajeev
On 14 Jun 2018, at 8:52 am, Rajeev Jain <jain...@gmail.com> wrote:So you know for future. In a multi part email chain it can be difficult to go back and extract what configuration may have been used that you might be referring to. So when you ask questions you should always repeat what is occurring in your case. It is even better not to reply on a previous email chain and the history of the previous issue, which may not be the same, can just confuse things. So I am just going to ask for the configuration again.Understood. No problem.Where is the Flask package installed?On my Ubuntu 16.04 system, anaconda python and all python modules are installed in my home directory. There is no virtual environment. When I log-in the PATH environment variable is set so any invocation of python uses the desired python distribution. All my python code is able to find all other installed modules. There is history and legacy here.My immediate objective is to have the Apache server boot and use the python distribution in my home directory for all Flask/WSGI related processing.From the command line, if you run the 'python' you want to use, what do you get when from the interpreter you do:import flaskprint(flask.__file__)/home/rajeev/anaconda3/lib/python3.6/site-packages/flask/__init__.pyAlso what do you get for:import sysprint(sys.prefix)/home/rajeev/anaconda3The prior configuration example in the email chain was not setting up the Python virtual environment correctly so can't be used as a guide.I need to see what is in the wsgi.load file if still using system package for mod_wsgi./etc/apache2/mods-enabled$ cat wsgi.loadLoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
notes:1) was able to successfully pip install mod_wsgipip install mod_wsgiRequirement already satisfied: mod_wsgi in ./anaconda3/lib/python3.6/site-packages (4.6.4)2) updated softlink to use new object/usr/lib/apache2/modules$ ll mod_wsg*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.53) server log shows the new mod_wsgi is being loaded.tail -l /var/log/apache2/error.log[Wed Jun 13 15:08:13.942743 2018] [mpm_prefork:notice] [pid 23851] AH00169: caught SIGTERM, shutting down[Wed Jun 13 15:12:14.024133 2018] [ssl:warn] [pid 24110] AH01909: 198.105.244.228:443:0 server certificate does NOT include an ID which matches the server name[Wed Jun 13 15:12:14.114890 2018] [ssl:warn] [pid 24111] AH01909: 198.105.244.228:443:0 server certificate does NOT include an ID which matches the server name[Wed Jun 13 15:12:14.121149 2018] [mpm_prefork:notice] [pid 24111] AH00163: Apache/2.4.18 (Ubuntu) OpenSSL/1.0.2g mod_wsgi/4.6.4 Python/3.6 configured -- resuming normal operations[Wed Jun 13 15:12:14.121185 2018] [core:notice] [pid 24111] AH00094: Command line: '/usr/sbin/apache2'I then need to see what you may have set WSGIPythonHome, WSGIPythonPath, and general configuration for mod_wsgi in the VirtualHost, including WSGIDaemonProcess. Basically, include all what you are using in your response. I really need to see what you are using, and not what someone else used, even if you think it is the same./etc/apache2/mods-enabled$ cat wsgi.conf<IfModule mod_wsgi.c>
WSGIPythonHome /home/rajeev/anaconda3WSGIPythonPath /home/rajeev/anaconda3/lib/python3.6/site-packages</IfModule>
/etc/apache2/sites-available$ cat FlaskApp.conf<VirtualHost *:83>ServerName flaskapp.comWSGIDaemonProcess flaskapp.com python-path=/home/rajeev/anaconda3
WSGIProcessGroup %{GLOBAL}
WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
<Directory /var/www/FlaskApp/FlaskApp/>
/var/www/FlaskApp/FlaskApp$ python __init__.py* Serving Flask app "__init__" (lazy loading)* Environment: productionWARNING: Do not use the development server in a production environment.Use a production WSGI server instead.* Debug mode: off* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)127.0.0.1 - - [13/Jun/2018 15:48:53] "GET / HTTP/1.1" 200 -127.0.0.1 - - [13/Jun/2018 15:48:53] "GET /favicon.ico HTTP/1.1" 404 -Using browser on server (http://localhost:5000)is able to load test pageThis is where I am at...
It is probably better to have run:mod_wsgi-express module-configThat should give you a LoadModule line for loading the mod_wsgi.so file from the place it is installed, as well as a LoadFile which loads the correct Python shared library for Anaconda, so the system Python library isn't picked up by mistake. Add the output of that into wsgi.load in place of what you have.
mod_wsgi-express module-config
LoadModule wsgi_module "/home/rajeev/anaconda3/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"
WSGIPythonHome "/home/rajeev/anaconda3"
cat wsgi.load
LoadModule wsgi_module "/home/rajeev/anaconda3/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"
Instead of WSGIPythonHome and WSGIPythonPath here, have:WSGIRestrictEmbedded OnThat will turn off embedded mode and if configuration is wrong and application is not delegated to daemon mode processes correctly, you will get a 500 error to tell you you have an issue.
WSGIDaemonProcess flaskapp.com python-home=/home/rajeev/anaconda3
WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi process-group=flaskapp.com application-group=%{GLOBAL}
<Directory /var/www/FlaskApp>
<Files flaskapp.wsgi>
Require all granted
</Files>
</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>
When using Anaconda Python, you cannot used mod_ssl in Apache. This is because Anaconda Python ships its own SSL libraries which aren't compatible, and by having mod_ssl loaded, the system SSL libraries will get loaded first, resulting in any use of SSL in Python to fail.If not using SSL in Apache, disable mod_ss
l. If you are using it, the only way to do it is to use mod_wsgi-express to create a distinct instance and have the main Apache proxy to it.
/etc/apache2/sites-available$ sudo a2dismod ssl
Module ssl disabled.
To activate the new configuration, you need to run:
service apache2 restart
After all that is addressed, we will see if any issues with permissions. That is, whether the Apache user can actually read everything in your home directory.
tail -l /var/log/apache2/error.log
[Wed Jun 13 17:50:04.857839 2018] [wsgi:error] [pid 2177] [remote 127.0.0.1:60208] from flask import Flask
[Wed Jun 13 17:50:04.857844 2018] [wsgi:error] [pid 2177] [remote 127.0.0.1:60208] File "/home/rajeev/anaconda3/lib/python3.6/site-packages/flask/__init__.py", line 21, in <module>
[Wed Jun 13 17:50:04.857847 2018] [wsgi:error] [pid 2177] [remote 127.0.0.1:60208] from .app import Flask, Request, Response
[Wed Jun 13 17:50:04.857852 2018] [wsgi:error] [pid 2177] [remote 127.0.0.1:60208] File "/home/rajeev/anaconda3/lib/python3.6/site-packages/flask/app.py", line 25, in <module>
[Wed Jun 13 17:50:04.857854 2018] [wsgi:error] [pid 2177] [remote 127.0.0.1:60208] from . import cli, json
[Wed Jun 13 17:50:04.857859 2018] [wsgi:error] [pid 2177] [remote 127.0.0.1:60208] File "/home/rajeev/anaconda3/lib/python3.6/site-packages/flask/cli.py", line 18, in <module>
[Wed Jun 13 17:50:04.857862 2018] [wsgi:error] [pid 2177] [remote 127.0.0.1:60208] import ssl
[Wed Jun 13 17:50:04.857866 2018] [wsgi:error] [pid 2177] [remote 127.0.0.1:60208] File "/home/rajeev/anaconda3/lib/python3.6/ssl.py", line 101, in <module>
[Wed Jun 13 17:50:04.857869 2018] [wsgi:error] [pid 2177] [remote 127.0.0.1:60208] import _ssl # if we can't import it, let the error propagate
[Wed Jun 13 17:50:04.857884 2018] [wsgi:error] [pid 2177] [remote 127.0.0.1:60208] ImportError: /home/rajeev/anaconda3/lib/python3.6/lib-dynload/_ssl.cpython-36m-x86_64-linux-gnu.so: undefined symbol: SSLv2_method
I verified ssl was disabled:
sudo a2dismod ssl
[sudo] password for rajeev:
Module ssl already disabled
I'm concerned what change is generating that "System program problem detected" and why its still complaining about SSL sysmbol even though we disabled the mod_ssl.
Suggestions, next steps? We should be close...just a configuration issue, yes?
[Wed Jun 13 17:55:33.173679 2018] [mpm_prefork:notice] [pid 2174] AH00169: caught SIGTERM, shutting down
[Wed Jun 13 17:55:34.421101 2018] [mpm_prefork:notice] [pid 2501] AH00163: Apache/2.4.18 (Ubuntu) mod_wsgi/4.6.4 Python/3.6 configured -- resuming normal operations
[Wed Jun 13 17:55:34.421158 2018] [core:notice] [pid 2501] AH00094: Command line: '/usr/sbin/apache2'
[Wed Jun 13 17:55:34.576866 2018] [wsgi:error] [pid 2504] mod_wsgi (pid=2504): Failed to exec Python script file '/var/www/FlaskApp/flaskapp.wsgi'.
[Wed Jun 13 17:55:34.576923 2018] [wsgi:error] [pid 2504] mod_wsgi (pid=2504): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'.
[Wed Jun 13 17:55:34.578129 2018] [wsgi:error] [pid 2504] Traceback (most recent call last):
[Wed Jun 13 17:55:34.578169 2018] [wsgi:error] [pid 2504] File "/var/www/FlaskApp/flaskapp.wsgi", line 7, in <module>
[Wed Jun 13 17:55:34.578182 2018] [wsgi:error] [pid 2504] from FlaskApp import app as application
[Wed Jun 13 17:55:34.578189 2018] [wsgi:error] [pid 2504] File "/var/www/FlaskApp/FlaskApp/__init__.py", line 2, in <module>
[Wed Jun 13 17:55:34.578192 2018] [wsgi:error] [pid 2504] from flask import Flask
[Wed Jun 13 17:55:34.578197 2018] [wsgi:error] [pid 2504] File "/home/rajeev/anaconda3/lib/python3.6/site-packages/flask/__init__.py", line 21, in <module>
[Wed Jun 13 17:55:34.578200 2018] [wsgi:error] [pid 2504] from .app import Flask, Request, Response
[Wed Jun 13 17:55:34.578205 2018] [wsgi:error] [pid 2504] File "/home/rajeev/anaconda3/lib/python3.6/site-packages/flask/app.py", line 25, in <module>
[Wed Jun 13 17:55:34.578207 2018] [wsgi:error] [pid 2504] from . import cli, json
[Wed Jun 13 17:55:34.578212 2018] [wsgi:error] [pid 2504] File "/home/rajeev/anaconda3/lib/python3.6/site-packages/flask/cli.py", line 18, in <module>
[Wed Jun 13 17:55:34.578218 2018] [wsgi:error] [pid 2504] import ssl
[Wed Jun 13 17:55:34.578223 2018] [wsgi:error] [pid 2504] File "/home/rajeev/anaconda3/lib/python3.6/ssl.py", line 101, in <module>
[Wed Jun 13 17:55:34.578225 2018] [wsgi:error] [pid 2504] import _ssl # if we can't import it, let the error propagate
[Wed Jun 13 17:55:34.578243 2018] [wsgi:error] [pid 2504] ImportError: /home/rajeev/anaconda3/lib/python3.6/lib-dynload/_ssl.cpython-36m-x86_64-linux-gnu.so: undefined symbol: SSLv2_method
/etc/apache2/mods-available$ ls
access_compat.load authn_file.load cache_disk.conf deflate.conf heartmonitor.load macro.load php7.0.load proxy.load session.load suexec.load
actions.conf authn_socache.load cache_disk.load deflate.load ident.load mime.conf proxy_ajp.load proxy_scgi.load setenvif.conf unique_id.load
actions.load authnz_fcgi.load cache.load dialup.load include.load mime.load proxy_balancer.conf proxy_wstunnel.load setenvif.load userdir.conf
alias.conf authnz_ldap.load cache_socache.load dir.conf info.conf mime_magic.conf proxy_balancer.load ratelimit.load slotmem_plain.load userdir.load
alias.load authz_core.load cgid.conf dir.load info.load mime_magic.load proxy.conf reflector.load slotmem_shm.load usertrack.load
allowmethods.load authz_dbd.load cgid.load dump_io.load lbmethod_bybusyness.load mpm_event.conf proxy_connect.load remoteip.load socache_dbm.load vhost_alias.load
asis.load authz_dbm.load cgi.load echo.load lbmethod_byrequests.load mpm_event.load proxy_express.load reqtimeout.conf socache_memcache.load wsgi.conf
auth_basic.load authz_groupfile.load charset_lite.load env.load lbmethod_bytraffic.load mpm_prefork.conf proxy_fcgi.load reqtimeout.load socache_shmcb.load wsgi.load
auth_digest.load authz_host.load data.load expires.load lbmethod_heartbeat.load mpm_prefork.load proxy_fdpass.load request.load speling.load xml2enc.load
auth_form.load authz_owner.load dav_fs.conf ext_filter.load ldap.conf mpm_worker.conf proxy_ftp.conf rewrite.load ssl.conf
authn_anon.load authz_user.load dav_fs.load file_cache.load ldap.load mpm_worker.load proxy_ftp.load sed.load ssl.load
authn_core.load autoindex.conf dav.load filter.load log_debug.load negotiation.conf proxy_html.conf session_cookie.load status.conf
authn_dbd.load autoindex.load dav_lock.load headers.load log_forensic.load negotiation.load proxy_html.load session_crypto.load status.load
authn_dbm.load buffer.load dbd.load heartbeat.load lua.load php7.0.conf proxy_http.load session_dbd.load substitute.load
On 14 Jun 2018, at 11:34 am, Rajeev Jain <jain...@gmail.com> wrote:I want to thank you for the time you spent with me. It is clear, using Anaconda with Apache is not a good idea. My objective now is to setup a virtual environment, and then configure a Apache virtual host to use it. There is a multitude of half complete solutions out there to accomplish this. Would you be kind enough to point me to from your perspective the best guide for this objective? I want to make sure the essential parameters are correctly set.Any examples for the following files would very helpful:- wsgi.conf
- wsgi.load
- myhost.conf
Latest update:
/etc/apache2/sites-available$ python --version
Python 3.6.5
python
Python 3.6.5 (default, May 3 2018, 10:08:28)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.prefix)
/usr
Flask location:
>>> import flask
>>> print(flask.__file__)
/usr/local/lib/python3.6/dist-packages/flask/__init__.py
mod_wsgi-express module-config
LoadModule wsgi_module "/usr/local/lib/python3.6/dist-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"
WSGIPythonHome "/usr"
cat wsgi.load
LoadModule wsgi_module /usr/local/lib/python3.6/dist-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so
WSGIDaemonProcess flaskapp.com python-home=/usr python-path=/var/www/FlaskApp
WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi process-group=flaskapp.com application-group=%{GLOBAL}
<Directory /var/www/FlaskApp/>
<Files flaskapp.wsgi>
Require all granted
</Files>
</Directory>
</VirtualHost>
/etc/apache2/mods-available$ cat wsgi.conf
<IfModule mod_wsgi.c>
WSGIRestrictEmbedded On
</IfModule>
Testing:
curl -sH 'Host: flaskapp.com' localhost:83|grep title
<title>500 Internal Server Error</title>
tail -l /var/log/apache2/error.log
[Wed Jun 13 22:18:08.678744 2018] [wsgi:error] [pid 3095] [remote 127.0.0.1:57590] from werkzeug.exceptions import abort
[Wed Jun 13 22:18:08.678749 2018] [wsgi:error] [pid 3095] [remote 127.0.0.1:57590] File "/usr/local/lib/python3.6/dist-packages/werkzeug/__init__.py", line 151, in <module>
[Wed Jun 13 22:18:08.678752 2018] [wsgi:error] [pid 3095] [remote 127.0.0.1:57590] __import__('werkzeug.exceptions')
[Wed Jun 13 22:18:08.678756 2018] [wsgi:error] [pid 3095] [remote 127.0.0.1:57590] File "/usr/local/lib/python3.6/dist-packages/werkzeug/exceptions.py", line 67, in <module>
[Wed Jun 13 22:18:08.678759 2018] [wsgi:error] [pid 3095] [remote 127.0.0.1:57590] from werkzeug._internal import _get_environ
[Wed Jun 13 22:18:08.678764 2018] [wsgi:error] [pid 3095] [remote 127.0.0.1:57590] File "/usr/local/lib/python3.6/dist-packages/werkzeug/_internal.py", line 15, in <module>
[Wed Jun 13 22:18:08.678766 2018] [wsgi:error] [pid 3095] [remote 127.0.0.1:57590] from datetime import datetime, date
[Wed Jun 13 22:18:08.678771 2018] [wsgi:error] [pid 3095] [remote 127.0.0.1:57590] File "/usr/lib/python3.6/datetime.py", line 8, in <module>
[Wed Jun 13 22:18:08.678773 2018] [wsgi:error] [pid 3095] [remote 127.0.0.1:57590] import math as _math
[Wed Jun 13 22:18:08.678786 2018] [wsgi:error] [pid 3095] [remote 127.0.0.1:57590] ModuleNotFoundError: No module named 'math'
Running FlaskApp on its own:
/var/www/FlaskApp/FlaskApp$ python __init__.py
* Serving Flask app "__init__" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [13/Jun/2018 22:25:23] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [13/Jun/2018 22:25:23] "GET /favicon.ico HTTP/1.1" 404 -
curl -sH 'Host: flaskapp.com' localhost:5000
Hello, this is running from flasK!
As you can see the FlaskApp is running fine.
Python and all modules are now installed in system locations and they are running fine.
Apache2 is running fine. I have 2 other virtualhosts running serving php/html pages
Still WSGI is still not setup correctly.
I'm shocked at the lack of decent documentation to get WCGI enabled on a Apache2 server. What am I missing??
Don't you have some basic test code or files one can run to verify the WSGI is setup correctly?
Please advise.
--Rajeev
Don't you have some basic test code or files one can run to verify the WSGI is setup correctly?
Please advise.--Rajeev
Let's suppose that you have a system running Ubuntu 16.04, 16.10, or 17.04, and you want Python 3.6 to be the default Python.
If you're using Ubuntu 16.04 LTS, you'll need to use a PPA:
sudo add-apt-repository ppa:jonathonf/python-3.6 # (only for 16.04 LTS)Then, run the following (this works out-of-the-box on 16.10 and 17.04):
sudo apt update
sudo apt install python3.6
sudo apt install python3.6-dev
sudo apt install python3.6-venv
wget https://bootstrap.pypa.io/get-pip.py
sudo python3.6 get-pip.py
sudo ln -s /usr/bin/python3.6 /usr/local/bin/python3
sudo ln -s /usr/local/bin/pip /usr/local/bin/pip3
# Do this only if you want python3 to be the default Python
# instead of python2 (may be dangerous, esp. before 2020):
# sudo ln -s /usr/bin/python3.6 /usr/local/bin/pythonWhen you have completed all of the above, each of the following shell commands should indicate Python 3.6.1 (or a more recent version of Python 3.6):
python --version # (this will reflect your choice, see above)
python3 --version
$(head -1 `which pip` | tail -c +3) --version
$(head -1 `which pip3` | tail -c +3) --versionOn 14 Jun 2018, at 4:06 pm, Rajeev Jain <jain...@gmail.com> wrote:on Jun 13, 2018, at 10:58 PM, Graham Dumpleton <graham.d...@gmail.com> wrote:Instead then. Print out sys.path from the interpreter and then also from your WSGI script file.pythonPython 3.6.5 (default, May 3 2018, 10:08:28)[GCC 5.4.0 20160609] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import sys>>> print(sys.path)['', '/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']>>>cat flaskapp.wsgi#!/usr/local/pythonimport sysimport logginglogging.basicConfig(stream=sys.stderr)sys.path.insert(0,"/var/www/FlaskApp/")
On 14 Jun 2018, at 6:06 pm, Rajeev Jain <jain...@gmail.com> wrote:Enabling WSGI on Apache2/Ubuntu16.04 is a very popular configuration. It should not be this difficult.
What python version do you want me to use?
Where do you want it installed?
Please tell me precisely what steps to follow to get this running?

On 24 Jun 2018, at 7:55 am, 'Rajeev Jain' via modwsgi <mod...@googlegroups.com> wrote:
background: my system is Ubuntu16.04 LTS running on a home network behind a firewall. Apache2 server is installed and successfully hosting 3 virtual hosts using ports 80, 81, 82. These 3 sites are working 100% fine. My objective is to setup a 4th virtual host using mod_wsgi for serving a python3.6 based Flask Application.After many trials and tribulations the 4th virtual host is now partially working...the site is successfully served when using the curl command but the site is not accessible when using a browser.Here is the tutorial I used:Here are my test results:Using curl:Hello, this is running from flasK!Using a browser:
<PastedGraphic-1.png>
I just rebooted my server and now the 4th virtual host is not even working with curl. Are there any out who have this desired configuration working?I relatively confident the python3.6 and the mod_wsgi modules are correctly installed and some configuration settings are not correct.Any guidance or trouble-shooting steps would be greatly appreciated. I’m happy to provide any kind of details required to get this working.TIA,—Rajeev
WSGIPythonHome "/usr"
3) FlaskApp.confcat /etc/apache2/sites-available/FlaskApp.conf<VirtualHost *:83>ServerName flaskapp.comServerAdmin ad...@flaskapp.comWSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi<Directory /var/www/FlaskApp/FlaskApp/>
Order allow,denyAllow from all
</Directory>ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
WSGIPythonHome "/usr"
3) FlaskApp.confcat /etc/apache2/sites-available/FlaskApp.conf<VirtualHost *:83>ServerName flaskapp.comServerAdmin ad...@flaskapp.comWSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi<Directory /var/www/FlaskApp/FlaskApp/>
Order allow,denyAllow from all
</Directory>ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
On Jun 23, 2018, at 4:42 PM, Graham Dumpleton <graham.d...@gmail.com> wrote:Run the curl on the same host and use:
Try doing a complete 'stop' and 'start' of Apache, not just a 'reload’.
BTW, you don't need the CustomLog directive either since would be same as main Apache one.
Possibly because for the other ports you opened up the firewall on the host so they can be accessed from outside, but you didn't do that for port 83.