Automattic / Automattic/studio
Studio native PHP runtime doesn't support CGI `file.php/[path]` routing
- Dominant language
- TypeScript
- Stars
- 517
- Forks
- 95
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 172
Description
Not sure whether this is a feature request or bug report so opened a blank issue instead.
## Background
I was trying to set up simplesaml.php but ran into problems with routing paths like `/simplesaml/module.php/admin/test/default-sp` in the same way that my managed host does - i.e. resolving to `simplesaml/module.php`, with `PATH_INFO` set to `'/admin/test/default-sp'`, as per [CGI](https://datatracker.ietf.org/doc/html/rfc3875). I would get 404s or redirects to the site route. The same setup worked fine on my managed host.
## Desired behaviour
When a path is of the form `foo/bar.php/baz/qux`, the script at `foo/bar.php` should be run with `PATH_INFO` set to `'/baz/qux'`. Similarly, if `foo/bar/index.php` is a file, but neither `foo/bar/baz` nor `foo/bar/baz/qux` resolve to a file or a directory with an index script, then `foo/bar/index.php` should be run with `PATH_INFO` as before. This is in contrast to the current behaviour, where if the full path resolves to neither a file nor a directory with an `index.php`, then the router falls through to WordPress.
It would be great if this could be an option, or enabled by default, in the native php runtime in WordPress Studio, as I'd imagine that this sort of setup - where other pieces of software are running alongside WordPress and using the CGI protocol - can't be too uncommon.
This behaviour is exhibited in the [PHP built-in web server](https://www.php.net/manual/en/features.commandline.webserver.php#:~:text=If%20neither%20file%20exists%2C%20the%20lookup%20for%20index.php%20and%20index.html%20will%20be%20continued%20in%20the%20parent%20directory%20and%20so%20on%20until%20one%20is%20found%20or%20the%20document%20root%20has%20been%20reached.%20If%20an%20index.php%20or%20index.html%20is%20found%2C%20it%20is%20returned%20and%20%24_SERVER%5B%27PATH_INFO%27%5D%20is%20set%20to%20the%20trailing%20part%20of%20the%20URI) and [sometimes Apache](https://httpd.apache.org/docs/trunk/mod/core.html#acceptpathinfo), in sensible situations; for context, I didn't have to do any additional setup on my managed hosting in order to make the above work. Therefore, I think it would be quite reasonable for Studio to support this behaviour too.
## Minimal test case
As a small reproducible testcase of the desired behaviour, if I were to create a file named `test.php` in the root of my wordpress site (created with `studio create`) with the following code:
```php
Contributor guide
Research direction
Reproduce the issue with `studio config set --runtime=native`, `studio start --skip-browser`, and a root `test.php`, then trace the native PHP runtime's router. Compare the request at `/test.php/foo/bar` with the desired `SCRIPT_NAME` and `PATH_INFO` values; done means the PHP script runs with `PATH_INFO` set correctly instead of returning a 404 or falling through to WordPress.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100