Changes between Version 12 and Version 13 of UoL LAMP HowTo Install Python Flask Applications


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

--

Legend:

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

    v12 v13  
    33Tags: [[HowTo]] [[Install]] [[Pain in the proverbial]] [[UoL LAMP Server]]
    44
    5 [[UoL LAMP HowTo Install Legacy Python Flask Applications]]
    65
    7 == Python 2
    8 
    9 === Difficulties
    10 
    11 This installations is made more difficult by 3 things:
    12 
    13 1. Suse Linux does not have mod_wsgi in its repositories, so you're going to have to compile it.
    14 2. mod_wsgi seems picky about where it picks python apps and libraries from
    15 3. The LAMP servers don't put things where you'd expect them to be.
    16 4. Some other stuff that I don't quite understand
    17 
    18 === Requirements
    19 
    20 Before installation can start, the following packages will have to be installed by IT services:
    21 
    22 - libmysqlclient-dev
    23 - python-dev
    24 
    25 === Start Services
    26 
    27 Start the Apache and MySQL and make sure that they are restarted when the server is rebooted.
    28 
    29 {{{
    30 sudo /sbin/chkconfig uol.apache2 on
    31 sudo /etc/init.d/uol.apache2 start
    32 sudo /sbin/chkconfig uol.mysql on
    33 sudo /etc/init.d/uol.mysql start
    34 }}}
    35 
    36 === Proceduce
    37 
    38 1. Install {{{mod_wsgi.so}}} into the directory {{{/local/apache2/etc/}}}
    39  1. Compile `mod_wsgi`. See: [[HowTo Compile mod_wsgi for LAMP servers]]
    40  2. Copy `mod_wsgi.so` from the directory {{{/local/apache2/etc/}}} of an existing UoL LAMP python Flask application.
    41 2. Clone the application from the `git` repository into `/local/` directory.
    42 3. Install virtualenv:
    43  a. First switch to python 2.7 by running the command `source /opt/python2/etc/python-env.sh`
    44 
    45 {{{
    46 easy_install --install-dir=/local/python virtualenv
    47 }}}
    48 
    49     ''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.''
    50 4. Create a virtual environment in the application directory.
    51 
    52 {{{
    53 cd /local/{application directory}
    54 /local/python/virtualenv --no-site-packages BASELINE
    55 }}}
    56 
    57     ''`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`.''
    58 
    59 5. Activate the environment, install the required packages, then deactivate.  This example shows some common requirements:
    60 
    61 {{{
    62 source BASELINE/bin/activate
    63 easy_install flask
    64 easy_install flask-sqlalchemy
    65 easy_install mysql-python
    66 easy_install flask-wtf
    67 easy_install WTForms-Components
    68 deactivate
    69 }}}
    70 
    71 6. Load the WSGI module into Apache, by editing the file `/local/apache2/etc/loadmodule.conf` by adding this line at the end.
    72 
    73 {{{
    74 LoadModule wsgi_module /local/apache2/etc/mod_wsgi.so
    75 }}}
    76 
    77 7. Add the WSGI config to the Apache config file `/local/apache2/etc/httpd.conf`:
    78 
    79 {{{
    80 <Directory /local/{application directory}>
    81     WSGIProcessGroup {application name}
    82     WSGIApplicationGroup %{GLOBAL}
    83     Order deny,allow
    84     Allow from all
    85 </Directory>
    86 
    87 WSGIDaemonProcess {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}/
    88 WSGIScriptAlias / /local/{application directory}/{path to *.wsgi}
    89 }}}
    90 
    91     ''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.''
    92 
    93 8. Restart apache:
    94 
    95 {{{
    96 sudo /etc/init.d/uol.apache2 restart
    97 }}}
    98 
    99 9. Create any databases that are required and given the appropriate user permissions.
    100 
    101 10. Update the application settings in {{{/local/{application directory} }}}
    102 
    103 10. Pray.
    104 
    105 == Other Possible Stuff (**Not required last time used!**)
    106 
    107 1. You may need to give `wwwrun` extra permissions to the `/local/{application directory}` directory.
    108 2. You might need to pray a bit more.
    109 
    110 {{{
    111 setfacl -m u:wwwrun:rwx /local/{application directory}
    112 setfacl -m d:u:wwwrun:rwx /local/telomere/{application directory}
    113 }}}
    114 
    115 === Gotchas
    116 
    117 - [[Python Flask Gotchas Import Database Module Fails]]
    118 
    119 
    120 
    121 == Python 3
     6This page is for python 3, for python 2 see [[UoL LAMP HowTo Install Legacy Python Flask Applications]]
    1227
    1238=== Create Environment