0

I tried the system() ex.( system(php bin/magento setup:upgrade) ) function of PHP to execute the CLI command of Magento, but no luck. Is there any other way? It is very hassle to use Flush Static Files Cache in Admin Panel just to apply the CSS or JS I added. We are using shared server, that means there is no SSH Account provided to us.

3 Answers 3

0

Login through SSH to your server (using something like PUTTY)

Use the command

cd path/to/magento/install/

Obviously change the path above to your actual Magento install, maybe

cd public_html/magento/

From there to install a module

php bin/magento setup:upgrade

php bin/magento setup:di:compile

php bin/magento setup:static-content:deploy

NOTE: FTP into your server and check in public_html/magento/bin/ that the magento file has the permission to be executed i.e. 0744

3
  • We have no SSH account, since we are only using shared server. Is there other way to run the CLI commands through file and execute it browser?
    – larp
    Sep 14, 2018 at 5:34
  • You would need to use the object manager class in a module as per below. I would STRONGLY suggest you ask your hosting provider to give you some kind of shell access
    – Anthony
    Sep 14, 2018 at 5:49
  • I asked that before to the hosting provider, but they dont give us shell access/ssh account.
    – larp
    Sep 14, 2018 at 5:54
0

Try this `
getObjectManager();

$modules = array('VENDORNAME_MODULENAME');
try{
    /* Code to enable a module [ php bin/magento module:enable VENDORNAME_MODULENAME ] */
    $moduleStatus = $objectManager->create('Magento\Framework\Module\Status')->setIsEnabled(true,$modules);


    /* Code to run setup upgrade [ php bin/magento setup:upgrade ] */
    $installerFactory = $objectManager->create('Magento\Setup\Test\Unit\Console\Command\UpgradeCommandTest')->testExecute();


    /* Code to clean cache [ php bin/magento:cache:clean ] */
    try{
        $_cacheTypeList = $objectManager->create('Magento\Framework\App\Cache\TypeListInterface');
        $_cacheFrontendPool = $objectManager->create('Magento\Framework\App\Cache\Frontend\Pool');
        $types = array('config','layout','block_html','collections','reflection','db_ddl','eav','config_integration','config_integration_api','full_page','translate','config_webservice');
        foreach ($types as $type) {
            $_cacheTypeList->cleanType($type);
        }
        foreach ($_cacheFrontendPool as $cacheFrontend) {
            $cacheFrontend->getBackend()->clean();
        }
    }catch(Exception $e){
        echo $msg = 'Error during cache clean: '.$e->getMessage();die();
    }   
}catch(Exception $e){
    echo $msg = 'Error during module enabling : '.$e->getMessage();die();
}`
7
  • Where to upload and run this codes? @Rahul.
    – larp
    Sep 14, 2018 at 5:32
  • create your simple plugin and add controller Sep 20, 2018 at 2:42
  • Then how to run this codes after creating a plugin?
    – larp
    Sep 20, 2018 at 3:22
  • opps sorry your module already not enable .. Sep 20, 2018 at 4:15
  • work with exciting enabled module Sep 20, 2018 at 4:16
0

Add your module name in app/etc/config.php like as

'Vendor_Module'=>1

Then run below code from root like as create file custom.php in root

Then run url like as below

http://your domain url/custom.php

<?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'; // write your proper command like setup:upgrade,cache:enable 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();
    }
}
10
  • So the code above will also be named 'Vendor_Module.php' ?
    – larp
    Sep 14, 2018 at 6:04
  • see my post i have write file name and way of code run Sep 14, 2018 at 6:05
  • what is your module name check in regisration.php file inside module Sep 14, 2018 at 6:07
  • \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Vendor_Module', DIR ); this is the code inside registration.php
    – larp
    Sep 14, 2018 at 6:29
  • After I run this codes it returns blank. No notification/message.
    – larp
    Sep 14, 2018 at 6:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.