zepgram / magento2-fast-vm

Optimal vagrant developer box for Magento2. Folders synced by nfs/rsync. This box includes Magento developer utilities.
MIT License
110 stars 35 forks source link

Pre existing project redirects to setup page #23

Closed ramzdam closed 5 years ago

ramzdam commented 5 years ago

Hi @zepgram I installed this project and set it up with an existing project from my repo. Now this project is already working. Now I redownloaded your project and reinstalled the magento 2.3.1 version. At first it gave me an error saying Cannot find magento.store_website which I think is just correct? Since I'm loading an existing project and the Magento DB is not created since I didn't go to the whole db/website installation process. So I uploaded my own DB dump from the created MariaDB connection. Now I did a vagrant reload --provision then visited the Admin. Upon visiting it I got an error saying the website is in Maintenance mode so I run bin/magento maintenance:disable then revisit the site again. Now it says the Application is not installed. So whenever I visit the site it redirects me to the Setup Page. Any idea regarding this?

Edit: Upon digging some more it seems that even if I set my config.yaml to pull from existing project it's trying to install Magento as a clean state? It's installing the database schema for the installation of installDataFixtures. And since it's installing from existing project there are no Database when doing vagrant reload --provision since somehow the database and all tables are being deleted. Now when I manually upload the DB dump and access the db that's when I get the mode is set to maintenance mode (which is why I needed to disable it every now and then). Below is the scripts that causes the issue

FIle: approot/setup/src/Magento/Setup/Model/Installer.php Line: 328 Function:

public function install($request) { $script[] = ['File permissions check...', 'checkInstallationFilePermissions', []]; $script[] = ['Required extensions check...', 'checkExtensions', []]; $script[] = ['Enabling Maintenance Mode...', 'setMaintenanceMode', [1]]; $script[] = ['Installing deployment configuration...', 'installDeploymentConfig', [$request]]; if (!empty($request[InstallCommand::INPUT_KEY_CLEANUP_DB])) { $script[] = ['Cleaning up database...', 'cleanupDb', []]; } $script[] = ['Installing database schema:', 'installSchema', [$request]]; $script[] = ['Installing user configuration...', 'installUserConfig', [$request]]; $script[] = ['Enabling caches:', 'enableCaches', []]; $script[] = ['Installing data...', 'installDataFixtures', [$request]]; if (!empty($request[InstallCommand::INPUT_KEY_SALES_ORDER_INCREMENT_PREFIX])) { $script[] = [ 'Creating sales order increment prefix...', 'installOrderIncrementPrefix', [$request[InstallCommand::INPUT_KEY_SALES_ORDER_INCREMENT_PREFIX]], ]; } if ($this->isAdminDataSet($request)) { $script[] = ['Installing admin user...', 'installAdminUser', [$request]]; } if (!$this->isDryRun($request)) { $script[] = ['Caches clearing:', 'cleanCaches', [$request]]; } $script[] = ['Disabling Maintenance Mode:', 'setMaintenanceMode', [0]]; $script[] = ['Post installation file permissions check...', 'checkApplicationFilePermissions', []]; $script[] = ['Write installation date...', 'writeInstallationDate', []]; $estimatedModules = $this->createModulesConfig($request, true); $total = count($script) + 4 * count(array_filter($estimatedModules)); $this->progress = new Installer\Progress($total, 0); $this->log->log('Starting Magento installation:'); foreach ($script as $item) { list($message, $method, $params) = $item; $this->log->log($message); call_user_func_array([$this, $method], $params); $this->logProgress(); } $this->log->logSuccess('Magento installation complete.'); $this->log->logSuccess( 'Magento Admin URI: /' . $this->deploymentConfig->get(BackendConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME) ); if ($this->progress->getCurrent() != $this->progress->getTotal()) { throw new \LogicException('Installation progress did not finish properly.'); } if ($this->sampleDataState->hasError()) { $this->log->log('Sample Data is installed with errors. See log file for details'); } }

Is this the correct process? Doing a DB dump? or probably offer the script to upload an existing DB dump perhaps? so that if the installer check for the dump it won't fail this there are already an existing db.

Or maybe you have a solution for my issue? Would really appreciate your help on this

zepgram commented 5 years ago

Hi @ramzdam,

The provision destroy the database so you cannot do this in 2 steps with a vagrant reload. To get through this I created extra script to customise the setup. I give you here the steps to import a db from existing project in your vagrant provision.

  1. First ou have to dump the db of your project.

    mysqldump -u user -p database | gzip > db-dump-latest.sql.gz
  2. You'll need your crypted key under app/etc/env.php from your existing project:

    'crypt' =>
    array (
    'key' => '***************************',
    )
  3. Put your dump in extra directory.

  4. Create extra/100-pre-build.sh sequence and add this script to import your dump:

    
    #!/bin/bash

if [ $PROJECT_SOURCE == "composer" ]; then exit 0; fi

Execute import sql

if [ -f /home/vagrant/extra/db-dump-latest.sql.gz ]; then gunzip /home/vagrant/extra/db-dump-latest.sql.gz fi if [ -f /home/vagrant/extra/db-dump-latest.sql ]; then echo '--- Magento db dump import ---' mysql -u vagrant -pvagrant -e "USE ${PROJECT_NAME};SET FOREIGN_KEY_CHECKS = 0;source /home/vagrant/extra/db-dump-latest.sql;SET FOREIGN_KEY_CHECKS = 1;" mysql -u vagrant -pvagrant -e "USE ${PROJECT_NAME};SET FOREIGN_KEY_CHECKS = 0;TRUNCATE TABLE admin_passwords;TRUNCATE TABLE admin_user;SET FOREIGN_KEY_CHECKS = 1;" fi


5. Create extra/120-post-build.sh and add this script with your crypted key:

!/bin/bash

if [ $PROJECT_SOURCE == "composer" ]; then exit 0; fi

Crypted Key

sudo -u "$PROJECT_SETUP_OWNER" bin/magento setup:config:set -n --key "put here the value of your crypted key"


6. Once it's done you just have to add this in your Vagrantfile in order to upload the dump to guest machine.

Extra provisionner

... process_extra_file(config, 'extra/db-dump-latest.sql.gz') ...



7. Run vagrant provision and everything should work.

Hope this help.
zepgram commented 5 years ago

And then, in order to do your migration it's development time.

You can change the version of Magento in composer.json to 2.3.1 Then you can work under vagrant and run those commands: composer update magento setup:upgrade magento setup:di:compile

The compile should crash and you'll have to fix your code until it work.

This way you can achieve your migration from 2.1 to 2.3

ramzdam commented 5 years ago

And then, in order to do your migration it's development time.

You can change the version of Magento in composer.json to 2.3.1 Then you can work under vagrant and run this commands: composer update magento setup:upgrade magento setup:di:compile

The compile should crash and you'll have to fix your code until it work.

This way you can achieve your migration from 2.1 to 2.3

What you mean by this? Sorry but I set the magento on my yaml file as 2.3.1..

zepgram commented 5 years ago

The version of Magento in config.yaml is only used when you setup Magento as a clean state from composer, in your case you try to install it from an existing project with git. The version used will be based from your existing project not from config.yaml

ramzdam commented 5 years ago

I see I understand now. Will try your solution and will give feedback for this. Thanks a lot for the prompt reply.

zepgram commented 5 years ago

You have two way in order to achieve your migration:

So you can go from 2.2.1 to 2.3.1 or you can start with 2.3.1 and migrate your code. Don't know which one is the best in your case, the second way is a bit cheaty but easier.

ramzdam commented 5 years ago

Actually our project is already 2.3.1 so I don't need to do any of those stuff right? I just need to run vagrant up and everything will be fine? Since in our composer it's also defined as 2.3.1 for the version

zepgram commented 5 years ago

Sorry I mixed up with an other issue about migration .. I'm a bit confused. My bad, stay on my first answer!

ramzdam commented 5 years ago

Wow @zepgram your solution really works... Thanks a million dude. Hope this solution will be included in your future version. Really helpful for those having a dump and an existing project. Kudos to you dude