The internet is a more complex than it was before. It is always good to safe the web sites and web applications from hackers. The .env file plays a remarkable role in this situation.
A web application file that starts with a dot like .env is not accessible by users. This file is used to secure sensitive data of web applications from outside world.
The .env file is created in the root folder of the project. This is a plain text file. This file defines the environment variables required for an application in key and value pairs.
Suppose we are storing the application name in the .env file.
APP_NAME = Project1
Now, we are retrieving this application name and show in our index.php file.
require_once realpath(__DIR__ . "/vendor/autoload.php");
use Dotenv\Dotenv;
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv-gt;load();
$app_name = $_ENV['APP_NAME'];
echo $app_name;
In this way we can create all the variables which are required in our project environment and access in our project files.
En esta página del sitio puede ver el video en línea Using environment variables in PHP with .env de Duración hora minuto segunda en buena calidad , que subió el usuario PHP Explained 21 mayo 2025, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 187 veces y le gustó 0 a los espectadores. Disfruta viendo!