Changes between Initial Version and Version 1 of UoL LAMP HowTo Install Legacy Python Flask Applications


Ignore:
Timestamp:
10/10/18 14:56:09 (6 years ago)
Author:
Richard Bramley
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UoL LAMP HowTo Install Legacy Python Flask Applications

    v1 v1  
     1= UoL LAMP HowTo Install Python Flask Applications
     2
     3Tags: [[HowTo]] [[Install]] [[Pain in the proverbial]] [[UoL LAMP Server]]
     4
     5== Python 2
     6
     7=== Difficulties
     8
     9This installations is made more difficult by 3 things:
     10
     111. Suse Linux does not have mod_wsgi in its repositories, so you're going to have to compile it.
     122. mod_wsgi seems picky about where it picks python apps and libraries from
     133. The LAMP servers don't put things where you'd expect them to be.
     144. Some other stuff that I don't quite understand
     15
     16=== Requirements
     17
     18Before installation can start, the following packages will have to be installed by IT services:
     19
     20- libmysqlclient-dev
     21- python-dev
     22
     23=== Start Services
     24
     25Start the Apache and MySQL and make sure that they are restarted when the server is rebooted.
     26
     27{{{
     28sudo /sbin/chkconfig uol.apache2 on
     29sudo /etc/init.d/uol.apache2 start
     30sudo /sbin/chkconfig uol.mysql on
     31sudo /etc/init.d/uol.mysql start
     32}}}
     33
     34=== Proceduce
     35
     361. Install {{{mod_wsgi.so}}} into the directory {{{/local/apache2/etc/}}}
     37 1. Compile `mod_wsgi`. See: [[HowTo Compile mod_wsgi for LAMP servers]]
     38 2. Copy `mod_wsgi.so` from the directory {{{/local/apache2/etc/}}} of an existing UoL LAMP python Flask application.
     392. Clone the application from the `git` repository into `/local/` directory.
     403. Install virtualenv:
     41 a. First switch to python 2.7 by running the command `source /opt/python2/etc/python-env.sh`
     42
     43{{{
     44easy_install --install-dir=/local/python virtualenv
     45}}}
     46
     47    ''For some reason that I can't work out (point 4. above), it would only pick up some of the python libraries from a virtual env and not when they were installed in `/local/python/`.  Maybe this was because of the order that I installed things, but I couldn't get it to work without the virtual environment.''
     484. Create a virtual environment in the application directory.
     49
     50{{{
     51cd /local/{application directory}
     52/local/python/virtualenv --no-site-packages BASELINE
     53}}}
     54
     55    ''`BASELINE` is the name of the virtual environment.  It could be called anything, but it's called that!  Also note that you need to use the full path to the `virtualenv` utility, since `/local/python` isn't in `$PATH`.''
     56
     575. Activate the environment, install the required packages, then deactivate.  This example shows some common requirements:
     58
     59{{{
     60source BASELINE/bin/activate
     61easy_install flask
     62easy_install flask-sqlalchemy
     63easy_install mysql-python
     64easy_install flask-wtf
     65easy_install WTForms-Components
     66deactivate
     67}}}
     68
     696. Load the WSGI module into Apache, by editing the file `/local/apache2/etc/loadmodule.conf` by adding this line at the end.
     70
     71{{{
     72LoadModule wsgi_module /local/apache2/etc/mod_wsgi.so
     73}}}
     74
     757. Add the WSGI config to the Apache config file `/local/apache2/etc/httpd.conf`:
     76
     77{{{
     78<Directory /local/{application directory}>
     79    WSGIProcessGroup {application name}
     80    WSGIApplicationGroup %{GLOBAL}
     81    Order deny,allow
     82    Allow from all
     83</Directory>
     84
     85WSGIDaemonProcess {application name} user=wwwrun threads=5 python-path=/local/{application directory}/BASELINE/lib/python2.6/site-packages:/local/python:/usr/lib64/python2.6/site-packages:/usr/share/doc/packages/ home=/local/{application directory}/
     86WSGIScriptAlias / /local/{application directory}/{path to *.wsgi}
     87}}}
     88
     89    ''The two hard won things here are the values for the `python-path` and `home` arguments.  The `python-path` must contain every directory where python libraries are installed, including a sub-directory of the virtualenv directory you created earlier.  The `home` must point to your application directory, or you won't be able to pick up your own modules.''
     90
     918. Restart apache:
     92
     93{{{
     94sudo /etc/init.d/uol.apache2 restart
     95}}}
     96
     979. Create any databases that are required and given the appropriate user permissions.
     98
     9910. Update the application settings in {{{/local/{application directory} }}}
     100
     10110. Pray.
     102
     103== Other Possible Stuff (**Not required last time used!**)
     104
     1051. You may need to give `wwwrun` extra permissions to the `/local/{application directory}` directory.
     1062. You might need to pray a bit more.
     107
     108{{{
     109setfacl -m u:wwwrun:rwx /local/{application directory}
     110setfacl -m d:u:wwwrun:rwx /local/telomere/{application directory}
     111}}}
     112
     113=== Gotchas
     114
     115- [[Python Flask Gotchas Import Database Module Fails]]
     116
     117[[BackLinks]]