• 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
  • Inviting everyone to the UX test of a new security feature in the WP Toolkit
    For WordPress site owners, threats posed by hackers are ever-present. Because of this, we are developing a new security feature for the WP Toolkit. If the topic of WordPress website security is relevant to you, we would be grateful if you could share your experience and help us test the usability of this feature. We invite you to join us for a 1-hour online session via Google Meet. Select a convenient meeting time with our friendly UX staff 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