How to Install Module or Run CLI Command Without SSH in Magento 2

Lots of Developer and Site Admin have a problem to run command and install module in Magento 2 when there hosting provider does’n provide SSH/CLI Access. In this post we give a custom solution for that. So, you just don’t worry about that. Follow this post and Install Module or Run CLI Command Without SSH/CLI in Magento 2.

We have a two solution for that.

First Solution

If you don’t have permission of CLI. Then we think system() function will help you on this.

To use this function , just simple create command.php file in your Magento root, then write below code in this file.

saveCopyzoom_out_map
<?php echo "<pre>"; system('php bin/magento setup:upgrade'); // You can change command as you want. echo "</pre>";

And run this script with http://domain.com/command.php It will gives you resulted output.

Second Solution

If you want to run Magento 2 command without CLI then we have a another solution for that, but it doesn’t gives you any message (Success or Fail), but you can use this if you don’t have any option.

For that you have to create command.php file in your Magento root, and paste below code in command.php file.

saveCopyzoom_out_map
<?php use Magento\Framework\App\Bootstrap; require __DIR__ . '/app/bootstrap.php'; $bootstrap = Bootstrap::create(BP, $_SERVER); $obj = $bootstrap->getObjectManager(); $state = $obj->get('Magento\Framework\App\State'); $state->setAreaCode('frontend'); $k[0]='bin/magento'; $k[1]='setup:upgrade'; // You can change command as you want like setup:static-content:deploy, cache:status etc. $_SERVER['argv']=$k; try { $handler = new \Magento\Framework\App\ErrorHandler(); set_error_handler([$handler, 'handler']); $application = new Magento\Framework\Console\Cli('Magento CLI'); $application->run(); } catch (\Exception $e) { while ($e) { echo $e->getMessage(); echo $e->getTraceAsString(); echo "\n\n"; $e = $e->getPrevious(); }

And run this script with http://domain.com/command.php it doesn’t gives you any message (Success or Fail), but you can use this as a second option.

That’s it, we hope this Magento post helped you to know How to Install Exetnsion or Run Command Without SSH/CLI in Magento 2.

Bookmark it for your future reference. Do comment below if you have any other questions or doubts.

P.S. Do share this post with your team.

Review other articles maybe it'll help you too.




Recent Articles
Tags
Newsletter
Chrome Extension
Copyright © 2024 devhooks.in All rights reserved.
Ads OFF toggle_off
wifi_off