Works Ubuntu Apache Passenger

Download Works Ubuntu Apache Passenger

Post on 29-May-2018

216 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

<ul><li><p>8/8/2019 Works Ubuntu Apache Passenger</p><p> 1/8</p><p>Rails:Apache-Passenger-MySQL</p><p>for Ubuntu 10.04.1 Server i386</p><p>Install Prerequisites:</p><p> sudo apt-get update &amp;&amp; sudo apt-get upgrade -y</p><p> (optional) Annex A: Set a static IP address in Ubuntu</p><p> (optional) Annex B: Optional SSH config for new Ubuntu install</p><p> sudo apt-get install build-essential ruby-full libmagickcore-dev imagemagick libxml2-</p><p>dev libxslt1-dev git-core apache2 apache2-prefork-dev libapr1-dev -y</p><p>Install MySQL:</p><p> sudo apt-get install mysql-server libmysqlclient-dev</p><p>Install the latest RubyGems from source:</p><p> wget http://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgz</p><p> tar -xzf rubygems-1.3.7.tgz</p><p> sudo ruby rubygems-1.3.7/setup.rb</p><p> rm -R rubygems*</p><p>Reliable way of making a symlink for rubygems 1.3.7:</p><p> sudo apt-get install rubygems -y</p><p> gem -v</p><p>Configure RubyGems to only install the gem and no documentation:</p><p> nano ~/.gemrcAdd these two lines:</p><p> install: --no-ri --no-rdoc</p><p> update: --no-ri --no-rdoc</p>http://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgzhttp://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgz</li><li><p>8/8/2019 Works Ubuntu Apache Passenger</p><p> 2/8</p><p>Install gems for your Rails server:</p><p> sudo gem install rails -v=2.3.8</p><p> sudo gem install will_paginate paperclip mysql passenger</p><p>Set the default environment to production globally:</p><p> sudo nano /etc/environment</p><p> And add the following line to it:</p><p> export RAILS_ENV=production</p><p>Install Phusion Passenger:</p><p> sudo passenger-install-apache2-module</p><p> (use default options, 1)</p><p>Configure Apache to load the Passenger module:</p><p> Find the apache config file path: apache2ctl -V | grep SERVER_CONFIG_FILE</p><p> sudo nano /etc/apache2/apache2.conf</p><p>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):</p><p>------------------------------------------</p><p>LoadModule passenger_module /opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.15</p><p>/ext/apache2/mod_passenger.so</p><p>PassengerRoot /opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.11</p><p>PassengerRuby /opt/local/bin/ruby</p><p>------------------------------------------</p><p>In addition, add the following to the apache.conf file:</p><p>------------------------------------------</p><p># Speeds up spawn time tremendously -- if your app is compatible. RMagick seems to be incompatible</p><p>with smart spawning.</p><p>RailsSpawnMethod smart</p><p># Just in case you're leaking memory, restart a listener</p><p># after processing 5000 requests</p></li><li><p>8/8/2019 Works Ubuntu Apache Passenger</p><p> 3/8</p><p>PassengerMaxRequests 5000</p><p># only check for restart.txt et al up to once every 5 seconds, instead of once per processed request</p><p>PassengerStatThrottleRate 5</p><p># Keep the spawners alive, which speeds up spawning a new Application listener after a period of</p><p>inactivity at the expense of memory.RailsAppSpawnerIdleTime 0</p><p># Additionally keep a copy of the Rails framework in memory. If you're using multiple apps on the same</p><p>version of Rails, this will speed up the creation of new RailsAppSpawners. This isn't necessary if you're</p><p>only running one or 2 applications, or if your applications use different versions of Rails.</p><p>RailsFrameworkSpawnerIdleTime 0</p><p># Keep the application instances alive longer. Default is 300 (seconds)</p><p>PassengerPoolIdleTime 1000</p><p>-----------------------------------------------------</p><p>Create your Apache virtual host:</p><p> cd /etc/apache2</p><p> ls (Take notice of the general layout of Apaches folders.)</p><p> cd sites-available</p><p> sudo nano MyWebsiteName</p><p>Content Example:</p><p>------------------------------------------</p><p>ServerName cfrghq.forces.caDocumentRoot /home/ubuntu/rails-sites/software/current/public/</p><p>Order allow,denyAllow from all</p><p>------------------------------------------</p><p>Restart Apache:</p><p> sudo apache2ctl restart</p><p>Deploy the application:</p><p>On your development machine, well assume you have the following:</p><p>git, Capistrano, ssh client, and a http://github.com/ account.</p></li><li><p>8/8/2019 Works Ubuntu Apache Passenger</p><p> 4/8</p><p>Git:</p><p>Before we get started with Git, lets make sure your development machine can access github. If</p><p>you havent created an account yet, what are you waiting for? :)</p><p>Once you have logged in to github, add your development machines public key to your account</p><p>settings. Github help section can guide you through this.</p><p>In the directory of your rails application, initialize an empty git repository on the local machine:</p><p> git init</p><p>This creates a series of files for git under the hidden folder .git within your applications folder.</p><p>If you want to tell git to exclude any of your applications files from being seen by git (for</p><p>example; large files, databases), you can add them now by creating a file hidden file .gitignore</p><p>in the root of your applications directory.</p><p>Add the files in your applications directory to Gits list of files:</p><p> git add .</p><p>Commit these files to your first entry with Git:</p><p> git commit -m my first commits message, rails is fun! :D</p><p>Tell git where your repository is. In this case were using a github account:</p><p> git remote add origin git@github.com:krisf/Software-Manager.git</p><p>Push all the files from your first commit to your git repositorys master branch:</p><p> git push origin master</p><p>You now have a repository setup on Github!</p><p>Now you need to add your servers public key to github so it can access the repository too:</p><p> http://help.github.com/linux-key-setup/</p><p>Ensure your application has a database in MySQL to deploy to:</p>mailto:git@github.comhttp://help.github.com/linux-key-setup/http://help.github.com/linux-key-setup/mailto:git@github.comhttp://help.github.com/linux-key-setup/</li><li><p>8/8/2019 Works Ubuntu Apache Passenger</p><p> 5/8</p><p> mysql -u root -p&gt; enter MySQL root password:</p><p>&gt; create database ApplicationsDatabaseProd;</p><p>&gt; exit</p><p>Capistrano:</p><p>In your applications directory, get Capistrano to create the files it requires (Capfile,</p><p>config/deploy.rb). Capfile is just an initialization file for Capistrano. Your deploy.rb file contains</p><p>the Capistrano settings.</p><p>Edit deploy.rb and use the following as a template:</p><p>Test Webserver performance with ApacheBench (ab):</p><p># ApacheBench: (concurrent requests: 50) (number of total requests : 2000) (url to your</p><p>website). Use the following command:</p><p> ab -c 50 -n 2000 (url to your website)</p></li><li><p>8/8/2019 Works Ubuntu Apache Passenger</p><p> 6/8</p><p>Annex A: Setting a static IP Address in Ubuntu</p><p> sudo nano /etc/network/interfaces</p><p>Content Example:</p><p>------------------------------------------</p><p>auto eth0</p><p>iface eth0 inet static</p><p>address 192.168.0.100</p><p>netmask 255.255.255.0</p><p>network 192.168.0.0</p><p>broadcast 192.168.0.255</p><p>gateway 192.168.0.1</p><p>------------------------------------------</p></li><li><p>8/8/2019 Works Ubuntu Apache Passenger</p><p> 7/8</p><p>Annex B: Configuring SSH on a fresh Ubuntu install</p><p>Install SSH:</p><p> sudo apt-get install openssh-server openssh-client -y</p><p>Create an SSH Alias for your server:</p><p> sudo nano ~/.ssh/config</p><p>Content Example:------------------------------------------</p><p>Host MyServersAliasName</p><p>Hostname 192.168.0.10</p><p>User ubuntu</p><p>------------------------------------------</p><p>Now you can use ssh MyServersAliasName to connect.</p><p>Configure SSH:</p><p>On the server:</p><p> mkdir .ssh</p><p>On your development machine:</p><p> cd ~/.ssh &amp;&amp; ls</p></li><li><p>8/8/2019 Works Ubuntu Apache Passenger</p><p> 8/8</p><p>If a public rsa key file exists (id_dsa.pub), copy it to the server so you can login without entering</p><p>a password:</p><p> scp ~/.ssh/id_dsa.pub MyServersAliasName:.ssh/authorized_keys</p><p>If youre running on Amazon EC2, its like:</p><p>scp -i cfrg.pem ~/.ssh/id_dsa.pub MyServersAliasName:.ssh/authorized_keys2</p></li></ul>

Recommended

View more >