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


Ignore:
Timestamp:
10/07/15 13:19:44 (9 years ago)
Author:
Richard Bramley
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UoL LAMP HowTo Install 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== Difficulties
     6
     7This installations is made more difficult by 3 things:
     8
     91. Suse Linux does not have mod_wsgi in its repositories, so you're going to have to compile it.
     102. mod_wsgi seems picky about where it picks python apps and libraries from
     113. The LAMP servers don't put things where you'd expect them to be.
     124. Some other stuff that I don't quite understand
     13
     14== Requirements
     15
     16Before installation can start, the following packages will have to be installed by IT services:
     17
     18- libmysqlclient-dev
     19- python-dev
     20
     21== Start Services
     22
     23Start the Apache and MySQL and make sure that they are restarted when the server is rebooted.
     24
     25{{{
     26sudo /sbin/chkconfig uol.apache2 on
     27sudo /etc/init.d/uol.apache2 start
     28sudo /sbin/chkconfig uol.mysql on
     29sudo /etc/init.d/uol.mysql start
     30}}}
     31
     32== Proceduce
     33
     341. [[HowTo Compile mod_wsgi for LAMP servers]]
     352. Copy the Telomere application from the `git` repository into `/local/` directory.
     363. Install virtualenv:
     37
     38{{{
     39easy_install --install-dir=/local/python virtualenv
     40}}}
     41
     42    ''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.''
     434. Create a virtual environment in the telomere application directory.
     44
     45{{{
     46cd /local/telomere
     47/local/python/virtualenv --no-site-packages BASELINE
     48}}}
     49
     50    ''`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`.''
     51
     525. Activate the environment, install the required packages, then deactivate:
     53
     54{{{
     55source BASELINE/bin/activate
     56easy_install flask
     57easy_install flask-sqlalchemy
     58easy_install mysql-python
     59easy_install flask-login
     60easy_install python-ldap
     61easy_install flask-wtf
     62easy_install WTForms-Components
     63easy_install openpyxl
     64deactivate
     65}}}
     66
     676. Load the WSGI module into Apache, by editing the file `/local/apache2/etc/loadmodule.conf` by adding this line at the end.
     68
     69{{{
     70LoadModule wsgi_module /local/apache2/etc/mod_wsgi.so
     71}}}
     72
     73    ''This presumes that you've copied the compiled `mod_wsgi.so` file into the `/local/apache2/etc/` directory.''
     74
     757. Add the WSGI config to the Apache config file `/local/apache2/etc/httpd.conf`:
     76
     77{{{
     78<Directory /local/telomere>
     79    WSGIProcessGroup telomere
     80    WSGIApplicationGroup %{GLOBAL}
     81    Order deny,allow
     82    Allow from all
     83</Directory>
     84
     85WSGIDaemonProcess telomere user=wwwrun threads=5 python-path=/local/telomere/BASELINE/lib/python2.6/site-packages:/local/python:/usr/lib64/python2.6/site-packages:/usr/share/doc/packages/ home=/local/telomere/
     86WSGIScriptAlias / /local/telomere/app/telomere.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. Pray.
     98
     99== Other Possible Stuff
     100
     1011. You may need to give `wwwrun` extra permissions to the `/local/telomere` directory.
     1022. You might need to pray a bit more.
     103
     104== Permission to Upload Directory
     105
     1061. In order to upload spreadsheets, you need to create an upload directory, for example `/local/telomere/uploads`.
     1072. You then need to point to this in the settings.py file `SPREADSHEET_UPLOAD_DIRECTORY = '/local/telomere/uploads'`
     1083. Finally, you need to give `wwwrun` permission to read and write to the directory.
     109
     110{{{
     111setfacl -m u:wwwrun:rwx /local/telomere/uploads/
     112setfacl -m d:u:wwwrun:rwx /local/telomere/uploads/
     113}}}
     114
     115[[BackLinks]]