Using Apache Server with Turbo Gears - jordy33/turbogears_tutorial GitHub Wiki
- Install enchant:
sudo apt-get install libenchant1c2a
sudo apt-get install myspell-es
pip install pyenchant
python
>>> import enchant
>>> d=enchant.Dict("es")
>>> d.check("Hola")
True
>>> d.check("Hello")
False
-
Install Apache2 with user jorge
https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-16-04 -
In the server install mod WSGI
Python 3
sudo apt-get install libapache2-mod-wsgi-py3 sudo apt install apache2-devCompile mod_wsgi
sudo apt-get install libtool cd /tmp wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.6.4.tar.gz tar xvzf 4.6.4.tar.gz cd mod_wsgi-4.6.4/ ./configure make sudo cp /tmp/mod_wsgi-4.6.4/src/server/.libs/mod_wsgi.so /usr/lib/apache2/modules/. sudo chmod 644 /usr/lib/apache2/modules/mod_wsgi.so -
Create a virtualenvironment with the specific TurboGears version your application depends on installed
sudo -i virtualenv -p python3 /var/tg2env source /var/tg2env/bin/activate pip install tg.devtools -
Activate the virtualenvironment
source /var/tg2env/bin/activate #virtualenv now activated (tg2env)$ -
Install your TurboGears application.
cd /var/www/python.mercury python setup.py develop -
Within the application director, create a script named app.wsgi. Give it these contents:
import os APP_CONFIG = "/var/www/python.mercury/production.ini" #Setup logging import logging.config logging.config.fileConfig(APP_CONFIG) #Load the application from paste.deploy import loadapp application = loadapp('config:%s' % APP_CONFIG) -
Change permisions
sudo chown -R www-data:www-data /var/www sudo chmod go-rwx /var/www sudo chmod go+x /var/www sudo chgrp -R www-data /var/www sudo chmod -R go-rwx /var/www sudo chmod -R g+rx /var/www sudo chmod -R g+rwx /var/www #### IMPORTANT!! sudo chgrp -R www-data /home/jorge/.python-eggs sudo chown www-data:www-data /home/jorge/.python-eggs -
Edit your Apache configuration and add some stuff. Disable current service:
a2dissite 000-default service apache2 reload cd /etc/apache2 vim ports.conf # Change to port 8090 /etc/apache2/sites-available sudo vim cygnus.conf -
Insert the following lines:
<VirtualHost *:8090> ServerName cygnus WSGIProcessGroup cygnus WSGIDaemonProcess cygnus user=www-data group=www-data threads=4 python-path=/var/tg2env/lib/python3.5/sitepackages WSGIScriptAlias / /var/www/python.cygnus/app.wsgi #Serve static files directly without TurboGears Alias /images /var/www/python.cygnus/pythoncygnus/public/images Alias /css /var/www/python.cygnus/pythoncygnus/public/css Alias /js /var/www/python.cygnus/pythoncygnus/public/js ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> WSGIPythonHome /var/tg2env WSGIPythonPath /var/tg2env/lib/python3.5 -
Start the Service: Enable WSGI
a2enmod wsgiTo enable site
a2ensite cygnusTo activate the new configuration, you need to run:
service apache2 reload(After this will appear in "sites-enabled")
sudo service apache2 restart -
Checking service:
apache2ctl configtest tail -10 /var/log/apache2/error.log sudo vim /home/terowsgi/grouped/python.cygnus sudo vim /etc/apache2/sites-available/cygnus.conf source /home/terowsgi/grouped/tg2env/bin/activate sudo vim /etc/apache2/sites-available/cygnus.conf sudo vim /var/www/cygnus/app.wsgi sudo service apache2 reload sudo a2ensite cygnus sudo a2dissite cygnus sudo service apache2 start sudo vim /home/terowsgi/grouped/python.cygnus/production.ini
conda create -n tgenv python=3.6
source activate tg2env
source deactivate
sudo apt-get install gcc
sudo apt-get install libmysqlclient-dev
pip install tg.devtools mysqlclient
$ sudo apt-get update
$ sudo apt-get -y install apache2 libapache2-mod-wsgi-py3
$ sudo a2enmod wsgi
$ sudo service apache2 restart
$ sudo a2dissite 000-default
$ sudo service apache2 restart
WSGI
First, add yourself into the group www-data
usermod -a -G www-data (your username)
Then:
chgrp www-data /home/myuser/folderA
chmod g+rwxs /home/myuser/folderA
Should do the trick unless the permissions on your /home/myuser do not permit other users access.
Another way is to change the username directly in apache config, this is if it's your local machine and you save images from somewhere else that would crush any permissions made on the folder. Also to do if you have only 1 user and don't care about www-data!
$ sudo vi /etc/apache2/apache2.conf
Find User and Group and put yours
User <Your User>
Group <Your Group>
$ sudo service apache2 restart
sudo chgrp www-data /home/ubuntu/public_wsgi/
sudo chmod g+rwxs /home/ubuntu/public_wsgi/```