deployer-extended-database
deployer-extended-database copied to clipboard
Missmatch with 'local/bin/php' on remote & local
I currently try to run vendor/bin/dep db:pull prod and have issues with php versions / discover
Case 1
This case fails, with task db:export:
[prod] [prod] run cd /home/typo3cms/app/current && /home/typo3cms/bin/php /home/typo3cms/app/current/vendor/bin/dep db:export prod --options=tags:pull,dumpcode:3d38c6633b2c0c4295d0f269587bf410
[prod] [prod] task db:export
[prod] [prod] [prod] Deployer\Exception\ConfigurationException in Typo3CmsDriver.php on line 23:
[prod] [prod] [prod]
[prod] [prod] [prod] Command: "/opt/homebrew/Cellar/[email protected]/8.2.28_1/bin/php vendor/bin/typo3 configuration:showactive DB --json" returned error code: "127"
[prod] [prod] [prod]
deploy.phpon local & remote:
host('prod')
->set('deploy_path', '/home/typo3cms/app')
->set('php_version', '8.2')
->set('local/bin/php', '/opt/homebrew/Cellar/[email protected]/8.2.28_1/bin/php')
->set('bin/php', '/home/typo3cms/bin/php')
;
host('local')
->set('deploy_path', getcwd())
->set('php_version', '8.2')
->set('local/bin/php', '/opt/homebrew/Cellar/[email protected]/8.2.28_1/bin/php')
->set('bin/php', 'php')
;
Case 2
This case works, but only when on local and remote are different deploy.php
deploy.phpon local:
host('prod')
->set('deploy_path', '/home/typo3cms/app')
->set('php_version', '8.2')
->set('local/bin/php', '/opt/homebrew/Cellar/[email protected]/8.2.28_1/bin/php')
->set('bin/php', '/home/typo3cms/bin/php')
;
host('local')
->set('deploy_path', getcwd())
->set('php_version', '8.2')
->set('local/bin/php', '/opt/homebrew/Cellar/[email protected]/8.2.28_1/bin/php')
->set('bin/php', 'php')
;
deploy.phpon remote:
host('prod')
->set('deploy_path', '/home/typo3cms/app')
->set('php_version', '8.2')
->set('local/bin/php', '/home/typo3cms/bin/php')
->set('bin/php', '/home/typo3cms/bin/php')
;
host('local')
->set('deploy_path', getcwd())
->set('php_version', '8.2')
->set('local/bin/php', '/opt/homebrew/Cellar/[email protected]/8.2.28_1/bin/php')
->set('bin/php', 'php')
;
Case 3
This case fails, with task db:pull:
[prod] error in db_pull.php on line 80:
[prod] run /home/typo3cms/bin/php ./vendor/bin/dep db:export prod --options=tags:pull,dumpcode:e21f0697b0adb8b8320f1045a2d54636
[prod] err bash: line 1: /home/typo3cms/bin/php: No such file or directory
[prod] exit code 127 (Command not found)
ERROR: Task db:pull failed!
deploy.phpon local & remote with each host setting:
host('prod')
->set('deploy_path', '/home/typo3cms/app')
->set('php_version', '8.2')
->set('local/bin/php', '/home/typo3cms/bin/php')
->set('bin/php', '/home/typo3cms/bin/php')
;
host('local')
->set('deploy_path', getcwd())
->set('php_version', '8.2')
->set('local/bin/php', '/opt/homebrew/Cellar/[email protected]/8.2.28_1/bin/php')
->set('bin/php', 'php')
;
Seems like there is a wrong 'local/bin/php' resolve during pull? Or do i misunderstand something?
Updated with case 3
@develth
Tnx for testing and sry for this bug.
I overlooked this because I was testing only the "php auto detection form composer.json" mode.
All my configs of hosts have neither bin/php or local/bin/php set and it was working good for dozens of different projects I used for testing.
Now I also tested the plain path to php bin/php or local/bin/php and indeed there is an issue.
I also tested the mode with only php_version set (this one to work needs that phpXY or phpX.Y is set in PATH).
Please check the branch local_php_issue which should fix the issue.
[...] sry for this bug.
Nothing to worry about!
Please check the branch local_php_issue which should fix the issue.
For this i need to require this package separatly, or?
@develth
You can try:
composer req "sourcebroker/deployer-extended-database":"dev-local_php_fix as 20.0.0"
Thanks. For clearification:
Is local/bin/php the php path for the local instance, or the one on the current host definition?
@develth
It is the one from current host definition.
So it will be the same for bin/php and local/bin/php.
Unfortunately it must be like that - reason below.
We can not use bin/php because when you do not overwrite it at host level with a string then this is a function which calls Deployer\which() and this Deployer\which() is calling inside a run() which is trying to connect to ssh to get the php path.
But we call it on remote server so it try to connect to itself! Crap.
Therefore we have separate local/bin/php which does not use run().
https://github.com/deployphp/deployer/blob/master/recipe/common.php#L110
BTW:
Consider using the php path autodetection.
This is enough that the PHP you want to use is in PATH and can be found like which php82. If yes then you do not need to define local/bin/php and also bin/php if you use https://github.com/sourcebroker/deployer-extended/blob/master/includes/settings/bin_php.php
My host definitions looks like below.
Mind that I do not even declare localhost because it it declared already in deployer-extended-database and use php autodetection.
host('production')
->setHostname('vm-dev.example.com')
->setRemoteUser('deploy')
->set('branch', 'main')
->set('public_urls', ['https://t3base13.example.com'])
->set('deploy_path', '~/t3base13/production');
host('staging')
->setHostname('vm-dev.example.com')
->setRemoteUser('deploy')
->set('branch', 'develop')
->set('public_urls', ['https://staging-t3base13.example.com'])
->set('deploy_path', '~/t3base13/staging');
@develth
I pushed the tag 20.0.1 with this fix.
Now i get [localhost] run command -v 'php8.3' || which 'php8.3' || type -p 'php8.3' [localhost] run command -v 'php83' || which 'php83' || type -p 'php83' [prod] error in db_pull.php on line 44: [prod] exit code 1 (General error) done db:pull 137ms ERROR: Task db:pull failed!
Edit:
I fixed it by setting
host('local') ->set('deploy_path', getcwd()) ->set('local/bin/php', 'php')
The documentation is wrong here, it states
->set('bin/php', 'php')
@webspin
Documentation is ok.
Those misunderstandings are because the way deployer-extended-database works.
It runs part of the commands form local level, I'd say the standard way.
But part of commands are remote calls of deployer at server level - this is something which makes the problems.
It looks like: run('dep db:import ....');.
So this is like you would run deployer (at remote) being already inside deployer (locally).
When you run deployer at the remote host, as above example, then if this command needs to connect to ssh to work (a regular run() calls) then there is internal ssh connection. A bin/php from deployer is example of such setting that internally do run( "which php"); command (from your example). So if I would like to use bin/php while I am already at server then there would be internal ssh connection! For that reason the local/bin/php has been introduced that do runLocally for which command.
I see however one improvement we can do here.
For now there are searches being done for PHP declared in composer.json. This is why you have:
[localhost] run command -v 'php8.3' || which 'php8.3' || type -p 'php8.3'
[localhost] run command -v 'php83' || which 'php83' || type -p 'php83'
I probably will not throw an error when those phpX.Y from composer.json can not be found and will fallback to just "php".
This actually was the way it was working in previous versions of deployer-extended-database. It was using just "php".
So could be even that this will be a bugfix for previous behaviour.
The documentation repeatedly states that for a local environment, you should configure:
localhost('local')
->set('deploy_path', getcwd())
->set('bin/php', 'php')
However, in db_pull.php, the code references:
$dl = host($local)->get('local/bin/php') . ' ' . get('local/bin/deployer');
This suggests a discrepancy, as there's no mention of 'local/bin/php' path anywhere in the documentation, only 'bin/php'. The documentation should be updated to resolve this inconsistency, I think.
Yes. You right.
Setting ('local/bin/php') should be also mentioned.
@webspin
If you install 20.1.0 then probably you can remove local/bin/php. Now if PHP from composer.json is not found then it will search for php binary and if not found it will just use plain php.
The docs are also updated! :)