works ubuntu apache passenger

Upload: kris6696

Post on 29-May-2018

229 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 Works Ubuntu Apache Passenger

    1/8

    Rails:Apache-Passenger-MySQL

    for Ubuntu 10.04.1 Server i386

    Install Prerequisites:

    sudo apt-get update && sudo apt-get upgrade -y

    (optional) Annex A: Set a static IP address in Ubuntu

    (optional) Annex B: Optional SSH config for new Ubuntu install

    sudo apt-get install build-essential ruby-full libmagickcore-dev imagemagick libxml2-

    dev libxslt1-dev git-core apache2 apache2-prefork-dev libapr1-dev -y

    Install MySQL:

    sudo apt-get install mysql-server libmysqlclient-dev

    Install the latest RubyGems from source:

    wget http://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgz

    tar -xzf rubygems-1.3.7.tgz

    sudo ruby rubygems-1.3.7/setup.rb

    rm -R rubygems*

    Reliable way of making a symlink for rubygems 1.3.7:

    sudo apt-get install rubygems -y

    gem -v

    Configure RubyGems to only install the gem and no documentation:

    nano ~/.gemrcAdd these two lines:

    install: --no-ri --no-rdoc

    update: --no-ri --no-rdoc

    http://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgzhttp://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgz
  • 8/8/2019 Works Ubuntu Apache Passenger

    2/8

    Install gems for your Rails server:

    sudo gem install rails -v=2.3.8

    sudo gem install will_paginate paperclip mysql passenger

    Set the default environment to production globally:

    sudo nano /etc/environment

    And add the following line to it:

    export RAILS_ENV=production

    Install Phusion Passenger:

    sudo passenger-install-apache2-module

    (use default options, 1)

    Configure Apache to load the Passenger module:

    Find the apache config file path: apache2ctl -V | grep SERVER_CONFIG_FILE

    sudo nano /etc/apache2/apache2.conf

    At the bottom of Apaches config file, tell it to load the Passenger module you justinstalled by copy/pasting output from the Phusion Passenger installer that lookedsomething like this (varies depending on ruby install and passenger install):

    ------------------------------------------

    LoadModule passenger_module /opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.15

    /ext/apache2/mod_passenger.so

    PassengerRoot /opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.11

    PassengerRuby /opt/local/bin/ruby

    ------------------------------------------

    In addition, add the following to the apache.conf file:

    ------------------------------------------

    # Speeds up spawn time tremendously -- if your app is compatible. RMagick seems to be incompatible

    with smart spawning.

    RailsSpawnMethod smart

    # Just in case you're leaking memory, restart a listener

    # after processing 5000 requests

  • 8/8/2019 Works Ubuntu Apache Passenger

    3/8

    PassengerMaxRequests 5000

    # only check for restart.txt et al up to once every 5 seconds, instead of once per processed request

    PassengerStatThrottleRate 5

    # Keep the spawners alive, which speeds up spawning a new Application listener after a period of

    inactivity at the expense of memory.RailsAppSpawnerIdleTime 0

    # Additionally keep a copy of the Rails framework in memory. If you're using multiple apps on the same

    version of Rails, this will speed up the creation of new RailsAppSpawners. This isn't necessary if you're

    only running one or 2 applications, or if your applications use different versions of Rails.

    RailsFrameworkSpawnerIdleTime 0

    # Keep the application instances alive longer. Default is 300 (seconds)

    PassengerPoolIdleTime 1000

    -----------------------------------------------------

    Create your Apache virtual host:

    cd /etc/apache2

    ls (Take notice of the general layout of Apaches folders.)

    cd sites-available

    sudo nano MyWebsiteName

    Content Example:

    ------------------------------------------

    ServerName cfrghq.forces.caDocumentRoot /home/ubuntu/rails-sites/software/current/public/

    Order allow,denyAllow from all

    ------------------------------------------

    Restart Apache:

    sudo apache2ctl restart

    Deploy the application:

    On your development machine, well assume you have the following:

    git, Capistrano, ssh client, and a http://github.com/ account.

  • 8/8/2019 Works Ubuntu Apache Passenger

    4/8

    Git:

    Before we get started with Git, lets make sure your development machine can access github. If

    you havent created an account yet, what are you waiting for? :)

    Once you have logged in to github, add your development machines public key to your account

    settings. Github help section can guide you through this.

    In the directory of your rails application, initialize an empty git repository on the local machine:

    git init

    This creates a series of files for git under the hidden folder .git within your applications folder.

    If you want to tell git to exclude any of your applications files from being seen by git (for

    example; large files, databases), you can add them now by creating a file hidden file .gitignore

    in the root of your applications directory.

    Add the files in your applications directory to Gits list of files:

    git add .

    Commit these files to your first entry with Git:

    git commit -m my first commits message, rails is fun! :D

    Tell git where your repository is. In this case were using a github account:

    git remote add origin [email protected]:krisf/Software-Manager.git

    Push all the files from your first commit to your git repositorys master branch:

    git push origin master

    You now have a repository setup on Github!

    Now you need to add your servers public key to github so it can access the repository too:

    http://help.github.com/linux-key-setup/

    Ensure your application has a database in MySQL to deploy to:

    mailto:[email protected]://help.github.com/linux-key-setup/http://help.github.com/linux-key-setup/mailto:[email protected]://help.github.com/linux-key-setup/
  • 8/8/2019 Works Ubuntu Apache Passenger

    5/8

    mysql -u root -p> enter MySQL root password:

    > create database ApplicationsDatabaseProd;

    > exit

    Capistrano:

    In your applications directory, get Capistrano to create the files it requires (Capfile,

    config/deploy.rb). Capfile is just an initialization file for Capistrano. Your deploy.rb file contains

    the Capistrano settings.

    Edit deploy.rb and use the following as a template:

    Test Webserver performance with ApacheBench (ab):

    # ApacheBench: (concurrent requests: 50) (number of total requests : 2000) (url to your

    website). Use the following command:

    ab -c 50 -n 2000 (url to your website)

  • 8/8/2019 Works Ubuntu Apache Passenger

    6/8

    Annex A: Setting a static IP Address in Ubuntu

    sudo nano /etc/network/interfaces

    Content Example:

    ------------------------------------------

    auto eth0

    iface eth0 inet static

    address 192.168.0.100

    netmask 255.255.255.0

    network 192.168.0.0

    broadcast 192.168.0.255

    gateway 192.168.0.1

    ------------------------------------------

  • 8/8/2019 Works Ubuntu Apache Passenger

    7/8

    Annex B: Configuring SSH on a fresh Ubuntu install

    Install SSH:

    sudo apt-get install openssh-server openssh-client -y

    Create an SSH Alias for your server:

    sudo nano ~/.ssh/config

    Content Example:------------------------------------------

    Host MyServersAliasName

    Hostname 192.168.0.10

    User ubuntu

    ------------------------------------------

    Now you can use ssh MyServersAliasName to connect.

    Configure SSH:

    On the server:

    mkdir .ssh

    On your development machine:

    cd ~/.ssh && ls

  • 8/8/2019 Works Ubuntu Apache Passenger

    8/8

    If a public rsa key file exists (id_dsa.pub), copy it to the server so you can login without entering

    a password:

    scp ~/.ssh/id_dsa.pub MyServersAliasName:.ssh/authorized_keys

    If youre running on Amazon EC2, its like:

    scp -i cfrg.pem ~/.ssh/id_dsa.pub MyServersAliasName:.ssh/authorized_keys2