Quick and Dirty Install
Assumes you are logged in as root. Use sudo where necessary (like any make or gem installs). Skip the steps that you already have (i.e. Ruby/RubyGems installation)
Install dependencies:
yum -y install zlib openssl-devel readline-devel gcc-c++
Install Ruby and RubyGems (if the REE installer fails for lack of finding an interpreter):
wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p72.tar.gz
tar -zxvf ruby-1.8.7-p72.tar.gz
cd ruby-1.8.7-p72
./configure
make && make install
wget http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz
tar -zxvf rubygems-1.3.1.tgz
cd rubygems-1.3.1
ruby setup.rb
Install Ruby Enterprise (if you are on a 64-bit distro, you may have duplicate i386 AND x86_64 versions of libstdc++ and you will get an error… either uninstall the i386 version, or add –no-tcmalloc option to installer command):
wget http://rubyforge.org/frs/download.php/51100/ruby-enterprise-1.8.6-20090201.tar.gz tar -zxvf ruby-enterprise-1.8.6-20090201.tar.gz ./ruby-enterprise-1.8.6-20090201/installer/opt/ruby-enterprise-1.8.6-20090201/bin/passenger-install-apache2-module
Add the following directory to your path (you could use symlinks too)
/opt/ruby-enterprise-1.8.6-20090201/bin
Add the following to Apache config:
LoadModule passenger_module /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.x/gems/passenger-2.0.6/ext/apache2/mod_passenger.so
PassengerRoot /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.x/gems/passenger-2.0.6
PassengerRuby /opt/ruby-enterprise-1.8.6-20090201/bin/ruby
Install any gems you want or that are required that *did not* get installed as a result of the REE installer..
gem install passenger rake rails fastthread rack sqlite3-ruby postgres
gem install mysql -- --with-mysql-config='/usr/bin/mysql_config'
Install Subversion:
yum install subversion
Create repository:
mkdir /usr/local/svn/repos/
svnadmin create /usr/local/svn/repos/project
chown -R apache:apache /usr/local/svn/repos/project
Add the following lines to subversion.conf (or whatever apache config file you choose to use):
<Location /svn/repos>
DAV svn
SVNParentPath /usr/local/svn/repos
</Location>
Create a password file:
htpasswd -cm /etc/svn-auth-file username
Add more usernames/passwords:
htpasswd -m /etc/svn-auth-file username
Modify your subversion.conf to use whatever security method you deem necessary
Create your rails app:
rails rails_app
Import your rails app:
svn import -m "Initial import" rails_app file:///usr/local/svn/repos/project
Add virtual host for rails app (this will entirely depend on your server/application setup, but mainly concern yourself with the fact that your DocumentRoot and Directory directives should have /public at the end):
<VirtualHost *:80>
ServerAdmin webmaster@yourdomain.com
DocumentRoot /path/to/rails_app/public
ServerName yourdomain.com
ErrorLog logs/yourdomain.com-error_log
CustomLog logs/yourdomain.com-access_log common
</VirtualHost>
Done. Time to go caffeinate.
Full install approach after the break.
Intro
Okay, so I have to be really honest. I’ve installed all of the above (and more) on probably 20 boxes at this point. Windows, CentOS4/5, RHEL4/5, FC6/7/8/9… and it always, no matter what, drives me nuts, because inevitably a library is missing or incompatible, meaning an extension doesn’t get installed when you compile your source, and then when you get the library, you have to recompile *everything*. Ugh. So I’ve come up with sort of a hit-list for what you need to make sure that your headaches never get to be as big as mine. These instructions assume that you have some sort of server admin experience, like that you can at a bare minimum open an SSH client, connect to your server, and not freak out when you feel like you’re set back to 1980. So, here goes.
We’ll be installing Ruby Enterprise (REE), which generally works right out of the box. However, on some Linux distros (I haven’t used enough varieties to know the reason), there is no Ruby interpreter, and thus REE will require you to have Ruby and RubyGems pre-installed. So if you notice that the installer fails to start, please install Ruby first. So if the following step fails, click here.
Install Ruby Enterprise
Okay, enough of that fun stuff. Now, let’s get Ruby Enterprise (REE) running. Wait.. why did we just install Ruby if we’re going to install REE? Because… the REE installer needs a version of Ruby and RubyGems to be existent in order to install itself. So, head over to the downloads page. (Latest Release – right-click/apple-click, Copy Link Location). Back to Terminal/Putty/whatever..
wget link://to/ruby-enterprise-location (probably on clipboard) tar -zxvf ruby-enterprise-x.x.x.tar.gz ./ruby-enterprise-X.X.X/installer
When the installer pauses, it’s generally asking a question, just hit Enter/return. This installer will install the following gems:
- passenger
- rake
- rails
- fastthread
- rack
- mysql
- sqlite3-ruby
- postgres
If you are running a 64-bit distro (RHE5 and CentOS have this issue for certain), you might end up with x86_64 AND i386 versions of libraries. Specifically, libstdc++ and REE will whine and throw a completely unrelated error (make: *** [libtcmalloc_minimal_la-internal_logging.lo] Error 1). If this is the case, you have 2 options. 1) Uninstall the i386 version of libstdc++ or 2) add –no-tcmalloc option to the installer command like so:
./ruby-enterprise-X.X.X/installer --no-tcmalloc
Any gems that the installer does not install will appear in yellow on your screen. Sometimes it hangs up on the sqlite3-ruby and postgres gems. If it misses all of them, there is most likely a problem with your RubyGems (like they’re non-existent) or a missing library.
Install Passenger Apache module
For less memory consumption, I highly recommend using Passenger a.k.a. mod_rails (instead of Mongrel) for your Rails apps.
/opt/ruby-enterprise-x.x.x/bin/passenger-install-apache2-module
Now we need to tell apache to use the passenger module, so in your apache config file (generally /etc/httpd/conf/httpd.conf or something of the like) find the lines with LoadModule at the beginning and add the lines of code that the installer gave you. They should look like:
LoadModule passenger_module /opt/ruby-enterprise-x.x.x/lib/ruby/gems/1.x/gems/passenger-x.x.x/ext/apache2/mod_passenger.so PassengerRoot /opt/ruby-enterprise-x.x.x/lib/ruby/gems/1.x/gems/passenger-x.x.x PassengerRuby /opt/ruby-enterprise-x.x.x/bin/ruby
You’ll need to restart apache for this to take effect (as with any changes you ever make to your conf file(s)).
Set Your Path
You will be kicking yourself if everytime you want to run a ruby or gem or rake command, you have to type /opt/ruby-enterprise-x.x.x/bin/command … So it’s a good idea to add the REE bin dir to your path. This can be done in several ways depending on your Linux distro. For CentOS5, there is now a function in the profile for pathmunge. Otherwise, you will probably have just an export line in your profile.
vi /etc/profile
Ubuntu uses /etc/environment and the line looks like:
PATH=”/opt/ruby-enterprise-x.x.x/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games”
Other distros will likely look like:
if [ "$EUID" = "0" ]; then
pathmunge /sbin
pathmunge /usr/sbin
pathmunge /usr/local/sbin
pathmunge /opt/ruby-enterprise-x.x.x/bin
fi
Because you modified your profile, you *must* reload it. Now if you type which ruby , you should see /opt/ruby-enterprise-x.x.x/bin/ruby
Install Subversion
yum install subversion
There, that was easy, right? If you don’t have yum, you have 2 options (maybe).
If you’re running a RedHat distro (or CentOS), you can get the binary from here. This *may* work on other distros as well, but I haven’t tested.
Otherwise, grab a tarball from this page. Then you’ll need to untar, configure, make and make install. Fairly straightforward and easy.
Subversion Setup
My instructions for Subversion setup make the assumptions that a) your folder structure looks like mine, b) you will want to access your repository/ies from remote sources, and c) you’ll potentially have multiple users of your repository/ies. If that’s not true, these instructions can still apply, but you may rather wander off your own way.
If you’re going to want to get to your repository from the “web” a.k.a http… whether it’s through a svn client or a browser… you’ll need the Apache 2.0 module. The odds – if you were to roll the dice – are that you already are running Apache. If not, download, configure and install it.
Now, again, if you’re choosing to use Apache 2.0, you need the mod_dav_svn plugin (it should have installed when you installed Subversion, but if you installed Subversion from source, then you’ll probably need to install it, as well as authz_svn_module).
Create a directory to hold your repository/ies.
mkdir /usr/local/svn/repos/
Now time to create your repo. Note: You must be logged in as root or be a sudoer to use the svnadmin commands. And you want your repository owned by apache so that any http protocols can access it (i.e. http://yourdomain.com/svn/repos/project)
svnadmin create /usr/local/svn/repos/project chown -R apache:apache/usr/local/svn/repos/project
The next step is entirely dependent on how you want to run your Subversion repositories. If you plan on having multiple repos under one main directory, you want to probably use SVNParentPath, otherwise SVNPath will be fine.
It is likely that when you installed subversion, it added a config file ‘subversion.conf’ in your /etc/httpd/ directory somewhere… possibly in conf/, possibly in conf.d/ … if you don’t see it, grep for it, or use find. Any config file can be used for your SVN directives, it’s merely preference to use an additional file. However, this file does contain the following two lines:
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
So if you choose to disable subversion.conf or if it isn’t existent, be sure to add those lines to your apache config, so that Apache will load your svn modules.
In subversion.conf, you should see a <Location> block commented out with things like AuthType Basic, etc inside.
Modify this so that it matches everything you’ve done so far. The <Location> block which has /svn/repos is how you want to access your URL. The SVNParentPath directive tells Apache to look in that directory for repositories.
For right now, we’re only going to worry about the <Location> block. So you want it to look like this, where the Location is the http location you want to hit (http://mydomain.com/svn/repos for instance) and SVNParentPath is the absolute path to your repos directory (this could look different if you setup your repository in a different directory than I showed earlier) :
<Location /svn/repos>
DAV svn
SVNParentPath /usr/local/svn/repos
</Location>
If you restart apache now, you should be able to open a web browser and visit http://yourdomain.com/svn/repos/project and see nothing (we haven’t imported/committed anything yet).
Subversion Security
Skip this section if you don’t care about password protecting your repositories, or if you’re not using Apache 2.0 and mod_dav_svn to have http access to your repos.
So you want to control access to your repository/ies. Svn security can get extremely fine-grained and I don’t plan to go into all of the details, but I will give you some high-level info about how to require authentication to access/checkout/commit, etc.
First, you’ll need to supply apache with some users and passwords. For this, we’re going to create our own svn users file, so as not to conflict with our regular apache users file.
htpasswd -cm /etc/svn-auth-file harry
We use the -c option to create the file since most likely it doesn’t already exist. Once it’s created, if you want to just add users, you only need to use the -m option. This command will prompt you for a password, then ask you to re-enter it. Repeat this command for as many users as you want.
Next, pick your authentication poison.
Simple Authentication
The first method I’m going to describe is a very basic method, which basically just uses our svn auth file to let a user login with their username and password and do whatever it is they gotta do. I.e. this method is not going to let you set individual permissions per user. It’s just an easy way if you only have maybe one or 2 users and all should have the same access/commit rights.
So back in your subversion.conf, where we edited the <Location> block before, now we modify it to look like:
<Location /svn/repos>
DAV svn
SVNParentPath /usr/local/svn/repos
AuthType Basic
AuthName "Authorization Realm"
AuthUserFile /etc/svn-auth-file
# <LimitExcept GET PROPFIND OPTIONS REPORT>
# if you want to require SSL when authenticating users, uncomment the next line
# SSLRequireSSL
Require valid-user
# </LimitExcept>
</Location>
You can uncomment the <LimitExcept> block to set restrictions on certain actions… LimitExcept means that anything you put here (like GET PROPFIND, etc) will be publicly accessible whereas, everything else (i.e. checkouts, propedits, commits, etc) will require authentication. Without the <LimitExcept> block, if you use the Require valid-user directive, all actions will require authentication.
Okay so that is the most basic way to secure your repository/ies.
Advanced Authentication
Advanced svn security assumes that you will probably have several users, each of which should have their own set(s) of permissions, potentially at the repository parent level, or possibly at an individual repository level. In other words, some or all users can do some or all things with some or all repositories.
This is where our authz_svn_module comes in handy.
You’re still in subversion.conf, so now we’re going to change up our <Location> block a bit. Remove the <LimitExcept> block, as your permissions/control are dictated by your authz file now.
Add the following line below the SVNParentPath/SVNPath directive:
AuthzSVNAccessFile /etc/svn-auth-control
This tells apache to find the control file which holds all of our permissions. So next, we’re going to create our auth access file. This is different from your users file, since it doesn’t store usernames/password, but rather permissions.
You should end up with something like:
<Location /repos>
DAV svn
SVNParentPath /usr/local/svn
# our access control policy
AuthzSVNAccessFile /path/to/access/file
# try anonymous access first, resort to real
# authentication if necessary.
Satisfy Any
Require valid-user
AuthType Basic
AuthName "Subversion repository"
AuthUserFile /path/to/users/file
</Location>
Now you’ll want to edit your authz file to add your permissions.
vi /etc/svn-auth-control
As for setting the permissions, there are tons of options, but note that if you leave this file empty, then no one will have any access to any repository. Everything in the brackets is done in the form of [repos-name:path]. So we might have something like the following:
# give everyone read-access to all repositories
[/]
* = r
# give harry read-write access, and sally read-access to /branches/1.2 within the 'project' repo
[project:/branches/1.2]
harry = rw
sally = r
# give sally write access only to the 'testing' subdir
[project:/branches/1.2/testing]
sally = rw
Or you can use groups (or a combination of users and groups) if you have lots of users where permissions overlap:
[groups] branch-developers = harry, sally, joe test-developers = frank, sally, jane everyone = harry, sally, joe, frank, sally, jane [project:/branches] @branch-developers = rw @test-developers = r jane = r
Again, be sure to restart apache for all of this to take effect.
Read all about Subversion Security
Creating the Rails App
There are way too many tutorials for creating a Rails app so I’m not going to rewrite the book, but I’ll run through a quick setup to show you then how to get your Rails project into your newly created repository.
So you’ll want to cd to whichever directory you want your working copy of your Rails app to be. Then within that directory, run the following, where new_proj is the name of your app:
rails rails_app
Importing to the Repository
So, first we need to do an initial import so that the repository has something to work with. From then out, we can just do commits/updates/etc.
svn import -m "Initial import" new_proj http://yourdomain.com/svn/repos/project
If you didn’t set up apache, you can use the following:
svn import -m "Initial import" rails_app file:///usr/local/svn/repos/project
Make Passenger Know About Your App
So to recap, we installed Ruby Enterprise, which gave us Passenger, which is what will run our Rails app. Passenger is *almost* magic, but not quite, so we need to make sure that it knows where our Rails app lives. So the last step, which is possibly the trickiest (or possibly the easiest, depending on how the rest of this went for you)… is to modify your apache config one more time to add a VirtualHost which points to your Rails app public directory. The reason this could be tricky to explain is, if you are on a VPS, odds are there is already a VirtualHost somewhere for your domain. Sometimes they exist solely in the domain directory (i.e. /var/www/vhosts/domain.com/conf/) and sometimes they exist in a single file in /etc/httpd/conf.d/vhosts.conf, or something of the like. If you’re on a dedicated server (or something similar) then you’ll probably just want to create a vhost.conf in your /etc/httpd/conf.d folder. All files with a .conf extension in this folder generally get included when apache starts.
Inside this file, you want something that looks similar to the following:
<VirtualHost *:80>
ServerAdmin webmaster@yourdomain.com
DocumentRoot /path/to/rails_app/public
ServerName yourdomain.com
ErrorLog logs/yourdomain.com-error_log
CustomLog logs/yourdomain.com-access_log common
</VirtualHost>
The most important thing, no matter what file this is in, is that you have /public at the end of your DocumentRoot directive. So, listening on port 80, if I were to visit yourdomain.com , Passenger would know to run the Rails app.
So, for example, I have an app called tools, which lives in /home/services/tools on my server. So my vhosts.conf (in /etc/httpd/conf.d/) looks like:
<VirtualHost 255.255.255.255:80>
ServerName tools.mydomain.com:80
ServerAdmin "admin@mydomain.com"
DocumentRoot /home/services/tools/public
<IfModule mod_ssl.c>
SSLEngine off
</IfModule>
<Directory /home/services/tools/public>
Options +Indexes +Includes +ExecCGI
</Directory>
</VirtualHost>
Of course, my IP address is not really 255.255.255.255 , you should use yours… and my domain is not really mydomain.com , again, you should use yours. But that’s the gist of it.
Finished!
So hopefully you now have a working Rails app that is under version control.
Extra
The following is for people who are unable to run the REE installer, because it requires Ruby and RubyGems to be pre-installed.
First, check that you have Ruby and/or RubyGems:
ruby -v
gem -v
If your Ruby version is less than 1.8.6, you should consider upgrading (just follow the install steps). Also, to note, you probably need RubyGems 1.3.1 or higher. If you already have Ruby and RubyGems installed, click here to skip those steps.
Install Yum and Libraries
Most crucial time-saver in the world = yum. Install it. This is the hardest part sometimes because you’ll need 17,000 dependencies (like not just python, but the specific version of python to match your metadata-parser library… seriously, it’s a puzzle). So I’m not covering the yum installation because it’s different for every single platform. Bleh.
Before you compile Ruby, check for the following couple of items (please leave a comment if your compilation requires a library you don’t already have that isn’t in this list and I’ll add it):
- zlib
- openssl-devel
- readline-devel
- gcc-c++
To see your installed libraries, run:
yum list installed
If you’re missing any from the list above, install them with yum install name-of-lib.
Install Ruby
So now you need Ruby. You’ll need to grab some source code (preferably a decent version, like 1.8.6 or higher — as of this post, 1.9.1 is out, but the Rails website recommends 1.8.7 ). If you’re on Ubuntu or Debian, it’s easy with sudo apt-get ruby irb rdoc ri. I’m only including a link to the Download pages, because this post will eventually become outdated, but basically right click on the link for the most stable version and Copy Link Location — or download it somewhere local and untar it… whatever you fancy).
wget link://to/ruby-location (which is probably saved on your clipboard)
Detarify the package…
tar -zxvf name-of-downloaded-package.tar.gz
Next, compile and install ruby.
cd name-of-downloaded-package
./configure
make && make install
Install RubyGems
You will need RubyGems (or gems) to install Rails, as well as other helpful tools, such as rake, passenger, etc. So, next, grab a RubyGems package. As of this post, you want rubygems-1.3.1.tgz. Untar and run the setup:
tar -zxvf rubygems-x.x.x.tgz
cd rubygems.x.x.x
ruby setup.rb
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.