nginx / unit

NGINX Unit - universal web app server - a lightweight and versatile open source server that simplifies the application stack by natively executing application code across eight different programming language runtimes.
https://unit.nginx.org
Apache License 2.0
5.4k stars 328 forks source link

How to use and assign applications to different PHP versions ? #46

Closed centminmod closed 7 years ago

centminmod commented 7 years ago

If I am understanding Nginx Unit's feature set, one is to be able to use different PHP versions for different applications ? From http://unit.nginx.org/docs-configuration.html#php-application I am not seeing any option to tie a PHP application to a specific PHP version ?

If I have multiple PHP versions installed 5.6.31, 7.0.23, 7.1.9 via conifguring PHP http://unit.nginx.org/docs-installation.html#source-code, how does an PHP application know which PHP version to use ? How is it associated ?

Right now if I configure for PHP 5.6.31, 7.0.23 and 7.1.9, which version gets used by default for a Unit created PHP application type = php ?

thanks

VBart commented 7 years ago

You can specify version in application type field like "type": "php 5", or "type": "php 7", or "type": "php 7.0". Unit tries to match version against existing modules. If several versions match (e.g. 7.0.23 and 7.1.9 both match php 7), then the newest version will be used.

The same rule works if no version specified: the newest version against all existing modules is used.

centminmod commented 7 years ago

sweet.. so

thanks @VBart

VBart commented 7 years ago

Not really. Module name doesn't matter at all. Unit gets the versions from PHP library. So, in your case they will be 5.6.31 and 7.1.9.

If you have only one PHP 7 version and it is 7.1.9, then php 7, php 7.1, and php 7.1.9 will work for you.

VBart commented 7 years ago

Module names can be anything, any random string. These names only used to name build targets and module files.

When Unit starts, it forks special "discovery" process. This process scans modules directory and loads each module one by one. It collects information about existing modules and their versions. Then it sends this information to the main process and exits.

Currently, the discovery process runs only once at start. Thus, in order to add new module to Unit, you have to reload it. In future, the modules directory will be monitored and all changes in the list of available modules will be discovered in realtime without reloads.

centminmod commented 7 years ago

Thanks @VBart for the info. Do you see any future development to allow picking up and differentiating different PHP versions ? 7.0.23, 7.1.9, 7.2.0 etc. Maybe inspecting the built php module's X-Powered-By header ?

with --lib-path=/usr/local/lib set

strings /usr/local/lib/libphp5.so  | awk -F ": PHP/" '/X-Powered-By/ {print $2}'
5.6.31
VBart commented 7 years ago

Not sure, that I understand what do you mean. Unit already is able to differentiate them. If you have built several versions, you can load the exact version that you need.

Could you elaborate?

centminmod commented 7 years ago

sorry misread your comment at https://github.com/nginx/unit/issues/46#issuecomment-331673543 so i can use type = php 7.1.9 or php 7.0.23 or php 7.2.0 to match the 3

VBart commented 7 years ago

Sure. It's just up to you how precise do you like to specify version number.

VBart commented 7 years ago

For example, if you have two 7.0.x versions: 7.0.2 and 7.0.23, and you want for your application to use 7.0.2, then you should set "type": "php 7.0.2".

centminmod commented 7 years ago

ok got it so only version number is needed and not php prefix or works with php prefix too "type": "7.0.2" or "type": "php 7.0.2" would both work ?

VBart commented 7 years ago

Sorry, "type": "7.0.2" was a mistake (must be "type": "php 7.0.2"). The php prefix in type field is needed. There can be several other languages at the same time.

In general, you can specify the exact version number, like "type": "php 7.0.13", or "type": "php 7.0" for the newest PHP 7.0.z, or "type": "php 7" for the newest PHP 7.y.z, or just "type": "php" for the newest PHP among all versions.

In fact, Unit doesn't care how many dots particular interpreter uses, it just does smart version matching and tires to find the best match.

The same is true for Python.

centminmod commented 7 years ago

Cheers thanks for the clarification :)

centminmod commented 7 years ago

oh one more related question is, is there a API command to be able to list all the php types registered/configured with Nginx Unit ?

VBart commented 7 years ago

Not yet, but it's planned. Currently only the configuration API is implemented. A few beta versions later, all configuration will be moved to the /configuration/ prefix and more APIs will be added. You will be able to get various status, versions information, reload particular application, and more.

centminmod commented 7 years ago

Sounds good.. looking forward to testing :)