• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion
  • Please beaware of a breaking change in the REST API on the next Plesk release (18.0.62).
    Starting from Plesk Obsidian 18.0.62, requests to REST API containing the Content-Type header with a media-type directive other than “application/json” will result in the HTTP “415 Unsupported Media Type” client error response code. Read more here

Issue FileManager and ServerFileManager permission issue

sfsdg

New Pleskian
I'm need to copy subdomain files to new domain folder, i have a custom extension. This extension using pm_ServerFileManager class's copyFile method. But files are copying with root user? If I use pm_FileManager extension return Permission error like "filemng failed: filemng: stat failed: Permission denied. System error 13: Permission denied"

Here is my code;

PHP:
protected function _run()
    {
        $from = $this->_params["from"];
        $to = $this->_params["to"];
        $defaultDbUsername = $this->_params["defaultDbUsername"];
        $defaultDbPassword = $this->_params["defaultDbPassword"];

        $domain = new \pm_Domain();

        $fromDomain =  $domain->getByDomainId($from);
        $toDomain =  $domain->getByDomainId($to);
  
        $fromDomainDocumentRoot = $fromDomain->getDocumentRoot();
        $toDomainDocumentRoot = $toDomain->getDocumentRoot();

        $fileManager = new \pm_FileManager($to);

        //Yükleme yapılacak site klsörünü temizleme
        $toFilePath = $fileManager->scanDir($toDomainDocumentRoot, true);
        foreach ($toFilePath as $value) {
            $fileManager->removeFile($toDomainDocumentRoot . "/" . $value);
        }

        //Wordpress yükleme
        $fromFilePath = $fileManager->scanDir($fromDomainDocumentRoot, true);
        foreach ($fromFilePath as $value) {
            $fileManager->copyFile($fromDomainDocumentRoot . "/" . $value, $toDomainDocumentRoot);
            //$fileManager->chmod($fromDomainDocumentRoot . "/" . $value, "755");
        }

        $toFileContents = $fileManager->fileGetContents($toDomainDocumentRoot . "/wp-config.php");

        $domainName = $domain->getName();

        $toFileContents = preg_replace('/define\(\'DB_NAME\', \'(.*?)\'\);/', "define('DB_NAME', '$domainName');", $toFileContents);
        $toFileContents = preg_replace('/define\(\'DB_USER\', \'(.*?)\'\);/', "define('DB_USER', '$defaultDbUsername');", $toFileContents);
        $toFileContents = preg_replace('/define\(\'DB_PASSWORD\', \'(.*?)\'\);/', "define('DB_PASSWORD', '$defaultDbPassword');", $toFileContents);

        $fileManager->filePutContents($toDomainDocumentRoot . "/wp-config.php", $toFileContents);


        return [
            'status' => true,
        ];
    }

This return like that result
Code:
<?xml version="1.0" encoding="UTF-8"?>
<packet version="1.6.8.0">
  <extension>
    <call>
      <result>
        <status>error</status>
        <errcode>1002</errcode>
        <errtext>filemng failed: filemng: stat failed: Permission denied

System error 13: Permission denied</errtext>
      </result>
    </call>
  </extension>
</packet>

If I use pm_ServerFileManager class code works perfectly but files are copy with root user;
roo_problem.png


Edit:
I'm researching already for this post. And everybody says like "this is not possible". But wp-toolkit and "Plesk Web Clone" doing this, how?
 
Last edited:
If customers are custom (not Administrator) and different or same I can copy files between domains. This is local, if I go to real server on the I can't do this.
 
Back
Top