27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Server setup<br />

up and running. Vagrant will allow you to download an operating system image and<br />

then set up VirtualBox in an exceptionally easy fashion.<br />

To install VirtualBox, you must first download it from http://virtualbox.org and<br />

install it like a normal program. 12 After that, you need to install the vagrant gem,<br />

which you can do by running this command:<br />

gem install vagrant<br />

Now that you’ve got VirtualBox and Vagrant, you can install Ubuntu using Vagrant.<br />

This is the operating system that you’ll use to run your server. This file is pretty large<br />

(over 500MB) and may not be good for some connections. As an alternative, we would<br />

recommend using a VPS, as suggested earlier. This command will download Ubuntu<br />

Lucid Lynx (10.04) which you can use as a perfectly fine base to set up your server:<br />

vagrant box add base http://files.vagrantup.com/lucid32.box<br />

To start up this server, you need to create a new folder called ubuntu (the name isn’t<br />

important and could be anything), where the configuration of your server will be<br />

stored. You can then run vagrant up and vagrant ssh to boot it and connect to it<br />

through SSH. Altogether:<br />

mkdir ubuntu<br />

cd ubuntu<br />

vagrant init<br />

vagrant up<br />

vagrant ssh<br />

The up command will take a couple of minutes to run, but the ssh command should<br />

be instantaneous after that.<br />

NOTE If at any point you wish to shut down your server, you can use the<br />

vagrant halt command.<br />

This is how you connect to servers in the real world, except you would use a command<br />

such as this:<br />

ssh username@some-server.somewhere.com<br />

The vagrant ssh is a good-enough analogy to that. By running vagrant ssh you connect<br />

to your server as the user vagrant. This user has administrative (or more commonly<br />

referred to as root) access on this box, and so you’re able to install the<br />

packages that you need.<br />

If you’re using a non-Vagrant machine, you’ll first need to set up a user for yourself<br />

rather than operating as the root user, as this can be dangerous. 13 To do this, use this<br />

command (replacing user with a username such as ryan):<br />

12 If you’re on Windows XP you may encounter issues where it claims to have not been verified correctly. This<br />

is a known problem. If you skip the errors, it will still work.<br />

13 For example, if you were running a script as the root user and that script attempted to delete the /usr directory,<br />

the command would execute. By executing commands as non-root, you save yourself some potential<br />

damage from malevolent scripts. This is because the user will only have access to some directories, rather than<br />

root, which has access to everything.<br />

387

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!