• We value your experience with Plesk during 2024
    Plesk strives to perform even better in 2025. To help us improve further, please answer a few questions about your experience with Plesk Obsidian 2024.
    Please take this short survey:

    https://pt-research.typeform.com/to/AmZvSXkx
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

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