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
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
-
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?– larpSep 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– AnthonySep 14, 2018 at 5:49
-
I asked that before to the hosting provider, but they dont give us shell access/ssh account.– larpSep 14, 2018 at 5:54
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();
}`
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();
}
}
-
-
-
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– larpSep 14, 2018 at 6:29
-