Skip to content
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

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

Closed
centminmod opened this issue Sep 23, 2017 · 15 comments
Closed

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

centminmod opened this issue Sep 23, 2017 · 15 comments

Comments

@centminmod
Copy link

centminmod commented Sep 23, 2017

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
Copy link
Contributor

VBart commented Sep 23, 2017

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
Copy link
Author

sweet.. so

  • if i configured PHP 5.6.31 with --module=php5631 I would just specify "type:" "php5631"
  • if i configured PHP 7.1.9 with --module=php719 I would just specify "type:" "php719"

thanks @VBart

@VBart
Copy link
Contributor

VBart commented Sep 23, 2017

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
Copy link
Contributor

VBart commented Sep 23, 2017

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
Copy link
Author

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
Copy link
Contributor

VBart commented Sep 23, 2017

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
Copy link
Author

sorry misread your comment at #46 (comment) so i can use type = php 7.1.9 or php 7.0.23 or php 7.2.0 to match the 3

@VBart
Copy link
Contributor

VBart commented Sep 23, 2017

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

@VBart
Copy link
Contributor

VBart commented Sep 23, 2017

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
Copy link
Author

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
Copy link
Contributor

VBart commented Sep 23, 2017

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
Copy link
Author

Cheers thanks for the clarification :)

@centminmod
Copy link
Author

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
Copy link
Contributor

VBart commented Sep 23, 2017

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
Copy link
Author

Sounds good.. looking forward to testing :)

josephapg referenced this issue in josephapg/unit-docs Jun 26, 2018
References:
1. https://mailman.nginx.org/pipermail/unit/2018-June/000055.html
2. https://www.nginx.com/blog/nginx-unit-1-2-release-available-now/

Additionally, this commit adds an explanation about the ability to define
a specific version of the language interpreter that will be used
to run the application
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants