For my development of Web games, I've hit a point where I need a Virtual Private Server. (For more on this see My Search for Game Hosting Begins.) I initially chose a Windows VPS because I know Windows best. A VPS is just an Internet-connected computer. "Virtual" means it may not be an actual physical computer, but a virtualized host, one of many, each running as if it were a real computer. Image (1) servers.jpg for post 1219Recently, though, I've run into a dead end, as it turns out that Couchbase doesn't support PHP on Windows. So I switched to a Linux VPS running Ubuntu server LTS 12-04. Since my main desktop PC runs Windows 7, the options to access the VPS are initially quite limited, and there's no remote desktop with a Linux server. My VPS is specified as 2 GB of ram, 2 CPUs and 80 GB of disk storage. The main problem with a VPS is that you have to self-manage it. It's maybe 90% set up for you, but you need the remaining 10%. You may have to install some software, edit a config file or two and occasionally bounce (stop then restart) daemons (Linux services), after editing their config files. If you can afford a managed service, then you can avoid all of this, but that costs extra.

Tasks To Do

Here is my list of tasks:
  • Install Couchbase
  • Install Couchbase client components
  • Set up a website, so I can upload files to it.

A Tip

Get a notebook (the paper kind) or better still, a password-protected file, and write down all of your configuration details, user names, passwords, paths, etc. If you are using long passwords, you'll definitely need to write them down. And make sure it's backed up off-site. Dropbox is good for that, and it's free for the first 2 gigabytes of storage. The best way to remote in is via SSH using Putty on Windows. This provides command line (better known as terminal in Linux parlance) access using the excellent open-source secure client. VPS Terminal Window with Putty You can also view the entire directory tree and copy/edit files using a Windows GUI open source secured application WinSCP. This is very handy if you don't like the terminal file editor Vi (or Vim), as WinSCP provides an easier way to edit config files. WinSCP My preference as a Windows developer is something GUI-ish, but I'd never used X-Server. On Windows I'd use rdp, which looks like you're logged in. For the Linux equivalent you still need a desktop, which Ubuntu server lacks. For a few seconds I did consider doing the mad thing of upgrading the server to desktop. It's easy to do, and I've done it before on a local Ubuntu box, but (a) it's not recommended on a server, (b) it eats up limited disk space, and (c) Unbuntu's official help explains why it's bad and provides some helpful hints. I decided to bite the bullet and stick to using the terminal. The VPS also comes with a copy of Plesk Parallels Panel, a Web admin package that makes it easy to configure up to 10 websites as well as monitor server resources, disk and memory used. Learn Plesk, it just makes life so much easier. vps_home


Logging in to the root account, even over SSH, is potentially a little risky. If a key-logger gets installed on my desktop PC or a hacker breaks the password, then it's game over. It's possible to configure SSH on the server to use a public key/private key for remote logging, so I'm looking into setting that up. Dyed-in-the-wool Linux users eat, breathe and drink terminal commands. I started on PCs back in the pre-Windows days when DOS command line was the only game in town, but honestly, trying to navigate around a directory tree from a command line is a bit tedious! With WinSCP, it becomes easier as you get a higher-level view of the folder structure. Now fetch the community edition of couchbase into /var/tmp with this command: wget I ran this command to install it. Note that the filenames may be different when you do this: dpkg -i couchbase-server-community_x86_64_2.0.0-beta.deb Unusually for Ubuntu, the server does have a root account, and the VPS provides you with root access, so no sudo command is needed. After that installation was done, it told me that several ports had to be opened: 11211, 11210, 11209, 4369, 8091 and from 21100 to 21299. I ran the command iptables -L to view the rules (iptables is the standard firewall), however there were no rules. Now, no hosting company would sell a VPS without a firewall, the Internet is just too much of a war zone. Hostile scripts scan blocks of Internet addresses looking for open ports and a way in to infect a machine. A VPS would be a great prize. A bit of digging in the Plesk Web interface reveals that it was monitoring the server and had 23 firewall rules. I know that the admin port for Couchbase (8091) was working, because I was able to log in to set up a bucket (a unit of storage equivalent to a database in a relational database). I wasn't greatly bothered by the other ports, as they're mainly needed for Couchbase replication, and for now there's just the one VPS. Next add the Couchbase client components needed for PHP to access the database. This also needs the C client as well. For more details, see my article on How to Set Up Couchbase on a PHP Website.

Setting up the Website

The last step is to point the DNS for my domain to the server, then add the domain in Plesk and create a website. Plesk also lets you set up FTP access to each website, and basically that's it. Now you just upload the site's files. One interesting thing I noticed: Each PHP page has code to see how long it takes to build a page on the server. Add this php at the top of the page: $pst = microtime(true); And this at the bottom, which then outputs the time it took: <?php echo number_format(microtime(true)-$pst,6);?> Secs Interestingly, the Linux VPS seems about 10 times faster than the same spec Windows VPS. It takes typically under a millisecond for pages without database access. Of course, compressing the page's html, JavaScript, etc, then sending it across the Internet to be decompressed by the browser and rendered usually takes hundreds of milliseconds or longer.

It's Never Over

Now that it's set up, you can't just ignore it. If you do, your website or worse your VPS may eventually fall over. Plesk auto-upgrades itself, and on the Windows VPS, that used to break a website. I was using PostgreSQL, and with every new update of Plesk, the PostgreSQL drivers were unhooked. It's also a good thing to check logs to see whether anybody's been trying to hack in. There's a whole host of things you should do. You could start by reading my article on Best Practices on Web Game Development, particularly the link to near the end.