mirror of
https://github.com/php/frankenphp.git
synced 2026-03-24 00:52:11 +01:00
feat: enable resolve_root_symlink by default (#546)
* feat: enable resolve_root_symlink by default * Update docs/config.md Co-authored-by: Francis Lavoie <lavofr@gmail.com> * fix init --------- Co-authored-by: Francis Lavoie <lavofr@gmail.com>
This commit is contained in:
@@ -59,6 +59,7 @@ You can also run command-line scripts with:
|
||||
* [Create **standalone**, self-executable PHP apps](https://frankenphp.dev/docs/embed/)
|
||||
* [Create static binaries](https://frankenphp.dev/docs/static/)
|
||||
* [Compile from sources](https://frankenphp.dev/docs/compile/)
|
||||
* [Laravel integration](https://frankenphp.dev/docs/laravel/)
|
||||
* [Known issues](https://frankenphp.dev/docs/known-issues/)
|
||||
* [Demo app (Symfony) and benchmarks](https://github.com/dunglas/frankenphp-demo)
|
||||
* [Go library documentation](https://pkg.go.dev/github.com/dunglas/frankenphp)
|
||||
|
||||
@@ -203,7 +203,7 @@ type FrankenPHPModule struct {
|
||||
// SplitPath sets the substrings for splitting the URI into two parts. The first matching substring will be used to split the "path info" from the path. The first piece is suffixed with the matching substring and will be assumed as the actual resource (CGI script) name. The second piece will be set to PATH_INFO for the CGI script to use. Default: `.php`.
|
||||
SplitPath []string `json:"split_path,omitempty"`
|
||||
// ResolveRootSymlink enables resolving the `root` directory to its actual value by evaluating a symbolic link, if one exists.
|
||||
ResolveRootSymlink bool `json:"resolve_root_symlink,omitempty"`
|
||||
ResolveRootSymlink *bool `json:"resolve_root_symlink,omitempty"`
|
||||
// Env sets an extra environment variable to the given value. Can be specified more than once for multiple environment variables.
|
||||
Env map[string]string `json:"env,omitempty"`
|
||||
logger *zap.Logger
|
||||
@@ -225,8 +225,9 @@ func (f *FrankenPHPModule) Provision(ctx caddy.Context) error {
|
||||
if frankenphp.EmbeddedAppPath == "" {
|
||||
f.Root = "{http.vars.root}"
|
||||
} else {
|
||||
rrs := false
|
||||
f.Root = filepath.Join(frankenphp.EmbeddedAppPath, defaultDocumentRoot)
|
||||
f.ResolveRootSymlink = false
|
||||
f.ResolveRootSymlink = &rrs
|
||||
}
|
||||
} else {
|
||||
if frankenphp.EmbeddedAppPath != "" && filepath.IsLocal(f.Root) {
|
||||
@@ -238,6 +239,11 @@ func (f *FrankenPHPModule) Provision(ctx caddy.Context) error {
|
||||
f.SplitPath = []string{".php"}
|
||||
}
|
||||
|
||||
if f.ResolveRootSymlink == nil {
|
||||
rrs := true
|
||||
f.ResolveRootSymlink = &rrs
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -257,7 +263,7 @@ func (f FrankenPHPModule) ServeHTTP(w http.ResponseWriter, r *http.Request, _ ca
|
||||
|
||||
fr, err := frankenphp.NewRequestWithContext(
|
||||
r,
|
||||
frankenphp.WithRequestDocumentRoot(documentRoot, f.ResolveRootSymlink),
|
||||
frankenphp.WithRequestDocumentRoot(documentRoot, *f.ResolveRootSymlink),
|
||||
frankenphp.WithRequestSplitPath(f.SplitPath),
|
||||
frankenphp.WithRequestEnv(env),
|
||||
)
|
||||
@@ -298,9 +304,18 @@ func (f *FrankenPHPModule) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||
|
||||
case "resolve_root_symlink":
|
||||
if d.NextArg() {
|
||||
if v, err := strconv.ParseBool(d.Val()); err == nil {
|
||||
f.ResolveRootSymlink = &v
|
||||
|
||||
if d.NextArg() {
|
||||
return d.ArgErr()
|
||||
}
|
||||
}
|
||||
|
||||
return d.ArgErr()
|
||||
}
|
||||
f.ResolveRootSymlink = true
|
||||
rrs := true
|
||||
f.ResolveRootSymlink = &rrs
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -444,7 +459,8 @@ func parsePhpServer(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)
|
||||
if phpsrv.Root == "" {
|
||||
phpsrv.Root = filepath.Join(frankenphp.EmbeddedAppPath, defaultDocumentRoot)
|
||||
fsrv.Root = phpsrv.Root
|
||||
phpsrv.ResolveRootSymlink = false
|
||||
rrs := false
|
||||
phpsrv.ResolveRootSymlink = &rrs
|
||||
} else if filepath.IsLocal(fsrv.Root) {
|
||||
phpsrv.Root = filepath.Join(frankenphp.EmbeddedAppPath, phpsrv.Root)
|
||||
fsrv.Root = phpsrv.Root
|
||||
|
||||
@@ -125,9 +125,11 @@ func cmdPHPServer(fs caddycmd.Flags) (int, error) {
|
||||
extensions := []string{"php"}
|
||||
tryFiles := []string{"{http.request.uri.path}", "{http.request.uri.path}/" + indexFile, indexFile}
|
||||
|
||||
rrs := true
|
||||
phpHandler := FrankenPHPModule{
|
||||
Root: root,
|
||||
SplitPath: extensions,
|
||||
Root: root,
|
||||
SplitPath: extensions,
|
||||
ResolveRootSymlink: &rrs,
|
||||
}
|
||||
|
||||
// route to redirect to canonical path if index PHP file
|
||||
|
||||
@@ -122,7 +122,7 @@ The `php_server` and the `php` directives have the following options:
|
||||
php_server [<matcher>] {
|
||||
root <directory> # Sets the root folder to the site. Default: `root` directive.
|
||||
split_path <delim...> # Sets the substrings for splitting the URI into two parts. The first matching substring will be used to split the "path info" from the path. The first piece is suffixed with the matching substring and will be assumed as the actual resource (CGI script) name. The second piece will be set to PATH_INFO for the CGI script to use. Default: `.php`
|
||||
resolve_root_symlink # Enables resolving the `root` directory to its actual value by evaluating a symbolic link, if one exists.
|
||||
resolve_root_symlink false # Disables resolving the `root` directory to its actual value by evaluating a symbolic link, if one exists (enabled by default).
|
||||
env <key> <value> # Sets an extra environment variable to the given value. Can be specified more than once for multiple environment variables.
|
||||
}
|
||||
```
|
||||
|
||||
@@ -32,10 +32,7 @@ Alternatively, you can run your Laravel projects with FrankenPHP from your local
|
||||
# Enable compression (optional)
|
||||
encode zstd br gzip
|
||||
# Execute PHP files in the current directory and serve assets
|
||||
php_server {
|
||||
# Required for the public/storage/ dir
|
||||
resolve_root_symlink
|
||||
}
|
||||
php_server
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user