Heads up! To view this whole video, sign in with your Courses Plus account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
Lastly, we need to set up PostgreSQL on our production server, and set our Rails app up to use it.
You can test this out either on an actual Ubuntu Linux server at your web hosting company, or you can use a virtual machine.
Connect to your server via SSH, and run:
sudo apt-get install postgresql libpq-dev
sudo -u postgres createuser --superuser deploy
cd /PATH/TO/YOUR/guestbook
git pull
bundle install
RAILS_ENV=production bin/rails db:setup
RAILS_ENV=production bin/rails server
We have postscripts all set up
on our development machine but
0:00
now it's time to install
it in production as well.
0:03
I'm using an Ubuntu server Linux
installation on a virtual machine but
0:06
the process should be similar
if you have a web host.
0:10
See the teacher's notes
if you'd like more info.
0:12
So first we're going to need to
establish an ssh connection to the host.
0:16
So I'm going to log in as my
deployment user on my host machine.
0:21
And then we need to install postscripts
itself which will do using a Ubuntu
0:31
package manager software.
0:35
So this is an administrative command so
I'm going to need to prefix it with sudo.
0:37
Then I'll run the apt get command.
0:43
That's Ubuntu package manager or
on the install sub command and
0:44
then we need the names of the software
packages we wanna install.
0:51
The first is going to
be postpressql itself.
0:55
And the second is a set of
development libraries that we're
1:01
going to need to compile the pggem so
that rails can communicate with postgress.
1:04
So I'm going to install libpq-dev.
1:08
Hit enter to run that only to provide
my deployment user's password.
1:14
Since I'm running a sudo command.
1:22
I'll confirm that I want
to install everything.
1:25
Now as I mentioned post press ports
multiple users we're going to need to
1:37
create a postscripts account for our rails
out to actually connect to the database.
1:41
So let's run a command to create that now.
1:47
In addition to installing the postscript
server, the apps get command we
1:50
ran will create a postscript user
with full control over postscript.
1:55
So, we are going to run this
command as that postscript user.
1:59
So we use this sudo command and will
specify with the -u command line flag.
2:02
That this command should be
run as the new postgres user.
2:09
Then we're going to run a command that
got installed along with postgres called
2:14
the create user.
2:17
This will create a new user for
the postgres database.
2:20
We want this user to be a super user, so
2:24
we'll add the command line
flag double dash superuser
2:28
that will give them full control over that
of base and we want this use it be named
2:32
deploy the same as the deployment
user that we use for our rails out.
2:37
Note that this is also the same
username that we set up
2:43
in our database dot yaml configuration for
the Rails app.
2:46
So we'll run this command and
create the user we need.
2:52
Now let's change into the directory for
Rails app.
2:56
I've committed the configuration changes I
made on my own development machine to get
3:01
and I've pushed them
out to the origin repo.
3:05
Now pull them down to the production app.
3:07
With git pull, we're also going
to be back shortly to create
3:10
the database here production
to do that with RAILS_ENV =
3:15
production to set the RAILS-ENV
environment variable.
3:20
And then we run the bin/rails command,
db set up just like we did in development.
3:25
That will create the production
database for us and load the schema.
3:33
And now we should be ready to run the
bin/rails server command in production.
3:37
Let's visit our browser.
3:46
Type in the address for our host.
3:48
Port 3000, And
here's our list of signatures.
3:53
Let's try creating a New Signature.
3:58
Looks like it was saved.
4:04
Our app is working with our
postgrass database in production.
4:18
So there you have it, we have our rails
app configured to work with a postgrass
4:23
database, pretty easy right.
4:26
Postgrass is by and
large a drop in replacement for SQLite.
4:28
But you'll find that it's much faster and
more stable.
4:32
If you having trouble replicating
these steps on your own set up,
4:35
be sure to check the teacher's notes for
hints and troubleshooting tips.
4:38
Hope you have fun trying
out your new database.
4:42
You need to sign up for Treehouse in order to download course files.
Sign up