I am slightly baffled.
I am using the bit.ly PHP API to shorten some urls. This works fine on local host - but when I tried it on my server (php running in Apache),
It probably has something to do with PHP configuration. Many servers have different php.inis for CLI and Apache. Check /etc/php5/ to see if there is more than one configuration. Specifically, you should be looking for allow_url_fopen.
EDIT: Actually, Ubuntu ships with that by default, the .ini is located at /etc/php5/apache2/php.ini