feat: 创建 PHP 运行环境同步修改index目录文件和文件夹权限 (#644)

pull/655/head
zhengkunwang223 2 years ago committed by GitHub
parent 5ce1b1591a
commit 059c3a0b80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,6 +2,7 @@ package service
import (
"fmt"
"github.com/1Panel-dev/1Panel/backend/utils/cmd"
"path"
"strconv"
"strings"
@ -58,8 +59,6 @@ func createIndexFile(website *model.Website, runtime *model.Runtime) error {
if runtime.Type == constant.RuntimePHP {
indexPath = path.Join(indexFolder, "index.php")
indexContent = string(nginx_conf.IndexPHP)
} else {
return nil
}
}
@ -74,6 +73,11 @@ func createIndexFile(website *model.Website, runtime *model.Runtime) error {
return err
}
}
if runtime.Resource == constant.ResourceAppstore {
if err := chownRootDir(indexFolder); err != nil {
return err
}
}
if err := fileOp.WriteFile(indexPath, strings.NewReader(indexContent), 0755); err != nil {
return err
}
@ -97,13 +101,14 @@ func createWebsiteFolder(nginxInstall model.AppInstall, website *model.Website,
if err := fileOp.CreateFile(path.Join(siteFolder, "log", "error.log")); err != nil {
return err
}
if err := fileOp.CreateDir(path.Join(siteFolder, "index"), 0755); err != nil {
if err := fileOp.CreateDir(path.Join(siteFolder, "index"), 0775); err != nil {
return err
}
if err := fileOp.CreateDir(path.Join(siteFolder, "ssl"), 0755); err != nil {
return err
}
if website.Type == constant.Runtime && runtime.Type == constant.RuntimePHP && runtime.Resource == constant.ResourceLocal {
if website.Type == constant.Runtime {
if runtime.Type == constant.RuntimePHP && runtime.Resource == constant.ResourceLocal {
phpPoolDir := path.Join(siteFolder, "php-pool")
if err := fileOp.CreateDir(phpPoolDir, 0755); err != nil {
return err
@ -112,6 +117,7 @@ func createWebsiteFolder(nginxInstall model.AppInstall, website *model.Website,
return err
}
}
}
if website.Type == constant.Static || website.Type == constant.Runtime {
if err := createIndexFile(website, runtime); err != nil {
return err
@ -505,3 +511,11 @@ func checkIsLinkApp(website model.Website) bool {
}
return false
}
func chownRootDir(path string) error {
_, err := cmd.ExecWithTimeOut(fmt.Sprintf("chown -R 1000:1000 %s", path), 1*time.Second)
if err != nil {
return err
}
return nil
}

Loading…
Cancel
Save