FreeBSD

All posts tagged FreeBSD

lowendbox.com has some pretty amazing deals on VPS servers. One in particular that jumped out at me was a 128MB  / 10GB disk / 500GB bandwidth per month OpenVS server from DotVPS for only $15.00 per year.

 [OpenVZ] 128MB RAM
 128MB RAM
 128MB Burst/vSWAP
 1 vCPU core
 10GB Diskspace
 500GB Bandwidth
 OpenVZ/SolusVM
 1 IPv4 Address
 5 IPv6 Address (UK)
 1Gbit port
 $15/Year

I was skeptical about a server this small being capable of hosting a WordPress powered site, but with a few tweaks I got it working perfectly. Here is how you can do the same, save yourself a ton of cash, and learn some awesome open-source goodness in the process.

1) Register a domain name. Registering your own domain name costs almost as much as the VPS server itself but I highly recommend getting one. You can do some neat things with a virtual hosts on your VPS server, but if your just getting started and want to play around with a VPS without committing to a name yet, you can skip this step for now and come back to it later. I use and highly recommend namecheap.com for all your domain registration needs.

2) Order your VPS server. If you haven’t done so yet use this link to order your VPS from DotVPS, or a similar VPS provider. This article is based on what I was provided – a 32 bit CentOS 5.8 powered Linux server. I’ll be using yum for installing all the packages. Debian based VPS’s are going to use apt-get and probably have different package naming schemes so ymmv.

3) Login as root and get to work installing packages. This is where the fun begins. If at any point you screw up so badly and you need to start over, you can login to your control panel and hit ‘reinstall’ to start from scratch. Fire up your favorite ssh client and login to your new server using the IP address, username and password established during setup.

First off, my server had apache2 pre-installed and already running. Apache is great, but I’m working with 128MB of RAM and need to conserve as much of it as possible. For my blog, I decided to use nginx along with an alternative php processor, php-fpm. Both of these projects are focused on 2 things that are very important – high performance and low memory consumption. A winning combination for a micro VPS server. I could have used lighthttpd instead but nginx is something I had no experience with and I’m always up for learning something new.

Kill off apache with:

service httpd stop

chkconfig httpd off

Next, enable a couple of extra repositories from Remi and EPEL to get access to nginx and php-fpm:

rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm

Now install nginx and php-fpm with:

yum –enablerepo=remi,remi-test install php-pecl-apc php-cli php-pear php-pdo php-mysql php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml

When its all done, fire up nginx, php-fpm, and set them to both start when the system comes up:

service nginx start
service php-fpm start
chkconfig nginx on
chkconfig php-fpm on

Yeah. Its that simple. You can fire up a web browser at this point and take a look at the default nginx welcome page using your server’s public IP address.

Now its time to install MySQL, start MySQL, and set it to start on boot:

yum –enablerepo=remi,remi-test install mysql mysql-server

service mysqld start
chkconfig mysqld on

Before you continue lets drop in a replacement mysql.conf file optimized for small memory systems:

cp /etc/my.cnf /etc/my.cnf.original

cp /usr/share/doc/mysql-server-5.5.32/my-small.cnf /etc/my.cnf

Then start the secure setup of MySQL. The default password for root is blank, so just hit enter when prompted and set a new one. You can say Y to everything else:

/usr/bin/mysql_secure_installation

Now we have nginx, php-fpm, and MySQL all setup and ready to go. Only 2 more steps remain. Setup nginx virtual-hosts and install WordPress.

Lets start with getting your virtual host setup. There are a couple of values you should define before going much further – the name of your site (most likely your domain name if you registered one), and the name of your database and user account that will connect to that database. You will want to have a new one for each virtual host you are hosting. You will also want to update the DNS A record for your domain to point to your VPS server’s IP address. When I did this with my provider, namecheap.com, the update was almost instant. When a http request is sent to your VPS, nginx looks at the host-header, looks up what virtual host is responsible for the content, and sends over the request. This makes is possible to host dozens of different websites using a single VPS server.

For my example, I’m using:

jasonoconnell.com as my domain

jasonoconnell as my web root

wordpress as my database name

wpuser as my wordpress DB username

wppass as my wordpress DB user’s password

Setup public_html and log directories for your new virtual host:

cd /var/www
mkdir -p jasonoconnell.com/{public_html,logs,stats}

Create a new config file for your virtual host:

vi /etc/nginx/conf.d/jasonoconnell.conf

Mine looks like this:

server {
listen 80;
server_name jasonoconnell.com www.jasonoconnell.com;

access_log /var/www/jasonoconnell.com/logs/access.log ;
error_log /var/www/jasonoconnell.com/logs/error.log ;

location / {
root /var/www/jasonoconnell.com/public_html;
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?q=$1 last;
break;
}

}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/jasonoconnell.com/public_html;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
root /var/www/jasonoconnell.com/public_html;
fastcgi_param SCRIPT_FILENAME /var/www/jasonoconnell.com/public_html$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\.ht {
deny all;
}
}

You can test if its working by dropping in an index.html file under your virtual hosts public_html directory, restarting nginx, and looking for a response. You can take that a step further and also check to make sure php is working by creating a file called info.php with the following:

<?php
phpinfo();
?>

Point your browser at domain.com/info.php and you should see a bunch of info on your php install.

Last step, install and configure WordPress.

cd /tmp

wget http://wordpress.org/latest.zip

unzip latest.zip

mv wordpress/* /var/www/example.com/public_html/

rm -rf wordpress latest.zip

Connect to MySQL and setup the DB for WordPress:

mysql -u root -p
mysql> CREATE DATABASE wordpress;

mysql> GRANT ALL PRIVILEGES ON wordpress.* TO “wpuser”@”localhost” IDENTIFIED BY “wppass”;

mysql> FLUSH PRIVILEGES;

mysql> EXIT

Now tell WordPress how to connect to your DB. You only need to modify 3 values in the config file: DB_NAME, DB_USER, and DB_PASSWORD:

cd /var/www/jasonoconnell.com/public_html

cp wp-config-sample.php wp-config.php vi wp-config.php

// ** MySQL settings – You can get this info from your web host ** // /** The name of the database for WordPress */ define(‘DB_NAME’, ‘wordpress’);
/** MySQL database username */

define(‘DB_USER’, ‘wpuser’);

/** MySQL database password */ define(‘DB_PASSWORD’, ‘wppass’);

That’s it, your done! If all went well you should be able to type in your domain name and get to your new self-hosted WordPress site. Walk through the simple setup and you can start blogging away. In my next article, I’ll walk you through setting up Google AdSense to try and make back the $30 you just spent 🙂

 

A few years ago I built a full-size MAME cabinet. At its core is an old Gateway G6 Pentium 2 running Windows 98. I’m lucky it still powers up. Knowing failure is imminent I needed to find a replacement.

I started experimenting with the Raspberry Pi a few months ago. First I built a XBMC media server but it never performed as well or could steam back as many formats as my HP MicroServer with XBMC. So next I built a music streaming device I could plug into anything and stream music to it from my PC or iPad. Ok well thats cool, but what else is there? Turns out there are lots of working emulators for the Pi, including MAME.

Getting MAME installed on the Pi was too easy. Download Raspbian, fire up the Pi Store, install MAME, copy in a couple of ROMs, done. A couple of Google searches later I had bluetooth working, CWiid installed, and was able to discover Wiimotes.

2013-07-16-20-04-27

What I wasn’t able to find was the magic glue that takes the Wiimote’s output and turns it into a key press that MAME can interprate. In about an hour I had the solution, wminput. wminput lets you map a button on the Wiimote to a keypress in any app. A few tweaks to a config file and I had a fully working Wiimote controller for MAME.

This is my mameplayer1 key definition file:

# mameplayer1
# buttons
Wiimote.A = KEY_LEFTSHIFT
Wiimote.B = KEY_SPACE
Wiimote.Up = KEY_LEFT
Wiimote.Down = KEY_RIGHT
Wiimote.Left = KEY_DOWN
Wiimote.Right = KEY_UP
Wiimote.Minus = KEY_5
Wiimote.Plus = KEY_1
Wiimote.Home = KEY_ESC
Wiimote.1 = KEY_LEFTCTRL
Wiimote.2 = KEY_LEFTALT
Plugin.led.Led1 = 1

And here’s how you kick off wminput:

wminput -c /usr/local/bin/indiecity/InstalledApps/mame4all_pi/Full/mameplayer1 -d &

To sync your Wiimote, just hit buttons 1 + 2 at the same time. All the blinky lights should flash for a few seconds, followed by Led1 staying solid blue.

Then you can fire up MAME:

/usr/local/bin/indiecity/InstalledApps/mame4all_pi/Full/
./mame

and your off. If you used my config, all Wiimote buttons should work inside MAME, even home will get you back to the main screen.

One last step. I like purpose-built stuff. You plug it in, it does a job. Since eventually this rig will live inside a cabinet I need complete automation. In Debian Linux this can be accomplished (somewhat hackingly) by editing /etc/rc.local, and making it executable so Raspbian’s init system will invoke it on boot. This will accomplish 2 things:

1) Start wminput in daemon mode with a config file specifically built for MAME, and

2) Launch directly into MAME4All.

In my /etc/rc.local, I call another script that starts the wminput daemon and fires up MAME. That way MAME is ready and waiting for you to sync your Wiimote and chose a ROM to play:

/usr/local/bin/indiecity/InstalledApps/mame4all_pi/Full/mame-wii.sh

And here’s mame-wii.sh:

#!/bin/bash
wminput -c /usr/local/bin/indiecity/InstalledApps/mame4all_pi/Full/mameplayer1 -d &
cd /usr/local/bin/indiecity/InstalledApps/mame4all_pi/Full/
./mame

So with a little digging I’ve built a really awesome little emulation station that consumes a fraction of the amount of power my PII Gateway does and is completely silent, oh and until it does get moved inside my cabinet, I can use a Wiimote to play Turtles!

2013-07-16-19-59-55

I hate Lotus Notes. It sucks.

That said, heres how to make it work on Ubuntu Feisty Fawn:

Since Edgy’s release /bin/sh has been symlinked to /bin/dash. To make the installer work correctly you need to link sh to bash. We will switch it back when we are done.

sudo ln -sf /bin/bash /bin/sh

Next, we need to create and set perms on the destination install dirs.

sudo mkdir -p /opt/downloads /opt/IBM/Workplace Managed Client
sudo chown $USER.$USER /opt/downloads
sudo chown $USER.$USER /opt/IBM/Workplace Managed Client

Download mozilla w/GTK2 bindings and place it in /usr/local/mozilla:

cd /opt/downloads
wget
http://releases.mozilla.org/pub/mozilla.org/mozilla/releases/mozilla1.7.12/contrib/mozilla-i686-pc-linux-gnu-1.7.12-gtk2+xft.tar.gz
tar zxvf mozilla-i686-pc-linux-gnu-1.7.12-gtk2+xft.tar.gz
sudo mv mozilla /usr/local

Create the file /etc/gre.conf with the following inside:

[1.7.12]

GRE_PATH=/usr/local/mozilla

Grab the client files. I have no idea where you can get these if you
don’t have a Notes administrator at your disposal. Luckily I do. If you
don’t, try a torrent site. The file should be called C93D1NA.zip. Put
it in your /opt/downloads dir.

unzip /opt/downloads/C93D1NA.zip -d notes
cd /opt/downloads/notes
unzip Personality.zip
chmod 755 setuplinux.bin setup_wct_platform.bin
cp setuplinux.bin updateSite/features/com.ibm.workplace.notesinstall.linux.feature_7.0.1.0000-0900/bin/linux
./setup_wct_platform.bin

The setup wizard should run and install to the location we created
earlier. When its done it will start the client with 2 blank panes.
Exit now and create the following script in your home directory:

notes.sh

#!/bin/bash

. $HOME/.bash_profile

/opt/IBM/Workplace Managed Client/rcp/richclient -personality com.ibm.workplace.noteswc.standalone.linux.personality

Make executable and replace the ‘target’ of the notes shortcut on your desktop to point to this script instead.

I had to copy my Notes ID from my Windows PC to the linux box, fill in
the deatils about my domino server, and I was in business!

Switch back the dash symlink.
sudo ln -sf /bin/bash /bin/dash

(Lotus Notes still sucks tho)

Not comparing apples to apples here, but my initial benchmarks turned up some interesting results.

Linux box ripon:
ab -n 1000 -c 5 http://ripon/snkpage.html

Server Software: Apache/2.0.46
Server Hostname: ripon
Server Port: 80

Document Path: /snkpage.html
Document Length: 187 bytes

Concurrency Level: 5
Time taken for tests: 0.275 seconds
Complete requests: 1000
Failed requests: 0
Broken pipe errors: 0
Total transferred: 451000 bytes
HTML transferred: 187000 bytes
Requests per second: 3636.36 [#/sec] (mean)
Time per request: 1.38 [ms] (mean)
Time per request: 0.28 [ms] (mean, across all concurrent requests)
Transfer rate: 1640.00 [Kbytes/sec] received

Connnection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 3
Processing: 0 1 0.2 1 4
Waiting: 0 0 0.1 0 3
Total: 0 1 0.2 1 4
WARING: The median and mean for the waiting time are not within a normal deviation
These results are propably not that reliable.

Percentage of the requests served within a certain time (ms)
50% 1
66% 1
75% 1
80% 1
90% 1
95% 1
98% 1
99% 1
100% 4 (last request)

FreeBSD box mitnick:
ab -n 1000 -c 5 http://mitnick/snkpage.html

Server Software: Apache/1.3.34
Server Hostname: mitnick
Server Port: 80

Document Path: /snkpage.html
Document Length: 187 bytes

Concurrency Level: 5
Time taken for tests: 0.581414 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 467000 bytes
HTML transferred: 187000 bytes
Requests per second: 1719.94 [#/sec] (mean)
Time per request: 2.907 [ms] (mean)
Time per request: 0.581 [ms] (mean, across all concurrent requests)
Transfer rate: 784.29 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 2
Processing: 1 2 0.7 2 7
Waiting: 0 1 0.8 2 6
Total: 1 2 0.7 2 7
WARNING: The median and mean for the waiting time are not within a normal deviation
These results are probably not that reliable.

Percentage of the requests served within a certain time (ms)
50% 2
66% 2
75% 3
80% 3
90% 3
95% 3
98% 4
99% 4
100% 7 (longest request)

How can that be explained?