What is the best way to define a global constant in PHP which is available in all files?

Define your constant in your top .php file, that will be included in all the other scripts. It may be your front controller, your config file, or a file created for this single purpose.

!defined('MY_CONST') && define('MY_CONST', 'hello');

do the following:

define("CONSTANT_NAME","value");

if you want to access this constant from other php files, you have to include it:

include_once("thefilewiththeconstant.php");

When you want to use global constants across PHP files, I feel a good practice is to use Object Oriented principles and define these in relevant classes. Using the spl_autoload_register() function built into PHP, you can define all your later classes to extend the related "globals class" without worrying about including files manually everywhere. All the later child classes of that globals class will always have access to the related global variables. (I say related because it's good design to have global constants in a class be related in some way, rather than everything grouped together with no rhyme or reason)