{"flag":true,"single":true,"pageTitle":"Access laravel .env variables in any other files that are not part of laravel application","post":{"id":303,"user_id":"1","slug":"access-laravel-env-variables-in-any-other-files-that-are-not-part-of-laravel-application-bny8","title":"Access laravel .env variables in any other files that are not part of laravel application","body":"<pre class=\"language-markup\"><code>&lt;?php\r\n\r\n\/\/ Now you can use env() or config()\r\n\/\/ give correct path of laravel autoload.php and app.php\r\nrequire __DIR__ . '\/..\/vendor\/autoload.php';\r\n$app = require_once __DIR__ . '\/..\/bootstrap\/app.php';\r\n\r\nuse Illuminate\\Contracts\\Console\\Kernel;\r\n\r\n$kernel = $app-&gt;make(Kernel::class);\r\n$kernel-&gt;bootstrap();\r\n\r\n$servername = \"localhost\";\r\n$dbname = env('DB_DATABASE');\r\n$username = env('DB_USERNAME');\r\n$password = env('DB_PASSWORD');\r\n<\/code><\/pre>","category_id":"2","is_private":"0","created_at":"2025-06-11T04:30:09.000000Z","updated_at":"2025-06-11T04:30:09.000000Z","category":{"id":2,"user_id":"1","name":"Laravel Core","slug":"laravel-nhyt","parent_id":"1","created_at":"2023-03-14T03:58:27.000000Z","updated_at":"2023-03-20T11:30:50.000000Z"},"user":{"id":1,"name":"R GONDAL","email":"rizikmw@gmail.com","email_verified_at":null,"two_factor_confirmed_at":null,"current_team_id":"1","profile_photo_path":null,"created_at":"2023-03-12T10:49:33.000000Z","updated_at":"2025-01-10T12:59:00.000000Z","profile_photo_url":"https:\/\/ui-avatars.com\/api\/?name=R+G&color=7F9CF5&background=EBF4FF"}},"pageDesc":"&lt;?php  \/\/ Now you can use env() or config() \/\/ give correct path of laravel autoload.php and app.php require __DIR__ . '\/..\/vendor\/autolo - Access laravel .env variables in any other files that are not part of laravel application (Updated: June 11, 2025) - Read more about Access laravel .env variables in any other files that are not part of laravel application at my programming site [SITE]","categories":[]}