Installing PHP5.3 on Ubuntu Karmic

Following my previous post about installing PHP5.3 on Jaunty, I have had a few requests about installing it on Karmic. I’ve never used Karmic before so I thought it would be a fun excuse to have a poke about whilst also keeping my blog (sort of) up-to-date.

After freshly installing Karmic (the desktop version looks very nice btw) on a new VirtualBox image and then updating with the latest, er, updates I was ready to begin.

The entire installation procedure is very simple, once all dependencies are met.

Firstly you must edit your sources list to include the DotDeb package repository and the old Jaunty security packages to meet dependencies.

$ sudo nano /etc/apt/sources.list
# php5.3
deb http://php53.dotdeb.org stable all
deb-src http://php53.dotdeb.org stable all
deb http://security.ubuntu.com/ubuntu jaunty-security main

Now update and upgrade Ubuntu

$ sudo apt-get update
$ sudo apt-get upgrade

You may find that you get the following warning:

WARNING: The following packages cannot be authenticated!
libevent-1.4-2
Install these packages without verification [y/N]?

I just answered Y and continued as normal

Once successfully upgraded then you can install Apache, MySQL and PHP as normal, feel free to cater the installation line to your tastes.

$ sudo aptitude install libicu38 apache2 apache2-mpm-prefork mysql-client-5.1 mysql-server-5.1 php5 php5-cli php5-mysql libapache2-mod-php5

You will get a warning about untrusted packages being installed but this simply means that the PHP5.3 stuff is not signed, so I typed in “yes” and carried on.

Robmorin commented in my Jaunty post that he had issues when installing PHP MCrypt. The answer can be found within the DotDeb comments

After you have installed everything you need to, test it out, either command line:

$ php -v
PHP 5.3.2-0.dotdeb.1 with Suhosin-Patch (cli) (built: Mar  9 2010 10:14:53)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies with Suhosin v0.9.29, Copyright (c) 2007, by SektionEins GmbH

Or by using phpinfo() page within your Apache installation:

$ sudo nano /var/www/info.php

<?PHP
phpinfo();
?>

then fire up http://localhost/info.php and at the top of the page you should see something along the lines of
PHP Version 5.3.2-0.dotdeb.1

Note: if your browser asks if you want to download info.php, simply restart Apache and try again:

$ sudo /etc/init.d/apache2 restart

All done. Not quite as simple as on Jaunty, but still better than compiling the source!

Post Script: Before starting this post, I did a quick search looking for tutorials to see if the work had already been done, but couldn’t find anything on installing PHP5.3 on Karmic. As there wasn’t anything I decided to continue with my tutorial and I ended up struggling for an hour or so with the dependency issues. Typically, after I had figured it out for myself, whilst searching for another dependency issue I found this post on the JMOZ blog about installing PH5.3 on Karmic Koala.  No idea why it’s not in Google, but either way, damn, I could have saved myself an hour or so!

My Perfect Desktop – Day 0

Today is an exciting day. I have in my possession a brand new custom built computer to use exclusively at the office. I currently use the laptop for both home and office work, but since the laptop is getting a bit old and computer components are so cheap these days I decided to build a work station just for me to use at the office. The best thing is that as it is custom built I can put whatever I damn well want on it – no pre-installed Windows or anything else. I can make it absolutely perfect for me.

I’ll be documenting here in my blog exactly the steps needed to take it from a tabula rasa to my perfect desktop system.  Apart from the system being obviously Linux based, there will be a number of things to consider before I get started. If I want it to be perfect, I need to think about what it is that I really need and want from a work only system. So, after a brainstorm this is the breakdown of what I require:

  1. Keyboard Friendly

    I am becoming less interested in using the mouse. This is for a number of reasons, firstly it is quicker to keep your hands on the keyboard rather than always having to find the mouse and point and click. Secondly, using the mouse greatly exacerbates RSI and all that jazz. As such a system designed for maximum keyboard usage is important.

  2. Great Web Development Tools

    As a web developer this is a no brainer. I need to be able to have the tools for developing websites, testing (at code, server and client level) deployment and client side version control.

  3. Base system should be small, quick and light

    Due to point 2, I can see the need for being able to have virtualised instances of Windows running, each running a different version of IE. As such, the base system should be as small, quick and light as possible so it doesn’t get bogged down when I have one (or more) windows running for testing purposes.

  4. Communications

    I have to be able to email, chat, and talk with people via my computer

  5. Music and sound

    I need to listen to music at work!

  6. Must get on with others

    Some strange people out there still use propriety software. My system needs to be able to read Word and Powerpoint and all that stuff.

  7. Not be rude

    This is a strange request, but over the weekend I had a friend staying who is an IT administrator for a large international company. He had to do some work on their Windows based infrastructure, so he powered up Vista on my laptop (which I never use*) to log into their systems via the Remote Desktop. Half way through he had to make a couple of calls. When he came back Vista had rebooted and he had lost everything. We narrowed it down to the fact that Vista had updates, installed them and rebooted without even asking for permission. IMO, that is really fucking rude.

  8. Stable

    Last, but by no means least, the system has to be solid. I can’t have it crashing on me every hour.

And that is pretty much it. Follow me over the next week or so whilst I sort out my ideal perfect work station.

* I just had to make that point

Building My Perfect Desktop

IE 7 indexOf() Replacement

Everyday I hate IE a little bit more, and by the same token, everyday I love jQuery that little bit more.

The reason for my hate/love feelings today was due to a bug caused by IE 7 not supporting the indexOf() method. I have no idea why IE doesn’t support this method, but it is annoying never-the-less. However, there is an easy fix if you are using jQuery – the inArray() function.

The inArray() function is pretty simple to use.

Instead of having:

haystack_array.indexOf("needle")

You should use:

jQuery.inArray("needle", haystack_array)

For those of you crazy nutters that aren’t using jQuery, there is a good post on this blog that will help you out.

Converting from Mac to Unix line endings

This is more a post for me than anyone else, but I thought I’d share anyway.

In our team we have a mixture of Linux and Mac users, and we are constantly editing the same files. One of the most irritating things is when a file is saved with Mac line endings instead of Unix line endings (displaying as ^M in Emacs). This happens very rarely, but on the occasion it does I can quickly convert back using the following commands on my Linux box:

$ tr 'r' 'n' < file-in-question.txt > tmp.file
$ mv tmp.file file-in-question.txt

Works perfectly

If you want to find more about the tr (Translate) program, visit the man page.

Site was Cracked

Some of you may have noticed I’ve been gone for a few months. More on that later. However, whilst I was away I found out that this site was cracked!

My apologies to any of you who were affected by this. I have taken steps to ensure this won’t happen again.

I’ll be back soon with more writing on PHP, JavaScript, Ubuntu and other Linux Distros and the fantastic Awesome Windows manager, I promise!

Understanding Bitwise Operators (hopefully)

After the trouble I had with bitwise operators yesterday I found some time to really sit down and get my head properly around them. Let’s dive straight in.

We need to initially define our flags:

define('BASE', 0); // binary 00000000
define('F1', 1);   // binary 00000001
define('F2', 2);   // binary 00000010
define('F3', 4);   // binary 00000100

To start with we have no flags set, so if we set F1 using the following:

$f1_set = BASE + F1; // $f1_set = 1
echo "F1 set = $f1_setn";

All is well and good, $f1_set = 1 as expected.

However, what if we set F1 again?

$f1_set_twice = $f1_set + F1; // $f1_set_twice = 2 !!! wrong !!!
echo "F1 set twice = $f1_set_twicen";

As you can see, if we set F1 twice, it effectively “unsets” F1 and sets F2. Not what we were after.

So why is this? Well, it’s kind of obvious and I was being a bit of a muppet for not spotting it yesterday. The reason is pretty simple: 1 + 1 = 2. (I told you it was obvious!)

Clearly this is not what we want, but how can we solve this? By using the bitwise OR. If we change the statements slightly as follows:

$f1_or_set = BASE | F1; // $f1_or_set = 1
echo "F1 OR set = $f1_or_setn";
 
$f1_or_set_twice = $f1_or_set | F1; // $f1_or_set_twice = 1 - huzzah!
echo "F1 OR set twice = $f1_or_set_twicen";

As far as “unsetting” the flags if we use my original method we fall (again) into trouble.

$f1_and_f3 = BASE | F1 | F3; // $f1_and_f3 = 5;
$unset_f3 = $f1_and_f3 - F3; // $unset_f3 = 1
echo "Unset F3 = $unset_f3n";
 
$unset_f1 = $f1_and_f3 - F1; // $unset_f1 = 4;
echo "Unset F1 = $unset_f1n";

Now, if we try to “unset” F1 twice, we arrive at the problem.

$unset_f1 = $f1_and_f3 - F1; // $unset_f1 = 3;
echo "Unset F1 = $unset_f1n";

Unsetting F1 twice here effectively turns off F3 and sets F1 and F2 – completely wrong!

Instead, if we use the &~ binary operator mentioned in Jesper’s comment all works as expected. (note: I can’t find mention of this operator in the PHP docs, please someone help me out)

$f1_and_f3 = BASE | F1 | F3; // $f1_and_f3 = 5;
$unset_f3 = $f1_and_f3 &amp;~ F3; // $unset_f3 = 1
echo "Unset F3 = $unset_f3n";
 
$unset_f1 = $f1_and_f3 &amp;~ F1; // $unset_f1 = 4;
echo "Unset F1 = $unset_f1n";

Even if we try to “unset” a flag twice, it still has the same results:

$unset_f1 = $f1_and_f3 &amp;~ F1; // $unset_f1 = 4;
echo "Unset F1 = $unset_f1n";
 
$unset_f1_twice = $unset_f1 &amp;~ F1; // $unset_f1_twice = 4;
echo "Unset F1 twice = $unset_f1_twicen";

Also in Jesper’s comment and original post was the use of the left shift operator: <<. After playing around with this it seems very simple to use, as follows:

$f1 = 1;    // 00000001
$f2 = 1<<1; // 00000010
$f3 = 1<<2; // 00000100
$f4 = 1<<3; // 00001000

Or to put it another way:

$f1 = 1;      // 00000001
$f2 = $f1<<1; // 00000010
$f3 = $f2<<1; // 00000100
$f4 = $f3<<1; // 00001000

After all this I think I am a little closer to understanding Bitwise operations, hopefully! Tomorrow I’ll have a crack at testing to see if a flag is turned on or not. Until then…

Bitwise Operators used for Flagging Items

Update: Thanks to Jesper Noehr of BitBucket fame for pointing out gaping flaws in my post below (see his comment). I strongly advise you disregard all I have said below, because it will get you into a mess, in much the same way it has me. I’m going to sit down when I have a spare 1/2 hour and try to work out exactly what is going on! Many thanks and big kudos to Jesper, I really appreciate the time you took to correct me.


I have always wondered what the point of Bitwise Operators were,to me they seem to belong to a distant past. However, after reading a couple of great blog posts I have at last an understanding of how they can be put to use, and have started playing around with them a bit (ba dum!).

Jesper Noehr has written about using bitwise operators for a flexible permissions scheme within Python  and Jonathan Snook has taken the bitwise concept further creating a great calendar app in Javascript. After reading these I thought I better dive in, and an opportunity came along yesterday when I had to code a flagging system within PHP.

(more…)

First Steps with Node.js: exciting stuff

If you are looking for a NodeJS tutorial, visit this post: NodeJS Tutorial with CouchDB and Haml.

During my Saturday morning reading yesterday I fell over something called Node.js.  According to the website

Node’s goal is to provide an easy way to build scalable network programs.

which is kind of exciting, but not mind blowing, however, Ryan Dahl’s GitHub page describes it as

evented I/O for v8 javascript

Which is slightly more exciting. However, it is when you start to play around with it that things begin to get very exciting indeed.

(more…)

3 days without the Interwebs

We had a bit of a nightmare over at ibrow Towers recently. Some bright spark at the building site down the road managed to cut the pipe supplying our interweb!

Disaster!

Fortunately the culprit managed to refrain from slicing all the way through, stopping just at the point to give us the drip feed equivalent of roughly a modem circa 1997. i.e. r e a l l y slow.

Did we really ever live with that? How did we cope?

But now it is the weekend, meaning that I have some spare time at home to explore the internet again. So here are a few links that I’m going to spend my morning reading.

(more…)

RobSearles: 1 Year Old!

This is just a quick post to say Happy Birthday this blog. Yes, I began my little journey into the Blogosphere one year ago today. Looking back on that first article, now is a good time to see if I managed to stay focused on the topics that I laid out in the beginning, as well as looking at some stats for the year and why I’m doing this.

(more…)