Ubuntu setup - page 3
In page 2 We consolidated the base install and updated the base image, installed the security updates and configured some personal configuration files.
Now we'll install the meat of the server: mysql with Ruby on Rails and subversion support.
If you are not logged in already then log in using the username we setup earlier:
ssh -p 30000 paul@YOURIPADDRESS
Start a screen session:
screen
Ubuntu has some handy meta-packages that include common programmes needed for one purpose. So instead of installing a dozen different package names, you can install just one meta-package. One such package is called 'build-essential'. Issue the command:
sudo apt-get install build-essential
Notice the programmes that are to be installed include gcc, make, patch, headers and so on. All these are needed for many other programmes to install properly. A neat system indeed. Click 'Y' and install them.
mysql install
Right, let's get on and install mysql and then optimise it for use with a VPS. It needs optimising as the default configuration uses a fair bit of memory and there is no need to 'waste' memory like that. We added the mysql bindings for ruby to save time later when we install Ruby on Rails. I like to plan ahead and install packages in groups rather than splinter bit and pieces everywhere and lose track of what is going on:
sudo apt-get install mysql-server mysql-client libmysqlclient15-dev libmysql-ruby -y
mysql installs without a password for the root user (don't confuse this 'root' user with your server's root user - it is simply the mysql user that has access to all the databases). Let's add a password straight away:
mysqladmin -u root password YOURMYSQLPASSWORD
There are some great articles on optimising mysql on the web. A couple to get you started (if you want to know more) are mysql performance and optimising mysql.
Now let's optimise mysql for your VPS. Open the mysql configuration file:
sudo nano /etc/mysql/my.cnf
We're going to add two lines in the basic setting section. Find the first two lines shown below and add the two lines shown after:
language = /usr/share/mysql/english
skip-external-locking
skip-locking
skip-innodb
NOTE: If you intend to use innodb databases then don't include the skip-innodb line!
Next, find the Fine Tuning section and adjust the settings / add the entries as shown below:
# * Fine Tuning
#
key_buffer = 16K
max_allowed_packet = 1M
thread_stack = 64K
thread_cache_size = 4
sort_buffer=64K
net_buffer_length=2K
Before we restart mysql, let's have a quick look at how much memory it's using on the original configuration. Enter the command 'top':
top
Then holding the 'Shift' button down, press 'm'. This will arrange the output of top in order of memory usage. You will see something like this:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3223 mysql 15 0 ---- ---- ---- -- 0 8.9 0:00.15 mysqld
On this 256MB test slice, mysql is using 8.9% of the memory (I've removed some of the other figures so the output is easily noted).
Exit top (Ctrl and 'c') and restart mysql:
sudo /etc/init.d/mysql restart
Now look at top again. My output is now:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3453 mysql 15 0 ---- ---- ---- -- 0 2.0 0:00.03 mysqld
See the immediate difference? Memory use is now just 2.0%. When memory is a factor, such as when using a VPS, optimising any install can be a very good idea.
Ruby on Rails install
We'll begin by installing ruby from the apt repositories and then installing rubygems via source code:
sudo apt-get install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8 libopenssl-ruby -y
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
In our home directory, we will create a 'sources' folder:
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! I continue the install with imagemagick and a quick ruby test as follows:
sudo apt-get install imagemagick librmagick-ruby1.8 librmagick-ruby-doc libfreetype6-dev xml-core -y
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
Obviously, if the output does not return 'true' for each 'require' command, then something has gone wrong. If the result is correct and returns 'true' then we have a working ruby install.
Finally, we need to install postfix (if we don't do this now, other programmes will install exim and all sorts of unneeded email help) and subversion so we can 'check-out' plugins and goodies for our Rails applications:
sudo apt-get install postfix subversion -y
Answer the postfix questions as you see fit but the defaults usually suffice for our purposes as we are only using it to send emails and not for mail-server purposes.
That's it!
We now have a secure, up to date Ubuntu server with mysql, Ruby on Rails and subversion.
At this point, you can split off from these tutorials and install your own server or other needs. However, in the Litespeed tutorials we'll install the Litespeed Webserver - quicker, easier and less hassle than apache or nginx, etc. No messing about with mongrels or trac server daemons. It incorportes all we need in one easy package with an incredibly low memory footprint.
We'll also install the latest php version with our Litespeed server.
PickledOnion.
Digg it |
del.icio.us |
reddit |
StumbleUpon

Subscribe to Feed
Article Comments:
knight 24 Jun, 2007
Hi, great tutorial i would say.
for the sql part , libmysql-ruby seem like not found ...
PickledOnion 24 Jun, 2007
Hmm, odd. Have you updated the sources.list to the one used in page 2 of the article?
It's possible it's on one of those repo's as I have libmysql-ruby on each of my Ubuntu VPS installs.
Let me know if you still have problems.
PickledOnion.
Adi 17 Sep, 2007
After reastarting mysql server with sudo /etc/init.d/mysql restart command the server didn't failed to start
...failed or took more than 6s. Please take a look at the syslog. /usr/bin/mysqladmin: connect to server at 'localhost' failed error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!