Small bash script to start and stop named services
Don't Repeat Yourself

You start/stop/restart apache2 and mysql the same way, so you don't need to duplicate their code. You could create a generalized function that can handle these or any standard service well, like this:

startstop_service() {
    cmd=$1
    name=$2
    sudo service $name $cmd
}


Naming

You renamed the universal and intuitive command names start/stop/restart to the shorter but kind of obscure st/sh/re. I recommend to stick with the originals. Among other things, the startstop_service in my previous point will work out of the box.

The case statement

The case statement in Bash is more concise and easier to read than many if-elif-elif-else statements, for example:

case "$1" in
    start|stop|restart) cmd=$1 ;;
    *) echo "usage: $0 [start|stop|restart] servicenames"; exit 1
esac
shift


Minor things


Your script doesn't use any Bash specific features, /bin/sh would be enough
It's better to validate the cmd parameter once, instead of for every single service name as in your code
If the cmd is invalid, it's good to exit the script with a non-zero exit code (typically exit 1), to indicate failure
You can simplify for name in "$@"; do as for name; do


Suggested implementation

Here's an alternative implementation using the above suggestions:

#!/bin/sh -e

NGINX=/home/prahlad/programs/nginx-1.6.0/sbin/nginx
PHP=/home/prahlad/programs/php-5.4/sbin/php-fpm
PHP_NAME=$(basename $PHP)

startstop_service() {
    cmd=$1
    name=$2
    sudo service $name $cmd
}

startstop_nginx() {
    cmd=$1
    case $cmd in
        stop) $NGINX -s stop ;;
        start) $NGINX ;;
        restart)
            $NGINX -s stop
            sleep 1
            $NGINX
            ;;
    esac
}

startstop_php() {
    cmd=$1
    case $cmd in
        stop) pkill $PHP_NAME ;;
        start) $PHP ;;
        restart)
            pkill $PHP_NAME
            sleep 1
            $PHP
            ;;
    esac
}

case "$1" in
    start|stop|restart) cmd=$1 ;;
    *)
        shift
        servicenames=${@-servicenames}
        echo "usage: $0 [start|stop|restart] $servicenames"
        exit 1
esac
shift

for name; do
    case "$name" in
        php-fpm) startstop_php $cmd ;;
        nginx) startstop_nginx $cmd ;;
        *) startstop_service $cmd $name ;;
    esac
done


Notice that apache2 and mysql are not even mentioned in this script, they are automatically handled by the generic startstop_service function. The script will work with any other standard service too.

As @vnp pointed out, the sleep 1 calls are dodgy, I did not fix that. To fix that, look for pid files created by those services, and use them to check if the service is still running or not.

The bigger picture

Ideally, you should standardize everything: make it possible to start/stop/restart your custom php-fpm and nginx just like other services. That way you can remove the service-specific logic from this script (doesn't really belong here anyway), and then it can work for any service you throw at it. Unfortunately I don't know enough Ubuntu to guide you, but I'm sure the guys on askubuntu.com can help with that.