mardi 26 mai 2020

.env file missing! You forgot to upload the .env file in Laravel

server.php

<?php
    $uri = urldecode(
        parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
    );
    if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
        return false;
    }
    require_once __DIR__.'/public/index.php';

public/index.php

<?php
    if(!file_exists('../.env')){
        $GLOBALS["error_type"] = "env-missing";
        include('error_install.php');
        exit(1);
    }

    if (version_compare(PHP_VERSION, '7.2.5') < 0){
        $GLOBALS["error_type"] = "php-version";
        include('error_install.php');
        exit(1);
    }
    changeEnvironmentVariable();

    function changeEnvironmentVariable()
    {

        $path = '../.env';
        if (file_exists($path)) {
            $current = file_get_contents($path);
            $original = [];
            if (preg_match('/^DB_PASSWORD=(.+)$/m', $current, $original)) {
                $current = preg_replace('/^DB_PASSWORD=.+$/m', 'DB_PASSWORD="' . $original[1] . '"', $current);
                if (strpos($original[1], '"') === false) {
                    file_put_contents($path, $current);
                }
            }
        }
    }

    require __DIR__.'/../vendor/autoload.php';

    $app = require_once __DIR__.'/../bootstrap/app.php';

    $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

    $response = $kernel->handle(
        $request = Illuminate\Http\Request::capture()
    );

    $response->send();

    $kernel->terminate($request, $response);

I am trying to deploy my laravel project on server but I am unable to run when I hit for example https://example.com then it shows directory structure I have checked all but can't find error and when I run server.php file with domain then it shows .env file missing! You forgot to upload the .env file. where I have already a .env file in my root dir and I also tried to replace it with .evn.example but it remain show directory structure.

I don't understand where am I doing wrong? Please help me to solve this.

Thank you



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire