"OSError: [Errno 88] Socket operation on non-socket" by flipflop
I've managed to run your example, but there are some tweaking involved to make it work.
You might need to change paths on your system, because from your logs it seems that you're using system that runs python2.6
and older apache
version which still uses httpd
file.
If it is possible I would advise you to upgrade your environment.
Here is a step-by-step working solution:
1.Install virtualenvwrapper
:
sudo -EH pip2 install virtualenvwrapper
2.Activte it:
source /usr/local/bin/virtualenvwrapper.sh
3.Create virtual env:
mkvirtualenv minimal
4.Install flask
and flup
:
pip install -U flask flup
flipflop
is not working for me, but as it's README states
This module is a simplified fork of flup, written by Allan Saddi. It only has the FastCGI part of the original module.
so you can safely use it.
5.Install apache2
:
sudo apt-get install apache2
6.Install libapache2-mod-fastcgi
:
sudo apt-get install libapache2-mod-fastcgi
7.Create /var/www/minimal/run.py
:
from flask import Flaskapp = Flask(__name__)@app.route('/')def hello_world(): return 'hello, world'
8.Create /var/www/minimal/minimal.fcgi
:
#!/usr/bin/pythonimport sysimport logginglogging.basicConfig(stream=sys.stderr)activate_this = '/home/some_user/.virtualenvs/minimal/bin/activate_this.py'execfile(activate_this, dict(__file__=activate_this))sys.path.insert(0,"/var/www/minimal/")from flup.server.fcgi import WSGIServerfrom run import appif __name__ == '__main__': WSGIServer(app).run()
9.Make minimal.fcgi
executable:
sudo chmod +x minimal.fcgi
10.Create minimal.conf
file (in /etc/apache2/sites-available
on my server):
FastCgiServer /var/www/minimal/minimal.fcgi -idle-timeout 300 -processes 5<VirtualHost *:80> ServerName YOUR_IP_ADDRESS DocumentRoot /var/www/minimal/ AddHandler fastcgi-script fcgi ScriptAlias / /var/www/minimal/minimal.fcgi/ <Location /> SetHandler fastcgi-script </Location></VirtualHost>
11.Enable new site:
sudo a2ensite minimal.conf
12.Change /var/www/
ownership to www-data
user:
sudo chown -R www-data:www-data /var/www/
13.Restart apache2
:
sudo /etc/init.d/apache2 restart
And voila! :)
If you visit your server address you should see hello, world
in your browser:
Also when restarting apache
you can view FastCGI
starting in apache's error.log
:
[Thu Aug 24 16:33:09.354544 2017] [mpm_event:notice] [pid 17375:tid 139752788969344] AH00491: caught SIGTERM, shutting down[Thu Aug 24 16:33:10.414829 2017] [mpm_event:notice] [pid 17548:tid 139700962228096] AH00489: Apache/2.4.18 (Ubuntu) mod_fastcgi/mod_fastcgi-SNAP-0910052141 configured -- resuming normal operations[Thu Aug 24 16:33:10.415033 2017] [core:notice] [pid 17548:tid 139700962228096] AH00094: Command line: '/usr/sbin/apache2'[Thu Aug 24 16:33:10.415651 2017] [:notice] [pid 17551:tid 139700962228096] FastCGI: process manager initialized (pid 17551)[Thu Aug 24 16:33:10.416135 2017] [:warn] [pid 17551:tid 139700962228096] FastCGI: server "/var/www/minimal/minimal.fcgi" started (pid 17556)[Thu Aug 24 16:33:11.416571 2017] [:warn] [pid 17551:tid 139700962228096] FastCGI: server "/var/www/minimal/minimal.fcgi" started (pid 17618)[Thu Aug 24 16:33:12.422058 2017] [:warn] [pid 17551:tid 139700962228096] FastCGI: server "/var/www/minimal/minimal.fcgi" started (pid 17643)[Thu Aug 24 16:33:13.422763 2017] [:warn] [pid 17551:tid 139700962228096] FastCGI: server "/var/www/minimal/minimal.fcgi" started (pid 17651)[Thu Aug 24 16:33:14.423536 2017] [:warn] [pid 17551:tid 139700962228096] FastCGI: server "/var/www/minimal/minimal.fcgi" started (pid 17659)
In general you should use mod_fastcgi
and configuration simillar to:
<VirtualHost *:8091> ServerName helloworld.local DocumentRoot /home/fe/work/flipflop FastCgiServer /home/fe/work/flipflop/run.py ScriptAlias / /home/fe/work/flipflop/run.py <Location /> Options none </Location></VirtualHost>
So it will make run your script as FastCgi, but I'm not familiar with flipflop
and can't make it works.
But if you are not limited to flipflop
you could use uwsgi
to run your application, mod_wsgi
to run it with Apache
(read more details in Flask documentation) or use Flask-Script
runserver
command to run your application in debug server (see example in Flask-Script documentation