Environment construction procedure: Ubuntu + Apache2 + Python + Pyramid

Introduction

This document describes the procedure for installing Apache + Python + Pyramid in the Ubuntu environment.

Prerequisites

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

procedure

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

Environment construction procedure: Ubuntu + Apache2 + Python + Pyramid
Anaconda3 python environment construction procedure
OpenCV3 & Python3 environment construction on Ubuntu
Python environment construction
python environment construction
Python --Environment construction
Python environment construction
python environment construction
[Ubuntu 18.04] Python environment construction with pyenv + pipenv
Python (anaconda) development environment construction procedure (SpringToolsSuites) _2020.4
python windows environment construction
homebrew python environment construction
Python development environment construction
python2.7 development environment construction
Mac environment construction Python
Python environment construction @ Win7
VS Code + Azure Functions + Python environment construction procedure
Python 3.x environment construction by Pyenv (CentOS, Ubuntu)
Python + Anaconda + Pycharm environment construction
Python environment construction (Windows10 + Emacs)
CI environment construction ~ Python edition ~
Build python3 environment with ubuntu 16.04
Python environment construction For Mac
Google App Engine / Python development environment construction procedure (late 2014)
Python3 environment construction (for beginners)
Python environment construction and TensorFlow
Python environment construction under Windows7 environment
Procedure to exe python file from Ubunts environment construction
[MEMO] [Development environment construction] Python
Ubuntu14.04 + GPU + TensorFlow environment construction
Environment construction of python2 & 3 (OSX)
Python environment construction procedure memo using Docker on Windows10 Home
Environment construction of python and opencv
Python environment construction memo on Windows 10
Get started with Python! ~ ① Environment construction ~
Linux Web server construction (Ubuntu & Apache)
Prepare Python development environment on Ubuntu
Python + Unity Reinforcement learning environment construction
Building a Python environment on Ubuntu
[Django] Memorandum of environment construction procedure
I checked Mac Python environment construction
Python environment construction memo on Mac
Python environment construction (pyenv, anaconda, tensorflow)
[Python3] Development environment construction << Windows edition >>
Python development environment construction on macOS
Python environment construction (pyenv + poetry + pipx)
Environment construction of python3.8 on mac
Python3 environment construction with pyenv-virtualenv (CentOS 7.3)
From Ubuntu 20.04 introduction to environment construction
Python3 TensorFlow for Mac environment construction
Emacs Python development environment construction memo
Ubuntu Desktop 20.04 development environment construction memo
pytorch @ python3.8 environment construction with pipenv
Build Python 3.8 + Pipenv environment on Ubuntu 18.04
[docker] python3.5 + numpy + matplotlib environment construction
Environment construction of "Tello_Video" on Ubuntu
Python3.6 environment construction (using Win environment Anaconda)
[Pyenv] Building a python environment with ubuntu 16.04
Build Python3 and OpenCV environment on Ubuntu 18.04
Python virtual environment and packages on Ubuntu
[Python] Road to snake charmer (1) Environment construction