27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

394 CHAPTER 14 Deployment<br />

service ssh restart<br />

The server is now set up with key-based authentication, which completes the user<br />

setup part of this chapter.<br />

The next step is to install a sturdy database server where you can keep the data for<br />

your application when it’s deployed. At the moment (on your local machine) you’re<br />

using the SQLite database for this. That’s great for light development, but you probably<br />

want something more robust for your application, just in case it gets popular overnight.<br />

19 That robust something is a database server called PostgreSQL.<br />

14.4 The database server<br />

PostgreSQL is the relational database 20 preferred by the majority of Rails developers.<br />

It will work perfectly with the Ticketee application because there’s no SQLite3-specific<br />

code within the Ticketee application at the moment. 21<br />

To install, use the aptitude command again:<br />

sudo aptitude install postgresql-8.4<br />

This will install the necessary software and commands for the database server, such as<br />

psql (used for interacting with the database server in a console), createuser (for creating<br />

a user in the system), and createdb (for creating databases on the server). 22<br />

You’ll be using these commands to create a user and a database for your application.<br />

14.4.1 Creating a database and user<br />

To begin this, switch to the postgres user, which is another account that this postgresql-8.4<br />

install has set up. To switch into this user, use this command:<br />

sudo su postgres<br />

This user account is the super user for the database and can perform commands such<br />

as creating databases and users, precisely what you want! Creating the database is easy<br />

enough; you only need to run createdb like this:<br />

createdb ticketeeapp.com<br />

Creating a user in PostgreSQL is a little more difficult, but (thankfully) isn’t rocket science.<br />

Using the createuser command, answer no to all the questions provided:<br />

$ createuser ticketeeapp.com<br />

Shall the new role be a superuser? (y/n) n<br />

Shall the new role be allowed to create databases? (y/n) n<br />

Shall the new role be allowed to create more new roles? (y/n) n<br />

19 Chances are low, but this is more to demonstrate how to set it up with a different database server.<br />

20 http://en.wikipedia.org/wiki/Relational_database. Contrasts the NoSQL term: http://en.wikipedia.org/<br />

wiki/NoSQL.<br />

21 Some Rails applications are developed on specific database systems and may contain code that depends on<br />

that system being used. Be wary.<br />

22 For more information about how to configure PostgreSQL, read about the pg_hba.conf file: http://www<br />

.postgresql.org/docs/9.0/static/auth-pg-hba-conf.html.

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

Saved successfully!

Ooh no, something went wrong!