I created a php script:

#!/usr/local/bin/php

<html><head><title>PHP Test</title></head>
<body>
<?php print( "Hello World<br />"); ?>
</body></html>

created an htacces file

AddHandler cgi-script .php
DirectoryIndex index.html index.php

changed the permission

chmod 711 hello.php
chmod 644 htaccess

This does not work:

http://xyz/~username/hello.php

By making the hello.php to hello.txt the file content can be viewed on the browser. I am not sure what can be done about it?

Thanks

If you are trying to run this on your own (local) machine, then you need to create a LAMP (Linux Apache MySQL PHP) environment. There are free packages like EasyPHP and WAMP that you can download to do this. You need to have a simulated Linux server environment (or a Windows server if that is your preference). PHP is a server-based language. PHP isn't actually executed by your Browser (unlike HTML or javascript).

Unfortunately I am hosting this on a university department server where they gave me that much information only. So I am bound by this limited opportunity.

did you upload a php-file with code:

<?
phpinfo();
?>

So you can see the module's, running at your server and what scripts is allowed to execute.