php-pm / php-pm

PPM is a process manager, supercharger and load balancer for modern PHP applications.
MIT License
6.56k stars 367 forks source link

Can't bring php-pm to life in Symfony5 #502

Open Sauerbrei opened 4 years ago

Sauerbrei commented 4 years ago

Basically, I did these steps:

symfony new ppm-test cd ppm-test docker run -vpwd:/var/www -p 8080:80 phppm/nginx --static-directory=public/

Output:

/var/www
+---------------------+--------------------------+
| bridge              | HttpKernel               |
| host                | 127.0.0.1                |
| port                | 8080                     |
| workers             | 8                        |
| app-env             | dev                      |
| debug               | 0                        |
| logging             | 1                        |
| static-directory    | web/                     |
| bootstrap           | PHPPM\Bootstraps\Symfony |
| max-requests        | 1000                     |
| max-execution-time  | 30                       |
| memory-limit        | -1                       |
| ttl                 | 0                        |
| populate-server-var | 1                        |
| socket-path         | /ppm/run                 |
| pidfile             | /ppm/ppm.pid             |
| reload-timeout      | 30                       |
| cgi-path            | /usr/bin/php-cgi7        |
+---------------------+--------------------------+
Starting PHP-PM with 8 workers, using StreamSelectLoop ...
--- Worker 5502 stderr ---
Uncaught Exception: Symfony Kernel class was not found in the configured locations. Given: '\AppKernel'
Application bootstrap failed. Restarting worker #5502 ...
--- Worker 5501 stderr ---
Uncaught Exception: Symfony Kernel class was not found in the configured locations. Given: '\AppKernel'
Application bootstrap failed. Restarting worker #5501 ...
--- Worker 5504 stderr ---
Uncaught Exception: Symfony Kernel class was not found in the configured locations. Given: '\AppKernel'
Application bootstrap failed. Restarting worker #5504 ...
Server is shutting down.
Stopping the process manager.

Tried then to start the server via packages: composer require php-pm/php-pm-httpkernel composer require php-pm/php-pm vendor/bin/ppm start --app-env=dev --logging=0 --debug=1 --workers=8 --port 8099 --cgi-path=

(I have no clue why I have to add --cgi-path= in order to bypass an error) Output:

/some/local/directory
+---------------------+--------------------------+
| bridge              | HttpKernel               |
| host                | 127.0.0.1                |
| port                | 8099                     |
| workers             | 8                        |
| app-env             | dev                      |
| debug               | 1                        |
| logging             | 0                        |
| static-directory    |                          |
| bootstrap           | PHPPM\Bootstraps\Symfony |
| max-requests        | 1000                     |
| max-execution-time  | 30                       |
| memory-limit        | -1                       |
| ttl                 | 0                        |
| populate-server-var | 1                        |
| socket-path         | .ppm/run/                |
| pidfile             | .ppm/ppm.pid             |
| reload-timeout      | 30                       |
| cgi-path            |                          |
+---------------------+--------------------------+
Starting PHP-PM with 8 workers, using StreamSelectLoop ...
--- Worker 5501 stderr ---
sh: 1: exec: : Permission denied
--- Worker 5502 stderr ---
sh: 1: exec: : Permission denied
--- Worker 5503 stderr ---
sh: 1: exec: : Permission denied
--- Worker 5504 stderr ---
sh: 1: exec: : Permission denied
--- Worker 5506 stderr ---
sh: 1: exec: : Permission denied
--- Worker 5507 stderr ---
sh: 1: exec: : Permission denied
--- Worker 5508 stderr ---
sh: 1: exec: : Permission denied
--- Worker 5505 stderr ---
sh: 1: exec: : Permission denied
Server is shutting down.
Stopping the process manager.

My goal is to run ppm and symfony via docker-compose. In first place I just want to get it work :D Help is very welcome :)

dave-redfern commented 4 years ago

@Sauerbrei the first error is because the Kernel cannot be located. This could be because you have not correctly mounted your current working directory to the Docker container; or depending on what you named the namespace in src/Kernel.php you may need to export the APP_KERNEL_NAMESPACE env var. The PHP-PM Symfony bootstrap will try both App\Kernel and AppKernel.

Re: cgi-path: you have to specify this as the PHP CGI bin file is not in a consistent location across OSs (macOS brew is: /usr/local/bin/php-cgi, Alpine is: /usr/bin/php-cgi7, CentOS is: /usr/bin/php-cgi etc etc). Depending on your OS you may have to install php-cgi explicitly as it is sometimes packaged separately.

acasademont commented 3 years ago

Hi @Sauerbrei any more info about this?

Sauerbrei commented 3 years ago

Hey @acasademont I tried what was written above but stumbled upon more errors. After considering the documentation twice and also now, I have had no progress, so I abandon my project with php-pm. Sorry for that.

acasademont commented 3 years ago

@Sauerbrei now the error seems more clear, by default php-pm searches for the main symfony kernel at \App\Kernel or \AppKernel. If you have a custom Kernel or in a different namespace you have the APP_KERNEL_NAMESPACE and APP_KERNEL_CLASS_NAME to fix it.

So where does your Kernel class live?

Sauerbrei commented 3 years ago

@acasademont ok, lets give it a last shot.

So, I am using the default symfony kernel, no changes within the symfony skeleton. My Symfony version is 5.1.2. That means my Kernel lives at App\Kernel. I already added to my .env

APP_KERNEL_NAMESPACE=App\
APP_KERNEL_CLASS_NAME=Kernel
APP_ENV=dev
APP_SECRET=xxx

image

Now, the following happens:

$ docker run -v `pwd`:/var/www -p 8080:80 phppm/nginx --bootstrap=symfony --static-directory=public/
/var/www
+---------------------+-------------------+
| bridge              | HttpKernel        |
| host                | 127.0.0.1         |
| port                | 8080              |
| workers             | 8                 |
| app-env             | dev               |
| debug               | 0                 |
| logging             | 1                 |
| static-directory    | public/           |
| bootstrap           | symfony           |
| max-requests        | 1000              |
| max-execution-time  | 30                |
| memory-limit        | -1                |
| ttl                 | 0                 |
| populate-server-var | 1                 |
| socket-path         | /ppm/run          |
| pidfile             | /ppm/ppm.pid      |
| reload-timeout      | 30                |
| cgi-path            | /usr/bin/php-cgi7 |
+---------------------+-------------------+
Starting PHP-PM with 8 workers, using StreamSelectLoop ...
Application bootstrap failed. Restarting worker #5506 ...
Application bootstrap failed. Restarting worker #5503 ...
Application bootstrap failed. Restarting worker #5502 ...
Application bootstrap failed. Restarting worker #5508 ...
Application bootstrap failed. Restarting worker #5504 ...
Application bootstrap failed. Restarting worker #5501 ...
Application bootstrap failed. Restarting worker #5505 ...
Application bootstrap failed. Restarting worker #5507 ...
Application bootstrap failed. Restarting worker #5506 ...
Application bootstrap failed. Restarting worker #5503 ...
Application bootstrap failed. Restarting worker #5502 ...
Application bootstrap failed. Restarting worker #5508 ...
Application bootstrap failed. Restarting worker #5504 ...
Application bootstrap failed. Restarting worker #5501 ...
Application bootstrap failed. Restarting worker #5505 ...
Application bootstrap failed. Restarting worker #5507 ...
Application bootstrap failed. Restarting worker #5506 ...

Here is my Repo: https://github.com/Sauerbrei/ppm-test

Thank you for your help :)

acasademont commented 3 years ago

If you're using the default kernel location in App\Kernel you should not need to use those env variables, those are only for non-standard Kernel locations/names.

Your repo is fine, very similar to our Symfony 5 project. I believe there must be a problem with the docker image and the folder structure & autoloading...could you try it without docker?

Sauerbrei commented 3 years ago

Hm, this is strange...

cd ppm-test
ppm start
> --- Worker 5505 stderr ---
> PCNTL is not enabled in the PHP installation at /usr/bin/php-cgi7.4. See: http://php.net/manual/en/pcntl.installation.php

$ php -m | grep pcntl
> pcntl
$ php-cgi7.4 -m | grep pcntl
> pcntl

What am I doing wrong?

Sauerbrei commented 3 years ago

Regarding this tutorial https://serverfault.com/questions/158113/installing-pcntl-module-for-php-without-recompiling

my php tells me, PCNTL is already loaded