How to Use a Linux Virtual Private Server

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

Security

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 http://packages.couchbase.com/releases/2.0.0-beta/couchbase-server-community_x86_64_2.0.0-beta.deb

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 stackexchange.com near the end.

Comments

  1. BY Dr. Zoidberg says:

    You’r post is bad and you should feel bad.

    Not only do you clearly know next to nothing of the tools you are going to be attempting to leverage but you also feel that not using google or wikipedia is the right way to solve this.

    Most people actually learn what the hell it is they are trying to do, try it then if they fail ask for help. You seem to have skipped the “doing something” part and gone strait to the complaining.

    Next time before complaining that you need help, maybe you should figure out just what it is you are supposed to be doing in the first place. Then if it is not working out, go from there.

    • BY David Bolton says:

      I hope you’ll see there are some good parts that you would agree with. I didn’t install a GUI, I did recommend Putty and WinSCP (for Windows) users. Which parts did you feel were bad? Have I given out bad advice that you don’t like? I am still learning, and welcome any tips you have to help me improve my Linux knowledge and administration.

      David

      • BY Lester Jensen says:

        David,
        Don’t take the poison dart from Zoidberg seriously. Unless we are talking about Futurama, the clue should be the “Dr.” in front of their name – another damn expert looking down their noise at the poor simpletons (“Dr.” only has relevance when speaking in your field – otherwise it’s just plan snobbish). I’d suggest they take their arrogant sorbic comments elsewhere. I appreciate that you were only trying to help and sharing your experience for what it is worth. For those that don’t find it of value they can either offer helpful suggestions/observations (so we can all work together, learn and grow) or else keep their pie-hole shut!

  2. BY Dennis says:

    I just want to say I hate it when people bash just to bash. Be constructive not destructive about his post. If not your just a turd!

  3. BY W. Anderson says:

    There are a couple of changes in configuration I would suggest, particularly for Windows PC user to remote Linux server.

    1. Consider installing Webmin – a server administration application acessed via client browser that eases several server configuration chores from Windows Desktop.

    2. A GUI Windows client to consider is NX that is very similar to RDP in regard full desktop GUI capabilities.

    The critical requirements are understanding and learning to use UNIX/Linux tools which provide a great deal of proficiency and flexibility for such task described.

    Getting totally away from the Microsoft Windows mentality of insisting on and prefering only the brain-dead GUI tools that are generally very inflexible and provide one task per tool will be agonizing and inefficient.

  4. BY mrg says:

    Webmin
    http://linuxhomeserverguide.com/server-config/Webmin.php

    and X11 forwarding…
    http://tldp.org/HOWTO/XDMCP-HOWTO/ssh.html

    If you really must you could setup a ‘virtual desktop’ and vnc to it. I certainly don’t recomend this method though.
    http://www.havetheknowhow.com/Configure-the-server/Install-VNC.html
    If you do make sure you tunnel your vnc connection through ssh…

    your options are myriad.

  5. BY dan says:

    David!
    Thanks for act and hope that you continue .I love it and enjoy reading but dont have
    all the components to practice.Please recommend the lowest and best possible self started
    hands on.

  6. BY Linux VPS says:

    I didn’t know about this but it is a soultion one of my technical problem concerned with my VPS. I would like to thank you.

  7. BY Brian says:

    Quite a number of hosting companies will in fact sell a VPS without any firewall rules enabled in my experience. You may want to check and make sure the firewall module in Plesk is turned on, as from what I recall Plesk uses iptables, so running “iptables -L” and not getting any rules in the return output would mean that the firewall is not active.

  8. BY Ryan Grange says:

    I recently set up a virtual Linux desktop and installed XRDP ( http://www.xrdp.org/ ) on it as a test. It worked really well. My next step is to try to tie it to a Windows Domain login and see if I can provide an on-demand virtual desktop to outside contractors who need a desktop connected to in-house resources rather than having to set up a physical system for them.

Post a Comment

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>