I have upgraded my PHP version on my dedicated server recently from php 4.4.4 to php 5.1.4, i will explain how i did that here, hope it might be useful to someone else. Some of the scripts we use may be upgraded to PHP 5 version, in that case it is always better to upgrade your server php version. The best way to do is from your WHM (Web Host Manager) installed on your server, i dont know how to do it from shell, there may be a way but i am scared that i may broke the server.
In most of the Linux servers php is installed as apache module, so we have to build apache by selecting the version of PHP you want to install.
First Identify the PHP version installed on your server, you can do this by creating a phpinfo file on your site, here its a good idea to note modules installed with php from the result of the phpinfo file. This is useful if something goes wrong after upgrading.
Login to your server as root with WHM, on the left side bar you will find software section, here click on Apache Update. It will show you the default configuration of apache.
If you want to load the previous configuration click the button that shows Load Previous Config. Any how you want to upgrade the PHP version, so select the latest version you want to upgrade from the list of available php versions. Leave the default selected modules like that otherwise your apache configuration may broke. Select other modules like xmlrpc, curl etc. carefully dont check all the boxes, some of the modules may not work and sometimes there may be some security concerns.
After selecting the php version and other modules you want to use click start build button, now apache will start recompiling, this process is slow and will take 1 or 2 hours depending on the modules you have selected. Please be patient and don’t do anything on whm. Once the process is finished you need to restart apache to see the changes. After restarting apache check all your sites installed on the server they should load properly, if something is wrong go back to apache and rebuilt with previous version.