-
Notifications
You must be signed in to change notification settings - Fork 479
docs: add Yii 3 page #2615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KalimeroMK
wants to merge
2
commits into
php:main
Choose a base branch
from
KalimeroMK:docs/yii3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+93
−0
Open
docs: add Yii 3 page #2615
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,93 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||||||||||||||||||||
| title: Running Yii 3 with FrankenPHP (Docker, worker mode) | ||||||||||||||||||||||||||||||||||||||||||||||||
| description: How to run a Yii 3 application with FrankenPHP using the Docker image, a local install, or worker mode with the yii-runner-frankenphp package. | ||||||||||||||||||||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| # Yii 3 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| ## Running Yii 3 with the FrankenPHP Docker image | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Serving a [Yii](https://www.yiiframework.com/) web application with FrankenPHP is as easy as mounting the project in the `/app` directory of the official Docker image. | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Run this command from the main directory of your Yii app: | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| ```console | ||||||||||||||||||||||||||||||||||||||||||||||||
| docker run -p 80:80 -p 443:443 -p 443:443/udp -v $PWD:/app dunglas/frankenphp | ||||||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| And enjoy! | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| ## Installing Yii 3 with FrankenPHP locally | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Alternatively, you can run your Yii projects with FrankenPHP from your local machine: | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| 1. [Download the binary corresponding to your system](../#standalone-binary) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 2. Add the following configuration to a file named `Caddyfile` in the root directory of your Yii project: | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| ```caddyfile | ||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||
| frankenphp | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| # The domain name of your server | ||||||||||||||||||||||||||||||||||||||||||||||||
| localhost { | ||||||||||||||||||||||||||||||||||||||||||||||||
| # Enable compression (optional) | ||||||||||||||||||||||||||||||||||||||||||||||||
| encode zstd br gzip | ||||||||||||||||||||||||||||||||||||||||||||||||
| # Execute PHP files from the public/ directory and serve assets | ||||||||||||||||||||||||||||||||||||||||||||||||
| php_server { | ||||||||||||||||||||||||||||||||||||||||||||||||
| root public/ | ||||||||||||||||||||||||||||||||||||||||||||||||
| try_files {path} index.php | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| 3. Start FrankenPHP from the root directory of your Yii project: `frankenphp run` | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| ## Yii 3 worker mode | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| To run your Yii application in [worker mode](worker.md), install the [Yii FrankenPHP runner](https://github.com/yiisoft/yii-runner-frankenphp): | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| ```console | ||||||||||||||||||||||||||||||||||||||||||||||||
| composer require yiisoft/yii-runner-frankenphp | ||||||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Then create a file named `worker.php` in the root directory of your application: | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| ```php | ||||||||||||||||||||||||||||||||||||||||||||||||
| <?php | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| declare(strict_types=1); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| use Yiisoft\Yii\Runner\FrankenPHP\FrankenPHPApplicationRunner; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| require_once __DIR__ . '/vendor/autoload.php'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| (new FrankenPHPApplicationRunner(rootPath: __DIR__))->run(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Update your `Caddyfile` to start the application in worker mode: | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| ```caddyfile | ||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||
| frankenphp | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| localhost { | ||||||||||||||||||||||||||||||||||||||||||||||||
| encode zstd br gzip | ||||||||||||||||||||||||||||||||||||||||||||||||
| php_server { | ||||||||||||||||||||||||||||||||||||||||||||||||
| root public/ | ||||||||||||||||||||||||||||||||||||||||||||||||
| worker ./worker.php { | ||||||||||||||||||||||||||||||||||||||||||||||||
| # Send all requests to the worker | ||||||||||||||||||||||||||||||||||||||||||||||||
| match * | ||||||||||||||||||||||||||||||||||||||||||||||||
| # Reload workers when PHP files change (development only) | ||||||||||||||||||||||||||||||||||||||||||||||||
| watch ./**/*.php | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+75
to
+86
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not familiar with Yii, but wouldn't you want to send all request to the worker (via match *)
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| If your application is based on the [official Yii app template](https://github.com/yiisoft/app), see the [package README](https://github.com/yiisoft/yii-runner-frankenphp) for a complete `worker.php` example with debug, environment, and error handler configuration. | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| To limit the number of requests a worker handles before being restarted (useful to mitigate memory leaks), set the `MAX_REQUESTS` environment variable. By default, workers handle requests indefinitely. | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| When using worker mode, make sure stateful services are reset after each request. See the [worker mode documentation](worker.md) and the [Yii DI `StateResetter` documentation](https://github.com/yiisoft/di#resetting-services-state) for details. | ||||||||||||||||||||||||||||||||||||||||||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit more efficient to have the root inside php_server