jalogut / magento2-deployer-plus

Tool based on deployer.org to perform zero downtime deployments of Magento 2 projects
GNU General Public License v3.0
200 stars 60 forks source link

setup:db:status -> No information is available: the Magento application is not installed. #33

Closed hamza553 closed 5 years ago

hamza553 commented 5 years ago

Here's what am trying to do:

Here's what I did

  1. composer require "jalogut/magento2-deployer-plus"
  2. cp vendor/jalogut/magento2-deployer-plus/deploy.php.sample_2_2_5 deploy.php ( as am using 2.2.7 version of Magento )

    That's how my deploy.php looks like

    
    <?php

namespace Deployer;

require 'vendor/jalogut/magento2-deployer-plus/recipe/magento_2_2_5.php';

// Use timestamp for release name set('release_name', function () { return date('YmdHis'); });

// Magento dir into the project root. Set "." if magento is installed on project root set('magento_dir', ''); // [Optional] Git repository. Only needed if not using build + artifact strategy set('repository', ''); // Space separated list of languages for static-content:deploy set('languages', 'en_US');

set('magento_bin', 'bin/magento');

set('shared_files', ['/var/www/staging/app/etc/env.php']); // OPcache configuration task('cache:clear:opcache', 'sudo systemctl reload php-fpm'); after('cache:clear', 'cache:clear:opcache');

// Build host localhost('build');

// Remote Servers host('dev_master') ->hostname('68.xxx.xxx.124') ->user('root') ->set('deploy_path', '/var/www/html') ->stage('dev') ->roles('master');


**I'm using build artifact:**

- php vendor/bin/dep build
    this goes fine and creates an archived for release 

- php vendor/bin/dep deploy-artifact dev  

It produces the following error:

[dev_master] > /usr/bin/php /var/www/html/releases/20190305070046/bin/magento setup:db:status [dev_master] < No information is available: the Magento application is not installed. In Client.php line 99: [Deployer\Exception\RuntimeException (1)] The command "/usr/bin/php /var/www/html/releases/20190305070046/bin/magento setup:db:status" failed. Exit Code: 1 (General error) Host Name: dev_master

No information is available: the Magento application is not installed.



Can any of you guide me through what am I doing wrong here?
osrecio commented 5 years ago

Hi, can you check your env.php. Is empty? (Can you share your env.php? hiding sensitive data like crypt key, db info, etc...)

jalogut commented 5 years ago

Hi @hamza553

Could you also check that your deploy_path configuration is correct? Where exactly is you dev instance located on the server (absolute_path)?

osrecio commented 5 years ago

I think is more related with env.php. At the end when you launch setup:db:status you have:

if (!$this->deploymentConfig->isAvailable()) {
            $output->writeln(
                "<info>No information is available: the Magento application is not installed.</info>"
            );
            return Cli::RETURN_FAILURE;
        }

If we check $this->deploymentConfig->isAvailable() method:

public function isAvailable()
    {
        $this->data = null;
        $this->load();
        return isset($this->flatData[ConfigOptionsListConstants::CONFIG_PATH_INSTALL_DATE]);
    }

Where flatData checked is in env.php -> install/date for constant: ConfigOptionsListConstants::CONFIG_PATH_INSTALL_DATE

for this reason that I think is related with env.php :)

jalogut commented 5 years ago

Looking again at you configuration I think the problem is that you are giving an absolute path for the shared_files. I think this path should be relative. It should also point to your dev instance and not to stage. Try removing this configuration and using the default one

osrecio commented 5 years ago

Oh yes... my fault @hamza553 You have set('shared_files', ['/var/www/staging/app/etc/env.php']);. but you have deploy_path to /var/www/html

Please follow the comments by @jalogut .

hamza553 commented 5 years ago

@jalogut sure am gonna do as you mentioned right away & will keep you posted on

hamza553 commented 5 years ago

The env on my dev instance:

<?php
return [
    'backend' => [
        'frontName' => 'admin'
    ],
    'crypt' => [
        'key' => 'd5703161e58a3e3dc647e51ceffeb8c2'
    ],
    'db' => [
        'table_prefix' => '',
        'connection' => [
            'default' => [
                'host' => 'localhost',
                'dbname' => 'lulusar_***',
                'username' => '****',
                'password' => '****',
                'active' => '1'
            ]
        ]
    ],
    'resource' => [
        'default_setup' => [
            'connection' => 'default'
        ]
    ],
    'x-frame-options' => 'SAMEORIGIN',
    'MAGE_MODE' => 'developer',
    'session' => [
        'save' => 'files'
    ],
    'cache_types' => [
        'config' => 1,
        'layout' => 1,
        'block_html' => 1,
        'collections' => 1,
        'reflection' => 1,
        'db_ddl' => 1,
        'eav' => 1,
        'customer_notification' => 1,
        'config_integration' => 1,
        'config_integration_api' => 1,
        'full_page' => 1,
        'config_webservice' => 1,
        'translate' => 1,
        'vertex' => 1,
        'compiled_config' => 1
    ],
    'install' => [
        'date' => 'Sun, 20 Jan 2019 00:10:33 +0000'
    ]
];

now that's the error:

In Client.php line 99:

  [Deployer\Exception\RuntimeException (1)]
  The command "/usr/bin/php /var/www/html/releases/20190305145232/bin/magento setup:db:status" failed.

  Exit Code: 1 (General error)

  Host Name: dev_master

  ================
  Invalid configuration file: '/var/www/html/releases/20190305145232/app/etc/env.php'

Now when I go and check at my staging instance in release//app/etc/env.php env.php appears to be a shortcut 😕

osrecio commented 5 years ago

Hello @hamza553 ,

The env.php is a symlink to the shared folder and it should see like this (can differ permissions, and user:group):

lrwxrwxrwx. 1 magento magento 45 Mar  5 16:19 app/etc/env.php -> ../../../../shared/app/etc/env.php

The env.php you copied to your comment is the same that you have when you launch ?: cat /var/www/html/releases/20190305145232/app/etc/env.php

The error: Invalid configuration file is declared here:

#vendor/magento/framework/App/DeploymentConfig/Reader.php:103
if ($fileDriver->isExists($filePath)) {
                $result = include $filePath;
                if (!is_array($result)) {
                    throw new RuntimeException(new Phrase("Invalid configuration file: '%1'", [$filePath]));
                }
            }

And it seems when trying to include the file /var/www/html/releases/20190305145232/app/etc/env.php is not an array... but if it is the same you put in your comment is so weird...

hamza553 commented 5 years ago

Hi @osrecio it's not the same infact it's empty and when I checked my build artifact folder

artifact.tar.gz\artifact.tar.\app\etc\

there does not exists any env.php, is it supposed be like this or should it be included in the artifact

osrecio commented 5 years ago

Hi @hamza553 ,

The env.php is a file that should be unique to each environment. That's why it is not included in the artifact and not should it be included in your version control.

The first time thtat the applications is deployed, the file has to be filled with the data of that environment, such as the database, etc.

Your initial problem was to declare the env.php with absolute paths, when you performed the change proposed by @jalogut, this file was created (empty) and a symlink was created to the shared folder where it should be.

So, do the following:

vim /var/www/html/shared/app/etc/env.php

Add the data of your environment and please deploy again.

This file will not be overwritten in the following deploys.

I recommend you read the Deployer documentation : https://deployer.org/docs/getting-started.html

hamza553 commented 5 years ago

@osrecio thanks man, its working now

osrecio commented 5 years ago

I'm glad to hear that.

I proceed to close the issue