Debian VPS setup - page 3

In this final Debian VPS setup article we install 'screen' so processes can be left running even if the connection is lost.

Then a MySQL install is optimised followed by Ruby on Rails with subversion and postfix support ready for the server of our choice (with Litespeed being top of the list).

screen

Let's get started straight away by installing screen. This is a great application that allows 'virtual' terminals to be opened in one console. Switching between them is done with the press of a key.

The advantages are that you can be working on more than one shell at a time, say one installing software and another monitoring network activity, without having more than one physical shell open. If the SSH connection is cut for some reason or you have to leave the room then close the terminal and the work will still carry on in the background.

I highly recommend installing and getting used to using screen. This screen tutorial gives an excellent introduction.

sudo aptitude install screen

To start a screen session simply enter the command:

screen

Press the space bar to remove the introduction page and to activate any custom bash_profile entries, enter:

source ~/.bash_profile

Essentials

Most software requires libraries and compilers to work properly. As you would imagine, they (nearly) all share the same libraries and compilers. If they didn't it would be a bit of mess really.

Debian provides what is known as 'meta-packages'. The meta-packages are a defined set of programmes for particular situations. One such set of packages include the 'essential' programmes described above such as shared libraries and compilers.

This is a nice time saver and ensure we don't forget anything. So go ahead and install the 'essentials':

sudo aptitude install build-essential

Have a look at what is going to be installed and, once you are happy with the build-essential package, click 'Y' to continue.

Postfix

Next we need to install Postfix. It may seem odd to install this now as it only has a 'supporting' role in this setup but completing this step now ensures many unnecessary email dependencies are not installed later on.

This step is very simple:

sudo aptitude install postfix

Don't be put off by the sight of so many programmes being installed and have a good look at the list. It includes many font and image libraries as well as secure connection files and so on.

They're all needed and they are all base requirements. If they weren't installed now, they surely would be later!

When the postfix installation asks for configuration details, simply press enter to select the default choices.

MySQL

Let carry on and install MySQL. Once installed we will optimise the default configuration so it uses less memory. Remember that we are on a VPS so memory is likely to be somewhat limited and the default MySQL configuration files are more suited to larger servers.

We need the server, client, libraries and ruby bindings:

sudo aptitude install install mysql-server mysql-client libmysqlclient15-dev libmysql-ruby

The very first thing to do is set a root password as the MySQL install does not have one set yet:

mysqladmin -u root password YOURMYSQLPASSWORD

Next we'll optimise the default configuration. There will be an article on how to optimise MySQL for your particular VPS needs and requirements but for the moment there are some great articles on optimising mysql on the web. One to get you started (if you want to know more) is mysql performance.

Fire up your favourite text editor and open the MySQL config file:

sudo nano /etc/mysql/my.cnf

If you do not use InnoDB databases then turn off InnoDB as this uses a fair chunk of memory. To do this find the 'Basic Settings' section and add the following two lines (just after the 'skip-external-locking' line if fine):

skip-locking
skip-innodb

Just below 'Basic Settings' is the 'Fine Tuning' section. Lowering the default values of this section will reduce memory usage. Adjust or add the following lines:

# * Fine Tuning
#
key_buffer    = 16K
max_allowed_packet  = 1M
thread_stack    = 64K
thread_cache_size = 4
sort_buffer=64K
net_buffer_length=2K

Save the configuration changes and restart MySQL:

sudo /etc/init.d/mysql restart

Ruby on Rails

To install Rails we can begin by using aptitude and then move onto source for the rubygems:

sudo aptitude install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8 libopenssl-ruby

Next we need to create some symlinks from the install to locations every programme would look. Each line below is a separate command:

sudo ln -s /usr/bin/ruby1.8 /usr/local/bin/ruby
sudo ln -s /usr/bin/ri1.8 /usr/local/bin/ri
sudo ln -s /usr/bin/rdoc1.8 /usr/local/bin/rdoc
sudo ln -s /usr/bin/irb1.8 /usr/local/bin/irb

Remember that a tidy server is a happy server and as we are now going to download the rubygems source code, it's a good idea to have folder just for this sort of administration. So in your home directory create a folder named 'sources' and move into it:

cd ~
mkdir sources
cd sources

Now we have moved to the sources directory, download the rubygems source code, unpack it and install it:

wget http://rubyforge.org/frs/download.php/20989/rubygems-0.9.4.tgz
tar -xvf rubygems-0.9.4.tgz
cd rubygems-0.9.4
sudo ruby setup.rb

Once done, move back to your home directory and update the ruby components:

cd ~
sudo gem update
sudo gem update --system

Now we can install rails with the command:

sudo gem install rails --include-dependencies

The basic Ruby on Rails install is now completed but I continue the install with imagemagick and a quick ruby test as follows:

sudo aptitude install imagemagick librmagick-ruby1.8 librmagick-ruby-doc libfreetype6-dev

Now we can do a quick test to see if the install works (thanks to brainspl.at for this idea).

The light grey parts of the code shown below are the terminal output - you enter the black/coloured commands:

irb
#irb(main):001:0>
require 'RMagick'
#=> true
#irb(main):002:0>
require 'mysql'
#=> true
#irb(main):003:0>
exit

If the output does not return 'true' for each 'require' command, then something has gone wrong during the install. Simply retrace your steps and see what was missed out.

Finally, we need to install subversion so we can 'check-out' plugins and goodies for our Rails applications:

sudo aptitude install subversion

Finished

That's it!

We now have a secure, up to date Debian Etch VPS with MySQL and Ruby on Rails with postfix and subversion support.

At this point, feel free to split off from these tutorials and install your own server or other software needs.

The Litespeed Webserver comes highly recommended for all web usage but especially for Rails users - quicker, easier and less hassle than apache or nginx, etc. No messing about with mongrels or load balancers. Go on, what have you got to lose?

However, whatever you do with your VPS, enjoy it.

PickledOnion.

Digg it | del.icio.us | reddit | StumbleUpon

Comments are closed for this article.