Category: Technology


Well yesterday I made one of the biggest purchases I have to date (not far behind my house, car etc)!! I have many computers in my house and have owned many computers over time but nothing beats the awesomeness of Apple’s hardware design! – I forked out and bought an iMac (the most expensive computer I have personally owned! :) ) and first one that I have not built myself…

Check out this beauty..

Unline many linux distrubutions FreeBSD by default disables ‘root’ login over SSH (at least it does with FreeBSD 8.2), If you do need to enable remote root logins over SSH this simple blog post will show you what you need to do; the more secure way of gaining remote admin access to your server would ideally be logging in as an alternative user and then using SUDO to perform any administrative tasks.

Firstly, You will need to edit the SSH daemon configuration file to enable this like so..

ee /etc/ssh/sshd_config

Find this line:

#PermitRootLogin no

and change it to:

PermitRootLogin yes

Basically you should have removed the hash ‘#’ from the start of the line (uncomment the line basically) and then change ‘no’ to ‘yes’, save the file and then restart the SSH daemon like so..

/etc/rc.d/sshd restart

…and your done, you should now be able to login as ‘root’ over SSH on your FreeBSD server!

In this easy to follow tutorial I will show you how to install Apache, PHP and MySQL on FreeBSD, I have used FreeBSD 8.2 in this tutorial but should work for at least a couple of release’s later.

I will be installing the software using FreeBSD ‘Ports’ you can also install software on FreeBSD using the pkg_add system but this is not covered in this tutorial!

First of all we make sure that you have the latest snapshot of the FreeBSD ports collection, do this by running:-

portsnap fetch

and extract the infomation like so..

portsnap extract

If you already have the ports setup, you can just run portsnap update instead..

First up we are going to install MySQL, so lets begin with logging into your FreeBSD server and running this command:

cd /usr/ports/databases/mysql55-server

make BUILD_OPTIMIZED=yes BUILD_STATIC=yes

make install clean

The first command above changes the current directory to the MySQL server ports folder, the next adds some build parameters and the last command installs and cleans up any debris :)

Now we want to add MySQL as part of the startup process so when the server re-boots the MySQL daemon will run..

Open /etc/rc.conf with your editor and add the line shown below to enable starting mysql server on boot.

mysql_enable=”YES”

Now to start MySQL for the first time run this command:

/usr/local/etc/rc.d/mysql-server start

We need to now set a password for the MySQL root user by executing..

/usr/local/bin/mysqladmin -uroot password ‘new-password’

MySQL is now installed and ready to be used!

Now we need to install and configure Apache..

cd /usr/ports/www/apache22

make install clean

..again, lets add Apache to the system startup process in the same way that we did for MySQL..

apache22_enable=”YES”

Thats it, the basic Apache22 package is now installed!

Now we install PHP5 and configure it for use with Apache..

Go to the php5 port directory by typing the command:

cd /usr/ports/lang/php5

Build and install the port by typing

make install clean

Make sure the APACHE (Build Apache module) option is ticked when configuring the build

cd /usr/ports/lang/php5-extensions

make install clean

Now, copy the default PHP.ini file so we can use it for our new installation..

cp /usr/local/etc/php.ini-dist /usr/local/etc/php.ini

Edit your Apache configuration file (/usr/local/etc/apache22/httpd.conf) and add this:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

in the DirectoryIndex add the php extentions like:

DirectoryIndex index.php index.html

Edit the Languageconfiguration file (/usr/local/etc/apache22/extra/httpd-languages.conf) and add the following lines:

AddDefaultCharset On

Ok, now lets start Apache for the first time..

/usr/local/etc/rc.d/apache22 start

Your all done! – You should now have a fully working AMP install on your FreeBSD 8.2 server :)

Well I thought I’d document how you can mount a SAMBA share on a Linux Server (in my case Ubuntu Server), I possibly have a project coming up soon where I may need to mount a Microsoft Windows based shared folder for additional storage/shared storage across multiple Linux/UNIX based web application servers.

Firstly you must make sure that your server/PC has the smbfs package installed, on Ubuntu you can install like like so..

sudo apt-get install smbfs

Once you have checked that you have that installed or installed it if your PC or server on which you want to mount the drive on then you can continue to the next step..

In this example I will be connecting to the following Windows Shared folder (\\myserver\data) and I will be mounting it on my linux server in /mnt/remote-data/.

If the folder ‘/mnt/remote-data/’ does not exist you will firstly need to create this folder like so..

sudo mkdir /mnt/remote-data

Now you can mount the Windows Shared folder like so..

sudo mount -t cifs -rw -o username=ballen,password=yourpassword //myserver/data /mnt/remote-data

If you then want to unmount the remote shared folder, you can enter the following command:

sudo umount /mnt/remote-data

You can also view all your current mounts like so:

sudo mount -l

I hope this helped some people, you can mount anywhere on your OS for example, you could mount the ‘music’ shared folder in your home directory like so…

sudo mount -t cifs -o username=ballen //myserver/music /home/ballen/Music

…but just remember that the folder needs to exist upon which you want to mount on :)

Well I found what I thought was a really handy way of easily mounting an .iso image on your Linux machine.

Check this out..

sudo mkdir -p /media/cdrom
sudo mount -o loop ~/Desktop/name_of_iso_file.iso /media/cdrom

You should now be able to access the .iso file data as if it was a physical CD-ROM :)

Hope someone finds this post useful :)

Ok well I have read many articles and a couple of times installed tools like Macbuntu which offer a complete transformation of Ubuntu GUI but I have never been happy with just how flaky these tools can be and how they can screw up your OS so I decided to make some simple graphical changes to make my Ubuntu Netbook look more prettier ;)

I thought I’d also share it with you all too (incase your interested)..

So this is what it looks like (its a small resolution screenshot as my Netbook has a small screen, imagine how nice it would look with a large desktop monitor :) ):-

Firstly you should download FaenzaMac.tar.gz this files contains all the icons and some other bits and bobs…

We now have to install ‘Aurora’ and the gtk2-engines-aurora packages…

sudo apt-get update
sudo apt-get install aurora
sudo apt-get install gtk2-engines-aurora

Next open up the System Settings applicaiton in Ubuntu and then click on Appearance

Now drag and drop the FaenzaMac.tar.gz file into the Appearance Preferences window, it will then install the theme for you…

Now choose Radiance as the theme you want to use (the screen should now update) then click on the Customise button.

Under the Controls tab in the Customise Theme window, scroll up and select Aurora.

Now choose the tab named Icons and now select the icon set named ‘FaenzaMac‘.

Now you can close the windows! – Where all done!

I personally like this theme better than Macbuntu as it does not alter core system files and is much more light weight and not as buddy, this is a simple change but personally I think makes a nice improvement to how my Netbook looks :)

Added:
I have now also added some extra stuff to my theme but adding the following two ‘Window Borders‘ which allow you to have the nicely styled MacOSX window borders (install in the same way, drag the two tar.gz files below into the Appearance Window and then select the new Mac OSX Window theme from the ‘Window Border’ tab).

Here is also a Pointer theme too that looks simular to make, install in the same way as above :)

I recently wanted to syncronise the contents of our backup VPS (for the ZPanel project) that we used to backup all of our servers and services that we use (MySQL databases, websites and SVN data) from multiple servers to a server sitting at my house – just for double protection as our backup VPS is donated to use free of charge :) .

The solution had to be secure and be able to run automatically from a CRON job on my home server at regular intervals without the need for human interaction. I also wanted to be able to archive daily data to another part of the system (as Rysnc synchronises data, it should not be relied upon as the total backup solution!)

The solution was to use Rsync over SSH whilst using a private/public key pair for authentication (thus not requiring password prompting for SSH access)..

So here is how I did it…

Firstly we need to generate a public/private key pair on your local server (in this case, my server at home), to generate the key pair use the following command:-

ssh-keygen -t rsa -b 4096 -f $HOME/homeserver-rsync-key

The above will create a 4096 strengh RSA public/private key pair located in your home directory, hence ($HOME) called homeserver-rsync-key – obviously you can chance this is you’d like.

Now we need to copy the public key (the file in your home directory ending in .pub) to the remote host (the server which holds the data you want to backup) you wish to automate your logon to. scp (Secure copy) the file to remoteuser@remotehost:~/.ssh/authorized_keys. If you do not wish to overwrite the existing authorized_keys file on the remote host, then, copy the .pub file to a new file on the remote host and append the contents to authorized_keys with the command:-

cat homeserver-rsync-key.pub >> ~/.ssh/authorized_keys

You can now use the ‘-i’ option in the ssh command line utility to login to the remote host without having to supply a password.

ssh -i homeserver-rsync-key remoteuser@remotehost

If everything has worked correctly to this point you will be given a command line prompt without having to enter the password for the remote system. It is also recommended to add a password to the private key when it is generated. This will stop anyone from using the private key for authentication, should it fall into the wrong hands. However, because the idea behind this is to automate your rsync remote backups with cron, you will not want to enter the password every time. This situation can be resolved by using the ssh-agent utility that ships with OpenSSH. You can add the password for a private key to the ssh-agent with the ssh-add commmand. When the ssh-agent is running on the system public/private key authentication will be password protected, but passwords will not be prompted for. However, the ssh-agent and ssh-add commands must be re-entered after each reboot of the back-up server.

NOTE: This is very insecure, never distribute the private key for any reason, as it will enable anyone to gain access to your system. It is recommended to add a password to the private key and use the ssh-agent utility provided with OpenSSH.

So now you can autoamte your backups via. RSYNC using the following command: (which ofcourse is then intended to be added to the cron job – In this example the files and folders are Rsync’d remotely every hour, on the hour)

0 * * * * rsync -avz -e "ssh -i /root/homeserver-rsync-key" root@remoteserver.com:/remote/file/path/* /local/folder/to/copy/to/

On the server at home, you’ll then want to create anoter cronjob that will archive the current data into a tar.gz file (dated!) using a shell script that I have written, the contents of the crontab would like as follows (in the example the data is archived every day at midnight)…

0 0 * * * /root/makeback.sh /path/to/rsync_folder /path/to/place/to/store/backups

You can download the shell script if you’d like to use it too from here (remember to chmod +x the file before attempting to run it!).

Well I should really be asshamed of myself (not have posted a blog post since Novemeber last year!!!) but to be honest with you all I have been very busy with many different things and haven’t really had anytime over the last month or two to do very much coding at all :(

But anyway, I thought I’d make a post for you PHP proceedural programmers out there who want to get to grips with OOP (Object Orientated Programming) and PHP Classes; Many new developers find this fairly daunting moving from Proceedural to Object Orientated (I did too!) so I thought I’d give a basic outline of what a Class is and then write a very basic class so you can apply what you learn here with what you already knew and then hopefully…. it’ll make much more sense and you’ll be writing your own PHP Classes in no time at all! :)

So in simple terms what is a PHP Class?

Well, really a Class is little more than a container that holds variables and functions but they can be very useful for building small components – almost miniture programs.  The difference is that you dont need to shell out to them or anything, and they can be plugged into most scripts with ease – Just a require or include statement at the top. A class describes an ‘object’. An object is a collection of smaller objects, just like in a class. Say for instance, we want to describe a simple door lock. A lock class might contain:

variable $Bolt
variable $Position
function TurnKey( $Direction, $Distance )
function CheckLock( )

TurnKey() would accept a direction value that would in turn determine if the bolt should be locked or unlocked. Once the key is turned far enough in either direction ($Distance) the Bolt will either set or clear. The $Bolt variable shows the current state of the door lock, and $Position is used to track how far the key has been turned in any direction. Now, obviously this could all be done with regular variables and functions, and if you only need to use one lock in the code, it would probably work just fine. But what if you want more than one lock? One if you wanted more details about the lock, or even something else? Maybe you want a door in the code, too – And the lock would just be a subset of the door. Maybe you have a whole house. You might have more than one door, or you might not. But each door certainly needs a lock. You can see how complex object-related problems can get. 

Class Structures

For lack of a better example right now, i’m going to show you how to create a simple page object. The page object encompasses a few of the basic page necessities in building an HTML page. Now, there is a lot more you could do with this class, but i’m going to keep it simple for the time being. You guys can expand on it if want later. Okay, lets start by looking at what the basic elements of an HTML page are. First, you have the open and closing tags, <HTML> and </HTML>. Those will need to be included in the output. Also, you have the page Title, Keywords for the Metatag field, and naturally the main content, or body. Now that we know what we need, lets start building our class. 

First thing we need is the class itself: 

<?php
 class Page {

 }
?>

This is a basic class. No variables, no functions, nothing – Completely empty. All class structures look the same here with the exception of the ‘Page’ name. Every class/object is assigned a name for reference. You’ll need to know this to create new copies of the object, so pick something straightforward and sensible. 

Next, we need to put in our variables. We need a title for the page, keywords, and a content body, like so: 

<?php
class Page {
   var $Title;
   var $Keywords;
   var $Content;
 }
?>

Now, we could actually start using the class here. We have an object. But it isn’t done – We still want to add some functions, to make it easier to work with. 

What functions do we need? Well, we need something to build the output HTML. Lets call that ‘Display’. Lets create simple functions for displaying the Title and Keywords, also. Lets make a function for setting the content as well. 

The final class code is:

<?php
class Page {
   var $Title;
   var $Keywords;
   var $Content;

   function Display( ) {
     echo "<HTML>\n<HEAD>\n";
     $this->DisplayTitle( );
     $this->DisplayKeywords( );
     echo "\n</HEAD>\n<BODY>\n";
     echo $this->Content;
     echo "\n</BODY>\n</HTML>\n";
   }

   function DisplayTitle( ) {
     echo "<TITLE>" $this->Title "</TITLE>\n";
   }

   function DisplayKeywords( ) {
     echo '<META NAME="keywords" CONTENT="' $this->Keywords '">';
   }

   function SetContent$Data ) {
     $this->Content $Data;
   }
 }
?>

Now, at first glance this looks pretty simple. And you know what? It is. Its just basic PHP code wrapped into a class. Let me point a few things out before we go any farther though.

VAR - All variables declared in the class must be placed at the top of the class structure, and preceeded with the VAR statement.�
$THIS - $this is a variable that incidates the current object. That way, the object knows how to find itself while running functions contained within it.�
 For instance, $this->Keywords gets the data from the $Keywords variable in the object. You’ll also notice that when using variables contained�
 within a class, you can’t use the $ to reference them – But you have to use it to reference the object itself. 

Lets save this class file out before we continue. If your following along, save it out as page.class for now. You’ll need it for the example coming up.  

Using the Class

 

Now that we have a class created, lets try using it in a normal script. 

<?php
 include "page.class";

 $Sample = new Page;

 $Content "<P>This page was generated by the Page Class example.</P>";

 $Sample->Title "Using Classes in PHP";
 $Sample->Keywords "PHP, Classes";
 $Sample->SetContent$Content );

 $Sample->Display( );

?>
 

Doesn’t get much simpler than that, does it? We use the include statement to bring in the class from its external file. We use the ‘new’ statement to create a new copy of the object so we can work with it. The new copy is stored into a variable called $Sample. Then we just set some variables – The Title, Keywords and Content – And use the Display function to output it. Easy or what?

If you would have asked me several years ago what I thought of Apple Mac’s I would have pretty much spat at you, I found them to be a ‘kiddies toy’ that designers used (to be fair at the time it was OS9) or maybe I was just blind!??!!!?!??

….However, since which time I have started to really love the eye candy that Mac OSX has to offer and if you have been reading my other blog posts you will have found that I am very much a Linux/Windows man myself and never really played with OSX…. until this weekend….

I found several articles online how to install OSX on an Intel based PC (this method has been named ‘Hackintosh’) so I thought whats all the hype about, I was bored and therefore thought I’d give it ago…..

After getting everything prepared and installing it I was in LOVE!!! – And thats only with the OSX software!!! – Gees, the actual Mac hardware is gorgeous so if I could afford to go out and buy a MacPro or iMac tomorrow I most certainly would!!! – But truth is that at over £1000 (almost and upto £2500) it really is way too steep for me at the moment unfortunetly but a brand new iMac or MacPro is certainly on my wishlist now!!!

So what and why do I love it??

Well several reasons really….

  1. It looks AWESOME
  2. It just works
  3. Its UNIX based
  4. Its stable and secure
  5. Its effortless to use

I have used it for a couple of days now and it basically JUST WORKS!!! – Its easy to use and I LOVE ‘Time Machine’ – I think this is a really great feature, these days I don’t really want to be messing around with Mico$oft Windows, its too flakey, boring to use and to be honest requires alot of effort keeping it patched and virus free!

I want a computer to work, be fun to use, and be secure… The way I look at this is…. Its a Mac, Its a UNIX based operating system that looks amazing… The best of both worlds….

Right… Its time I start saying up for a new Mac and get rid of all my PC junk ;)

Well the last month has been very eventful with regards to the projects that I have been running/involved in….

I have released ZPanel 6.0.0 Alpha1 on Sunday for testing and so far so good so hopefully a full upgrade release will be released as stable very soon as soon as everyone from the ZPanel team is happy.

I have also been working on my own Linux distrubution (something that I have wanted to do for years) which is based on Ubuntu LTS releases and is targetted as a free alternative to a propertiarial operating system which uses the code names of animals for their releases (you should be able to get it from that clue) but if not work out which one is missing from this list… (Windows, Linux, Unix, ***)? – Hopefully you get it now :)

The Linux distrubution that I am making is attempting to be easy on the eyes (eye candy from the start), Fast and stable when in use.

I have removed many of the default applications from Ubuntu 10.04 (LTS); The reason that I am using the LTS version is that the distrubution is then officially supported for three years meaning that non-technical users don’t have to worry about upgrading every six months.

As well as the operating system myself and a small team (team not yet setup) will be creating a cloud service that is linked from the OS (using Dock icons and desktop icons) that enables new users to register an account and then give them webmail, POP3 email and file sharing.

I hope that the new distrubution will encourage users to switch to the OS as it is provided free of charge and will be a stable platform for their home PC/laptop or netbook. – Ofcourse there is nothing stopping people using this in the office either but our initial market for users will be home users.

You never know, in the future we may also bring out a Server version too :)

…All very exciting times :)