You can refer, for example, to $_SERVER['PWD']
and $_SERVER['OLDPWD']
For example, I have script test.php
in ./dev
subfolder with contents:
var_dump($_SERVER['PWD'], $_SERVER['OLDPWD']);
So, you can see:
user@host:/var/www/data$ php dev/test.php string(13) "/var/www/data" string(17) "/var/www/data/dev"
So, first one is what you're looking for.
Script full name, as usual, will be available in __FILE__
constant.