dotENV in PHP | environment variables | $_ENV super global array | phpdotenv via composer #kody_az
Dərs haqqında
Composer vasitəsi ilə:
composer require vlucas/phpdotenv
.env faylı PHP-də verilənlər bazası məlumatları, API açarları və tətbiq ayarları kimi mühit dəyişənlərini saxlamaq üçün istifadə olunan sadə mətn faylıdır.
PHP özü .env fayllarını birbaşa tanımır, yalnız əməliyyat sistemi və ya veb server tərəfindən ötürülən mühit dəyişənlərini bilir.
.env faylındakı dəyərləri PHP-yə yükləmək üçün adətən vlucas/phpdotenv kimi kitabxanalardan istifadə olunur; bu kitabxana faylı oxuyur və dəyişənləri $_ENV və ya proses mühitinə yerləşdirir.
.env faylı parolları və gizli açarları kod daxilində yazmaq əvəzinə ayrıca saxlayaraq təhlükəsizliyi artırır.
Dotenv kitabxanası faylı yüklədikdən sonra bu dəyişənlərə PHP kodunda $_ENV['DB_HOST'] və ya getenv('DB_HOST') vasitəsilə çıxış etmək mümkündür.
Bu yanaşma tətbiqi daşına bilən edir, çünki lokal mühitdən istehsala və ya test mühitinə keçid üçün yalnız .env faylını dəyişmək kifayətdir.
Müasir PHP framework-lərin (Laravel, Symfony, CodeIgniter və s.) çoxu .env fayllarını konfiqurasiya idarəsi üçün əsas üsul kimi istifadə edir.
===
A .env file in PHP is a simple text file used to store environment variables such as database information, API keys, and application settings.
PHP itself does not recognize .env files directly, it only knows about environment variables passed by the operating system or the web server.
To load the values from a .env file into PHP, developers usually use libraries like vlucas/phpdotenv; this library reads the file and places the variables into $_ENV or the process environment.
A .env file increases security by storing passwords and secret keys separately instead of writing them directly in the code.
After loading the file with the Dotenv library, these variables can be accessed in PHP code using $_ENV['DB_HOST'] or getenv('DB_HOST').
This approach makes the application portable, since moving from local development to production or testing only requires changing the .env file.
Most modern PHP frameworks (Laravel, Symfony, CodeIgniter, etc.) use .env files as the main method for configuration management.
#kody_az #kodyaz #php #phpcode #laravel #phpprogramming #viral #viralcode #viralvideo #random #code #coder #azerbaycan #azerbaijan #baku #baki #programming #programmer #codes #hazırlıq #hazirliq #kurs #kurslar #course #courses #online #onlinecourses #test #quiz