From 1b510db71b0ca65c332ae1bafc1bbaf90ba91958 Mon Sep 17 00:00:00 2001 From: Mohammed Al Ashaal Date: Sat, 12 Aug 2023 11:12:38 +0300 Subject: [PATCH 1/5] Delete phoo.yaml --- example/phoo.yaml | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 example/phoo.yaml diff --git a/example/phoo.yaml b/example/phoo.yaml deleted file mode 100644 index a3603c0..0000000 --- a/example/phoo.yaml +++ /dev/null @@ -1,18 +0,0 @@ -document_root: "./example" -default_script: "./example/index.php" -gzip_level: 0 -http_listen_addr: ":8000" -data_dir: ".phoo" -enable_access_logs: true - -env: - APP_NAME: "laravel" - APP_ENV: "debug" - -fpm: - bin: "php-fpm8.2" - worker_count: 4 - worker_max_requests: 500 - -ini: - display_errors: On From ab873a023870c1455d8ed963340c0aef2fde72ce Mon Sep 17 00:00:00 2001 From: Mohammed Al Ashaal Date: Tue, 22 Aug 2023 13:20:01 +0300 Subject: [PATCH 2/5] Update README.md --- README.md | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 8027270..626c488 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ PHOO Examples ======== -> Imagine you have a php application uses modern framework like laravel, symfony ... etc +> Imagine you have a php application that uses a modern framework like laravel, Symfony... etc > that app contains a public directory, and that public directory contains the main bootstrap file that -> serves the incoming requests named as `index.php`. +> serves the incoming requests named `index.php`. ```shell -# this all what you need to serve a laravel application! +# this is all that you need to serve a laravel application! $ phoo serve -r ./public ⇨ http server started on [::]:8000 ``` @@ -26,22 +26,29 @@ $ phoo serve -r ./public --http 0.0.0.0:80 $ phoo serve -r ./public -i display_errors=Off -i another_key=another_value ⇨ http server started on [::]:8000 ``` -#### I have a high traffic web-app and I want to increase the php workers +#### I have a high traffic web app and I want to increase the number of php workers ```shell -# just increase the workers count +# increase the workers' count $ phoo serve -r ./public --workers=20 ⇨ http server started on [::]:8000 ``` -#### Hmmmm, but I want to monitor my app via prometheus metrics, I don't want to do it manually +#### Hmmmm, but I want to monitor my app via Prometheus metrics, I don't want to do it manually ```shell -# no need to do it yourself, this will enable prometheus metrics at the specified `/metrics` path +# no need to do it yourself, this will enable Prometheus metrics at the specified `/metrics` path $ phoo serve -r ./public --metrics "/metrics" ⇨ http server started on [::]:8000 ``` -#### Wow!, seems `phoo` has a lot of simple flags/configs, is it documented anywhere? -> just run `phoo serve --help` and enjoy it :), you will find that you can also pass flags via `ENV` vars, and it will automatically read `.env` file in the current working directory. +#### Can I choose the `php-fpm` version / binary path? +```shell +# Of course +$ phoo serve -r ./public --fpm "php-fpm8.2" +⇨ http server started on [::]:8000 +``` + +#### Wow!, it seems `phoo` has a lot of simple flags/configs, is it documented anywhere? +> Just run `phoo serve --help` and enjoy it :), you will find that you can also pass flags via `ENV` vars, and it will automatically read the `.env` file in the current working directory. Requirements ============ @@ -57,4 +64,4 @@ Installation TODOs ===== - [ ] Add `.env.example` with comments to describe each var. -- [ ] Add future plans/thoughts. \ No newline at end of file +- [ ] Add future plans/thoughts. From 98e925ad44a76d74a13aea5c6fa57e865ed6d2f9 Mon Sep 17 00:00:00 2001 From: Mohamed Al Ashaal Date: Tue, 12 Sep 2023 12:51:52 +0300 Subject: [PATCH 3/5] added www-data as default user and group --- go.mod | 6 ++---- go.sum | 5 ++--- internals/fpm/php-fpm.conf | 2 ++ 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 5708fdd..08fe3ba 100644 --- a/go.mod +++ b/go.mod @@ -3,23 +3,21 @@ module github.com/alash3al/phoo go 1.21 require ( + github.com/joho/godotenv v1.5.1 + github.com/labstack/echo-contrib v0.15.0 github.com/labstack/echo/v4 v4.11.1 github.com/urfave/cli/v2 v2.25.7 github.com/valyala/fasttemplate v1.2.2 github.com/yookoala/gofast v0.7.0 - gopkg.in/yaml.v3 v3.0.1 ) require ( github.com/beorn7/perks v1.0.1 // indirect - github.com/caarlos0/env/v9 v9.0.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/golang/protobuf v1.5.2 // indirect - github.com/joho/godotenv v1.5.1 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/labstack/echo-contrib v0.15.0 // indirect github.com/labstack/gommon v0.4.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.19 // indirect diff --git a/go.sum b/go.sum index f4eea9a..13a123c 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/caarlos0/env/v9 v9.0.0 h1:SI6JNsOA+y5gj9njpgybykATIylrRMklbs5ch6wO6pc= -github.com/caarlos0/env/v9 v9.0.0/go.mod h1:ye5mlCVMYh6tZ+vCgrs/B95sj88cg5Tlnc0XIzgZ020= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= @@ -18,6 +16,8 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= @@ -121,7 +121,6 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/ini.v1 v1.38.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internals/fpm/php-fpm.conf b/internals/fpm/php-fpm.conf index 19751fc..5b0b8e9 100644 --- a/internals/fpm/php-fpm.conf +++ b/internals/fpm/php-fpm.conf @@ -12,3 +12,5 @@ pm.max_children = {{worker.count}} pm.max_requests = {{worker.request.max_count}} request_terminate_timeout = {{worker.request.max_time}} clear_env = no +user = www-data +group = www-data \ No newline at end of file From 4a91363a8f3cd6ab71e97dbff8b29e879dd6035a Mon Sep 17 00:00:00 2001 From: Mohamed Al Ashaal Date: Tue, 12 Sep 2023 13:12:55 +0300 Subject: [PATCH 4/5] added .env.example --- .env.example | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/.env.example b/.env.example index e69de29..71e7055 100644 --- a/.env.example +++ b/.env.example @@ -0,0 +1,66 @@ +# the path to document root used as static file server root +PHOO_DOCUMENT_ROOT="./public" + +# the main php script that acts as the server +# this is the default implementation in modern frameworks +# like laravel, symfony, ... etc +PHOO_ENTRYPOINT="./public/server.php" + +# the http listen address in the form of [address]:port +PHOO_HTTP_LISTEN_ADDR=":8000" + +# whether to enable access logs or not +PHOO_ENABLE_ACCESS_LOGS=false + +# the php-fpm binary filename/filepath +PHOO_PHP_FPM="php-fpm" + +# the directory to store phoo internal temp files in +PHOO_DATA_DIR="./.phoo" + +# php ini settings in the form of key=value +# you can pass multiple key=value pairs separated by ';' +# Example: PHOO_PHP_INI="upload_max_filesize=6M;post_max_size=30M" +PHOO_PHP_INI="" + +# php fpm workers, this is the maximum requests to be served at the same time +# the default value is the machine cpus count +PHOO_WORKER_COUNT= + +# php fpm max requests per worker, +# if a worker reached this number, it would be recycled +# this is helpful to guard against memory leeks. +PHOO_WORKER_MAX_REQUEST_COUNT= $PHOO_WORKER_COUNT * 100 + +# php fpm max request time in seconds per worker, +# if a worker reached this number, it would be terminated. +# 0 means 'Disabled' +PHOO_WORKER_MAX_REQUEST_TIME="300" + +# the prometheus metrics endpoint, empty means disabled. +# default is empty (disabled) +PHOO_METRICS_PATH= + +# whether to enable/disable the cors-* features/flags +PHOO_CORS_ENABLED=false + +# this flag adds the specified origin to the list of allowed cors origins. +# you can pass multiple origins separated by ';' +# Example: PHOO_CORS_ORIGINS="host-name1;host-name2" +PHOO_CORS_ORIGINS="*" + +# this flag adds the specified headers to the list of allowed cors headers the client can send. +# you can pass multiple origins separated by ';' +# Example: PHOO_CORS_HEADERS="header-1;header-2" +PHOO_CORS_HEADERS="" + +# this flag adds the specified headers to the list of allowed headers the client can access +# you can pass multiple origins separated by ';' +# Example: PHOO_CORS_EXPOSE="header-1;header-2" +PHOO_CORS_EXPOSE="" + +# this flag indicates whether or not the actual request can be made using credentials +PHOO_CORS_CREDENTIALS=false + +# the cors max_age in seconds +PHOO_CORS_AGE=0 From 25a3943c3d7c98b15e545b253b58326cdaa0c56e Mon Sep 17 00:00:00 2001 From: Mohamed Al Ashaal Date: Tue, 12 Sep 2023 13:13:16 +0300 Subject: [PATCH 5/5] updated README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8027270..4c20f9b 100644 --- a/README.md +++ b/README.md @@ -56,5 +56,5 @@ Installation TODOs ===== -- [ ] Add `.env.example` with comments to describe each var. +- [x] Add `.env.example` with comments to describe each var. - [ ] Add future plans/thoughts. \ No newline at end of file