Creating a Linux Server for Web Services



In this post you’re going to learn how to download and install VirtualBox on your Mac to aid the creation of Linux servers to do web service development. Often iOS applications require the need to know how to develop web services, as much of the functionality of a given app is actually “in the cloud”. If you’ve developed any Facebook or Twitter applications, you’re already familiar with the concept of using a “service in the cloud”. This tutorial is part of a series designed to bootstrap you into developing your own webservices.

First, go grab VirtualBox! You can find a link to download a Mac DMG here. Double-click the DMG and you’ll be presented with a window prompting you to double-click on the VirtualBox.pkg installer.


Follow each of the prompts presented to you on the screen. Once the installation is declared successful, go to your applications folder and launch VirtualBox.

Now that we have VirtualBox running, we need an OS to install! Our examples will use Ubuntu 12.04 LTS, which you will need to download from here. We’re going to use the server installer, as we don’t need a GUI. To be precise, we’ll use the 64-bit Ubuntu 12.04 Server. Clicking on this link will download an ISO image which we will give to VirtualBox to create us a Linux server on which we’ll host web services development!

In the Oracle VM VirtualBox Manager screen, click New. You’ll be prompted to identify the OS you are going to install and give it a name. We’ll use webservicedev. For Type, choose Linux, and for Version choose Ubuntu (64-bit).


You’ll then be prompted to select a memory size, for the VM, the default of 512M is sufficient for our purposes. When prompted for the hard drive settings, choose Create a virtual hard drive now. When prompted for the hard drive file type, choose VDI (Virtual Disk Image). Choose Dynamically allocated when prompted, and accept the defaults for the File location and size (8GB).

You will now see your system configured and ready to go. You need to make one adjustment here, and that is setting the initial boot device to the Ubuntu ISO image you downloaded. Select the webservicedev machine in the left-hand menu of the Oracle VM VirtualBox Manager and right click and choose Settings. You’ll be presented with a menu of settings like this:


Click the Storage icon to see:


Click on the CD Entry that says Empty, and then on the right-hand side of the window, click on the little CD next to the drop-down menu for CD/DVD Drive. Clicking on the little CD icon will give you the option to Choose a virtual CD/DVD disk file. Select this option and use the Finder navigator to where you saved the file ubuntu-12.04.2-server-amd64.iso (most likely in the Downloads folder).

One last thing, click on the Network icon at the top of webservicedev settings window. Change the value ‘NAT’ under Adapter 1 to Bridged Adapter and under name, select whichever network adapter your Mac is connected to your router on. In our example, we use Wi-Fi as the only network connection for the Mac.


Now, click on OK to dismiss the Settings window and boot your VM! Select webservicedev in the menu and click on the big green arrow that says Start. The Ubuntu installer should boot and you can walk yourself through the installer. Our example will be using English, but make selections appropriate for you!


After selecting the Language, choose Install Ubuntu Server and then follow the prompts and make the selections appropriate for your language, keyboard layout, etc. Here are the values we used when installing:

  • Hostname: webservicedev
  • Full name for the new user: webservice
  • Username for the account: webservice
  • Encrypt your home directory? No
  • Timezone: UTC
  • Guided Partitioning: use entire disk

Continue the prompts to partition the disk, if you need help or have questions about the Ubuntu installer there are plenty of guides on the web. This one you might find to be helpful. In general for development systems on your local machine, you don’t need fancy partitioning. If you find yourself as the server administrator for production servers, you might bone up on advanced partitioning schemes.

When prompted about an HTTP proxy, you most likely can leave it blank, unless you really need one (in which case you should be familiar with filling out this kind of information).

When prompted about managing upgrades and updates, choose No automatic updates (this is our personal preference).

When prompted, you will definitely want to install OpenSSH server, and you can skip the rest for now. There are number of packages we’ll install after the system initially boots.


Finally, Install the GRUB boot loader to the master boot record should be Yes. Press ENTER when you see the Installation is complete screen. Congratulations, your new VM should now be booting and momentarily you will see something similar to this:


Log in with the username and password you selected. We don’t like working in the VirtualBox screen, so we run ifconfig to find the IP address assigned to the VM, and then ssh into it with iTerm2.

Now, this VM is functional, but we’re going to be doing some web service hosting on it, and to do that we’re going to need quite a few software packages. Let’s outline what we’ll be installing and why first

  • Ruby – because our web service is written in Ruby
  • Bundler – because it is the way to manage Ruby gems in a web application
  • Passenger – because we like the Passenger module for running Ruby code in a web server
  • Nginx – because we like to run Nginx as our web server
  • GCC and make – because they are required to build modules and libraries needed by the aforementioned
  • Other development packages required by Passenger
  • Git – because we’ll need to check our code out onto the web server, and we use

Well, let’s get started. You can painstakingly type sudo before each command, but we know a lot of these commands are going to require sudo, so we’ll just switch now.

Let’s get Ruby going first.

Select Y and watch the apt-get go and fetch everything it needs to install Ruby 1.9.3 (for an explanation as why Ruby 1.9.3 is installed when running apt-get install ruby1.9.1 see here).

Now, install make and g++, and this time we’ll use the -y option to apt-get to speed things up. We’ve also included make and g++ on the same line.

root@webservicedev:/home/webservice# apt-get -y install make g++

When we install Nginx it will require a number of dependencies, so let’s get them out of the way by installing ruby1.9.1-dev, zlib1g-dev, libssl-dev, and libcurl4-openssl-dev.

root@webservicedev:/home/webservice# apt-get -y install ruby1.9.1-dev zlib1g-dev libssl-dev libcurl4-openssl-dev

Now, install the passenger gem with gem install passenger . You should see something similar to:

And before we install Nginx, install bundler too.

This one will take a while, but if you’ve followed all the steps up until now, run passenger-install-nginx-module. You will prompted to Press Enter to continue so press Enter (to continue!). You want to see

followed by Enter your choice (1 or 2) or press Ctrl-C to abort: Enter 1. The automated installer will automatically download all of the source necessary to build and install Nginx, a high performance web server. Select the defaults when prompted.

If all goes well (and why shouldn’t it, right?), you should see

That’s actually the end of this tutorial, as its sort of a small step towards getting a fully functioning web services web server running. If you really want to try things out now, go ahead and install git-core.

root@webservicedev:/home/webservice# apt-get install git-core

Then, let’s create a directory to hold our webservice code:

mkdir -p /web/apps/webservice
chown webservice.webservice -R /web/

If you are still running around as root, type exit to go back to the webservice user. Continue and check out the code:

Prepare the area to run as a Passenger application by creating a public directory and then execute bundle install:

Now, edit your nginx.conf (found in /opt/nginx/conf/, and you will need to use sudo vi) to look exactly like this (unless you know what you are doing, use the default passenger_root and passenger_ruby directives).

Start the nginx process with sudo /opt/nginx/sbin/nginx and then point your browser to the web service, for example, for us displays:


Now, for our disclaimer: this is not the way we will be deploying our web service application to the web server! We’ll be using Capistrano to deploy our applications from the Mac onto the web server. Stay tuned for that blog post.

Leave a Reply

Your email address will not be published. Required fields are marked *