Intro to hosting on a VPS

Why and What is a VPS

NOTE: these are just some notes from a little tutorial I ran, don't rely on this as being complete


  • a virtualized "slice" of a fullsize server
    • Performance depends on disk speed and overprovisioning of CPU resources
  • a small free standing server


  • Pros
    • Managing it yourself
    • Cheap, between $5 & $20/month
    • potential for higher performance and scalability
    • host many low-traffic sites on one machine
    • freedom to choose your own "stack"
    • Your web performance is not effected (as much) by overloading of shared hosting.
    • Run your own monitoring
    • Accessing your own logs - privacy, privacy, privacy
    • Learning experience, how does the underlying technology work? Debugging, whats wrong with your code/app
  • Cons
    • Managing it yourself
    • You, and you alone are responsibe for backups
    • You, and you alone are responsibe for security
    • You, and you alone are responsibe for uptime

VPS providers

Linux command line basics

# make dir
mkdir foo

# Change directory
cd foo

# Whats my current directory?

# 'list' all files in the current directory
ls /var/tmp

# create an empty file
touch somefile.txt

# edit a file, (add a few lines of random text into it)
nano somefile.txt

# print the last few lines from a file
tail somefile.txt

# copy a file to another place
cp somefile.txt someotherfile.txt

# delete a file
rm somefile.txt

# move or rename a file
mv someotherfile.txt somefile.txt

Add user for security

For security reasone we want to prevent the root users from allowing to log in over ssh, therefore we will create a new users, grant him sudo privileges and reconfigure sshd

# add new user
useradd -d /home/madmaze -m -s /bin/bash madmaze 

# give it a password
passwd madmaze

# give the user sudo permissions
usermod -a -G sudo madmaze

# edit /etc/ssh/sshd_config
PermitRootLogin no
AllowUsers madmaze

# restart SSH after changing settings
service ssh restart

# test that you cant log in as root

Installing the basics (LAMP)

LAMP = Linux Apache MySQL PHP

# Update/upgrade
sudo apt-get update
sudo apt-get upgrade

# Installing Apache
sudo apt-get install apache2

# test apache at http://localhost

# Installing PHP
sudo apt-get install php5 libapache2-mod-php5

# test php is working

# Installing mysql
sudo apt-get install mysql-server php5-mysql

# restart apache
sudo service apache2 restart

# test php is working with mysql

Installing wordpress

# download WP
cd /var/www
sudo wget

# unpack wordpress
sudo tar xvf latest.tar.gz

# setup MySQL database user

#log into mysql
mysql -u root -p

#create new user
create user 'dbuser'@'localhost' identified by 'somepass';
create database wpdatabase;
grant all privileges on wpdatabase.* to 'dbuser'@'localhost';

# allow wp installer to write to wp-config.php
chmod 777 wp-config.php

# run the wp installer

Technologies to choose from:

  • Webserver
    • Apache
    • lighttpd
  • Database
    • mysql
    • sqlite
    • postgres
    • etc etc etc...
  • php
  • monitoring
    • vnstat
    • nmon
  • Connection Methods
    • ssh
    • scp
    • rsync
    • sftp


  • Single Server Configuration
    • point DNS/Domain at your IP address
  • Virtual hosts (multiple domains on one server)

Securing the VPS

  • ssh password
    • ssh keys
  • fail2ban

backing up

  • rdiff-backup


  • nagios