Good bye CentOS! Hello Ubuntu

Its been about almost more then two years since I have been playing with CentOS on many different platforms etc. Its very stable but on the other hand, PHP/MySQL updates are very hard to get and still PHP is 5.1.6. I tried EPEL repo and it updated PHP to 5.3.1 but still there were conflicts with stuff and many core packages.

So, I thought why not move to Ubuntu since it has just announced 10.04LTS (Long Term Support) in April 2010. Folks at iWeb were really nice to do a reinstall without any charges and also process a memory upgrade request at an amazing 50% discount.

Ubuntu 10.04 LTS

  • Apache 2 version is 2.2.14
  • PHP version is 5.3.2
  • MySQL version is 5.1.41-3ubuntu12
  • SVN (Subversion) version is 1.6.6

As a comparison CentOS 5.4 has the following versions

  • Apache 2 version is 2.2.3
  • PHP version is 5.1.6
  • MySQL version is 5.0.77
  • SVN (Subversion) version is 1.4.2

So if you are a PHP developer looking to deploy a Linux flavour on your new box, choose Ubuntu 🙂

Installing PHP 5.2.6 on CentOS box

If you want to install PHP 5.2.x instead of the PHP 5.1.6 offered with default CentOSPlus repo. Please consider installing the utterramblings repo. Setting up this repo is a breeze … just follow these steps

Continue reading

How to Install Webmin on CentOS

Install dependencies before we proceed to install webmin

[root@testbed ~]# yum -y install perl-Net-SSLeay

Download latest rpm package from Webmin’s official website

[root@testbed ~]# http://www.webmin.com/download/rpm/webmin-current.rpm -O /tmp/webmin.rpm

Once it is downloaded, install the RPM using the following command

[root@testbed ~]# rpm -i /tmp/webmin.rpm

No more steps required. Its installed 🙂
Go to your browser and access the control panel with valid ssh credentials.
Default URL is https://your-ip:10000/ (IF you have not changed the default port)

Creating and Installing crontabs using CodeIgniter

Last night, I was trying to get a crontab working in CodeIgniter, since my current project (a personal project) is using CodeIgniter now. I didn’t wanted to use the conventional approach of running crontabs and my code seperate.

Unfortunately, CodeIgniter does not have support for Crontabs and I didn’t wanted to user wget in linux crontab to initiate unwanted requests.

I spent some time and came up with a solution. It uses

  1. CodeIgniter backend
  2. Does not modify any core architecture of CodeIgniter
  3. Keeps configuration at one place

So enough of the summary and let me show you how its done.
Create a file (e.g. cron.php) in the same place as your index.php and system folder. Here is its code

/**
* @author 	    Asim Zeeshan
* @web         http://www.asim.pk/
* @date		13th May, 2009
* @copyright 	No Copyrights, but please link back in any way
*/

/*
|---------------------------------------------------------------
| CASTING argc AND argv INTO LOCAL VARIABLES
|---------------------------------------------------------------
|
*/
$argc = $_SERVER['argc'];
$argv = $_SERVER['argv'];

// INTERPRETTING INPUT
if ($argc > 1 && isset($argv[1])) {
$_SERVER['PATH_INFO'] 	= $argv[1];
$_SERVER['REQUEST_URI'] = $argv[1];
} else {
$_SERVER['PATH_INFO'] 	= '/crons/index';
$_SERVER['REQUEST_URI'] = '/crons/index';
}

/*
|---------------------------------------------------------------
| PHP SCRIPT EXECUTION TIME ('0' means Unlimited)
|---------------------------------------------------------------
|
*/
set_time_limit(0);

require_once('index.php');

/* End of file test.php */

Now, we need a controller e.g. test so the controller code could be something like this. Please note that normally we do not need to output anything from these controllers since they are doing some background work or sending emails but for the sake of giving an example, I will be output-ing something to elaborate the example.

/**
* @author 	    Asim Zeeshan
* @web         http://www.asim.pk/
* @date		13th May, 2009
* @copyright 	No Copyrights, but please link back in any way
*/</code>

class Test extends Controller {

function __construct()
{
parent::Controller();
}

function index()
{
echo "testing from index \n";
}

function test() {
echo "testing from test \n";
}
}

Now execute crontab on linux command prompt

php /full-path-to-cron-file/cron.php /test/index

Voila! all you need now, is to setup the crontab like you normally do.
This code is not shared under any license so feel free to copy/modify/use it. Please link back to this website / post in any way e.g. direct link, credits etc.

P.S. The examples above user PHP5 constructor, If you need to execute this code on PHP4, please modify the constructors.

Installing MySQL 5.1 on Ubuntu

I wanted to use PARTITIONING introduced in MySQL 5.1 to handle some 2 Million records (and growing everyday) in a table. Ubuntu 8.10 does not have MySQL 5.1 available if you do apt-get the latest version available is 5.0

So this is what I did, its easy and this might help somebody.

nano /etc/apt/sources.list

I prefer nano editor but you can use any editor of your choice. Add these new lines at the end of the end of the file.

deb http://ppa.launchpad.net/monty/ubuntu gutsy main universe restricted multiverse
deb http://ppa.launchpad.net/smurf/ubuntu gutsy main universe restricted multiverse

(These packages were targeted for 7.10 so I will recommend using them and removing them from this list once you got the latest MySQL version)

Now run the following commands

apt-get update
apt-get upgrade

Note that you may need to do sudo prefix to these commands if you are using a non-root account. Now lets do the one last step, Installing MySQL 5.1

apt-get install mysql-server-5.1

Update: I have got another source to get even latest minor version of MySQL 5.1, just follow the above steps, then start over again and add following lines to “/etc/apt/sources.list” instead of the one above.

deb http://packages.dotdeb.org stable all
deb-src http://packages.dotdeb.org stable all

It worked for me on Ubuntu 8.10, im sure it will work for just any server version.

I am not a linux guru so if someone has a better option to upgrade to MySQL 5.1 or the latest version, please let me know.

Intall Apache, MySQL and PHP on Ubuntu 8.10

WARNING: Please use this method to install Apache, PHP and MySQL because its more suitable for most of your needs and has options to auto-upgrade your installation. The following method is obsolete and not recommended.

After trying to install Apache, MySQL and PHP on Ubuntu 8.10 via several methods listed over the web. I opted for xampp package for linux.

It is as easy as ABC

Download the xampp linux package from their official website

wget http://nchc.dl.sourceforge.net/sourceforge/xampp/xampp-linux-1.7.tar.gz

(I have selected NCHC, Taiwan as the mirror to download this package, you may try another)

Extract the files

sudo tar xvfz xampp-linux-1.7.tar.gz -C /opt

Chmod the files to have nobody ownership

sudo chown -R nobody:root /opt/lampp/

Configure xampp security

sudo /opt/lampp/lampp security

Start xampp with this command

sudo /opt/lampp/lampp start

Stop xampp

sudo /opt/lampp/lampp stop

Restart xampp

sudo /opt/lampp/lampp restart

Login to ftp using the username nobody and the password that you have set up in the “xampp security”

To uninstall xampp

sudo rm -fr /opt/lampp

Enjoy!!