This document describes the procedure for installing Apache + Python + Pyramid in the Ubuntu environment.
The following software is used to build this environment.
software | version |
---|---|
Ubuntu | 12.04 LTS |
Apache | 2.2.22 |
Python(System) | 2.7.3 (Ubuntu 12.What is installed by default in 04) |
Python(for virtualenv) | 2.7.6 |
VirtualEnv | 1.7.1.2 |
Pythonz | - |
Pyramid | 1.4.5 |
This time, we built the environment on AWS. The AMI used at that time is "Ubuntu Server 12.04.3 LTS --ami-6aad335a (64-bit)".
Also, make the following preparations.
→ Refer to the following for the procedure for creating a pyramid user. (Run as root user.)
$ sudo adduser pyramid #Enter any password. Press Enter for all other items.
$ sudo gpasswd -a pyramid sudo
$ sudo cp -r /home/ubuntu/.ssh /home/pyramid
$ sudo chown -R pyramid:pyramid /home/pyramid/.ssh
→ In this explanation, we will use an application called "sampleapp". The procedure for creating a "sample app" is as follows. (When creating a "sample app", please follow the steps up to (14) below.)
$ cd /home/pyramid
$ pcreate -s starter sampleapp
$ cd sampleapp
$ python setup.py install
All steps from here should be performed by the pyramid user.
(1) Update the package list of the package management system (APT).
$ sudo apt-get -y update
(2) Upgrade the installed package.
$ sudo apt-get -y upgrade
(3) Install build-essential and curl.
$ sudo apt-get -y install build-essential curl
(4) Install Python related packages.
$ sudo apt-get -y install python-dev python-setuptools python-pip python-virtualenv
(5) Install the library required when building with Pythonz.
$ sudo apt-get -y install libncurses-dev libreadline6-dev libbz2-dev liblzma-dev libsqlite3-dev libgbm-dev
(6) Install Apache2.
$ sudo apt-get -y install apache2
(7) Install mod_wsgi.
$ sudo apt-get -y install libapache2-mod-wsgi
(8) Install Pythonz.
$ curl -kL https://raw.github.com/saghul/pythonz/master/pythonz-install | bash
(9) Add the following contents to /home/pyramid/.bashrc.
[[ -s $HOME/.pythonz/etc/bashrc ]] && source $HOME/.pythonz/etc/bashrc
(10) Apply the contents of .bashrc.
$ source /home/pyramid/.bashrc
(11) Install Python 2.7.6 using Pythonz.
$ pythonz install 2.7.6
(12) Use Pythonz and Virtualenv to create a Python environment for use with Pyramid. *) This time, the name of the Python environment to be created is "env".
$ mkdir /home/pyramid/.virtualenv
$ cd /home/pyramid/.virtualenv
$ virtualenv -p /home/pyramid/.pythonz/pythons/CPython-2.7.6/bin/python --no-site-packages env
(13) Enable the env environment created above.
$ source /home/pyramid/.virtualenv/env/bin/activate
(14) Install Pyramid. This time, to install the version 1.4.5, execute the following command. *) To install the latest version of pyramid, please execute "pip install pyramid".
$ pip install pyramid==1.4.5
(15) Create a pyramid.wsgi file directly under the sample app.
$ cd /home/pyramid/sampleapp
$ vi pyramid.wsgi
(16) Add the following contents to the pyramid.wsgi file. *) This time, it is described assuming that it will operate in a production environment. For a development environment, production.ini will be development.ini.
from pyramid.paster import get_app
application = get_app(
'/home/pyramid/sampleapp/production.ini', 'main')
(17) Change the permissions of the pyramid.wsgi file to 755.
$ sudo chmod 755 /home/pyramid/sampleapp/pyramid.wsgi
(18) Create an Apache configuration file for Pyramid.
$ sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/pyramid
$ sudo vi /etc/apache2/sites-available/pyramid
(19) Open the created configuration file with vi and change it to the following contents.
<VirtualHost *:80>
DocumentRoot /home/pyramid/sampleapp
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
WSGIDaemonProcess pyramid user=www-data group=www-data threads=4 \
python-path=/home/pyramid/.virtualenv/env/lib/python2.7/site-packages
WSGIScriptAlias /sampleapp /home/pyramid/sampleapp/pyramid.wsgi
<Directory /home/pyramid/sampleapp/>
WSGIProcessGroup pyramid
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
(20) Enable the Pyramid site and disable the default site.
$ sudo a2ensite pyramid
$ sudo a2dissite default
(21) Restart Apache.
$ sudo /etc/init.d/apache2 restart
(22) Access "http: // [ipaddress] / sampleapp" with a browser and check that the Pyramid page is displayed.
Recommended Posts