Install Pyramid on Ubuntu 12.04 LTS in the Rackspace Cloud

Check the Installed Python Version

python --version

You should see the following output:

Python 2.7.3

Install Prerequisites

apt-get install python-setuptools python-pip python-virtualenv virtualenvwrapper

Install Prerequisites for Pyramid Speedups

apt-get install gcc cpp libc6-dev python2.7-dev

Install nginx

apt-get install nginx nginx-full nginx-common

Create a wwwuser that waitress (the web server) will run as

useradd wwwuser -d /home/wwwuser -k /etc/skel -m -s /bin/bash -U

Setup the Virtual Environment

mkdir -p /var/www/delixus.com
mkdir /var/www/environments
cd /var
chown -R wwwuser:wwwuser www

We are now going to change users to wwwuser user.

su - wwwuser
cd /var/www/environments
virtualenv env_delixus

Install Pyramid

You must perform the following steps as the wwwuser user.

cd /var/www/environments/env_delixus
source bin/activate

You should see the environment name as the prefix in the command prompt, such as:

(env_delixus)wwwuser@ws2:

easy_install Pyramid
pip install waitress

Checkout the Pyramid Project

cd /var/www/delixus.com

Change the SVN checkout command to something that matches your server. If you use git, then change appropriately.

svn checkout https://repo.company.com/source/delixus/tags/1.0 .

Install the delixus.com Pyramid project

cd /var/www/delixus.com/delixus
vi production.ini

Under [app:main], add a [server:main] configuration as follows:


# http://docs.pylonsproject.org/projects/waitress/en/latest/arguments.html
[server:main]
use = egg:waitress#main
host = 127.0.0.1
port = %(http_port)s
# default # of threads = 4
threads = 8
url_scheme = http

I don’t think you need to install the development version of the site, but it seems to be the only way that I get everything to work while debugging…go figure.

python setup.py develop
pserve development.ini

Then open the site in a text-based web browser.

links http://localhost:6543

You should be able to view your site at this point.

Now, let’s install the production version of the site.

python setup.py install

Start Waitress

First we’re going to start and test waitress, then we’ll start it as a deamon.

pserve production.ini http_port=5000
links http://localhost:5000

Again, you should be able to view your site.

pserve production.ini start --daemon --pid-file=/var/www/5000.pid \
--log-file=/var/www/5000.log --monitor-restart http_port=5000
pserve production.ini start --daemon --pid-file=/var/www/5001.pid \
--log-file=/var/www/5001.log --monitor-restart http_port=5001

Check the waitress process.

ps -ef | grep pserve

You should see the pserve process running.

Configure nginx as a Proxy for Waitress

The following steps must be performed as root.

cd /etc/nginx/sites-available
vi delixus

Paste the following into the delixus.conf file.


upstream delixus-site {
    server 127.0.0.1:5000;
    server 127.0.0.1:5001;
}

server {
    listen 80;
    server_name  localhost www.delixus.com delixus.com;

    access_log  /var/log/nginx/delixus.com-access.log;

    location / {
        proxy_set_header        Host $host;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        X-Forwarded-Proto $scheme;

        client_max_body_size    10m;
        client_body_buffer_size 128k;
        proxy_connect_timeout   60s;
        proxy_send_timeout      90s;
        proxy_read_timeout      90s;
        proxy_buffering         off;
        proxy_temp_file_write_size 64k;
        proxy_pass http://delixus-site;
        proxy_redirect          off;
    }

    location /static {
        root            /var/www/delixus.com/delixus/delixus;
        expires         30d;
        add_header      Cache-Control public;
        access_log      off;
    }
}

rm /etc/nginx/sites-enabled/default
ln -s /etc/nginx/sites-available/delixus /etc/nginx/sites-enabled/delixus
service nginx stop
service nginx start

A good next step at this point is to setup Supervisor to control pserve/waitress.

Advertisements

Install MySQL 5.5 on Ubuntu 10.04 LTS running in the Rackspace Cloud

Update April 23, 2012
I added new instructions for adding the MySQL libs to the loader path. Failure to add the libs to the loader path will cause errors when you try to run/build programs that depend on MySQL, such as installing the MySQL driver for Pyramid (Python).

Update April 18, 2012
Thanks to Lampros for pointing out that WordPress was converting double dashes into single dashes “-“. I have updated the post so that double dashes are displayed correctly.

The following are installation notes for MySQL 5.5 on Ubuntu 10.04 LTS running on the Rackspace cloud.

Download MySQL

Download the MySQL package from http://www.mysql.com in the ~/Downloads directory.

Download the following package from http://www.mysql.com/downloads/mysql/#downloads by selecting Debian Linux from the Select Platform drop-down list:

mysql-5.5.22-debian6.0-x86_64.deb

Installation Prerequisities

After the download is complete, open a terminal and execute the following commands:

Note:
libpthread-stubs0 libpthread-stubs0-dev coreutils are really not required, but I installed them as I was working through another issue.

apt-get install build-essential cmake libncurses5-dev libaio-dev bison libpthread-stubs0 libpthread-stubs0-dev coreutils

Setup the MySQL User and Group

groupadd mysql

useradd -r -g mysql mysql

Install MySQL

cd ~/Downloads

dpkg -i mysql-5.5.22-debian6.0-x86_64.deb

Note:

MySQL is now installed into the following directory:

/opt/mysql/server-5.5

cd /opt
chown root:root mysql
cd mysql
chown root:root server-5.5
cd server-5.5
chown -R mysql:mysql ./*
./scripts/mysql_install_db --user=mysql
chown mysql:mysql ./*
cd lib
chown -h mysql libmysqlclient.so libmysqlclient.so.18 libmysqlclient_r.a libmysqlclient_r.so libmysqlclient_r.so.18 libmysqlclient_r.so.18.0.0
cd ../support-files/

Note:
Decide which of the configuration files meets your needs, then copy it to /etc.

cp my-medium.cnf /etc/my.cnf
cp mysql.server /etc/init.d/mysql

Add MySQL to PATH

vi /etc/environment

Add the following to the end of the path:

/opt/mysql/server-5.5/bin

Example:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/mysql/server-5.5/bin"

source /etc/environment

Start the MySQL Server

/etc/init.d/mysql start

Set the MySQL Server to Start on Boot

update-rc.d mysql defaults

Create a root Password and Secure the Server

The following is the most basic and minimal security, but the steps below are required for a production server.

/opt/mysql/server-5.5/bin/mysql_secure_installation

Check the security settings:

mysql -u root -p
mysql> use mysql;
mysql> SELECT User, Host, Password FROM mysql.user;

Note:
None of the password fields should be blank.

Add the MySQL Libs to the Loader Path

We now need to update our loader path to include the MySQL libs. This is important for any future work we do that depends on the MySQL libraries, such as installing a MySQL driver for Pyramid.

cd /etc/ld.so.conf.d
vi mysql.conf

Paste in the following:

# MySQL 5.5 Libraries
/opt/mysql/server-5.5/lib

ldconfig

Post installation checks

mysqladmin version -u root -p
mysqladmin variables -u root -p

Create an Ubuntu 10.04 LTS in the Rackspace Cloud

The following are instructions for creating an Ubuntu 10.04 (LTS) server instance in the Rackspace cloud.

  1. Login to your CloudControl Panel account.
  2. In the left pane, click Hosting, then click Cloud Servers.
  3. Click Add Server.
  4. Click Select next to Ubuntu 10.04 LTS (Lucid).
  5. Enter a Server Name.
  6. Select a Server Size.
  7. Click Create Server.