Вопрос

I am working third party integration for which new files generating automatically when my code is running.

But it required permission after creating the file.

I want to give the permission as a root user?

I have tried like this shell_exec("chmod -R 777 /run/folderName/filename");

But this is not working

Нет правильного решения

Другие советы

Try to use this below code from root file :

<?php

error_reporting(1);
ini_set('max_execution_time', 0);
use \Magento\Framework\App\Bootstrap;

require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('\Magento\Framework\App\State');
$state->setAreaCode('frontend');
$drive = $objectManager->get('\Magento\Framework\Shell\Driver');
$collections = $drive->execute('chmod -R 777 /run/folderName/filename',[]);

Hope, It will helpful for you.

Disclaimer: Try to avoid setting 777 on files and run functions as root in php due to security concerns.

But if you really want to use shell commands as root from PHP can you can do so like below. I also recommend using Rohans implementation instead of using native shell_exec to decouple your logic from the implementation.

<?php

shell_exec("echo mysudopassword | /usr/bin/sudo -S chown -R 655 /some/path/to/things");

As a side note you PHP has its over permission management functions, although not useful in your case since they will run as the PHP user. https://www.php.net/manual/en/function.chmod.php https://www.php.net/manual/en/function.chown.php

Лицензировано под: CC-BY-SA с атрибуция
Не связан с magento.stackexchange
scroll top