Skip to content

Missmatch with 'local/bin/php' on remote & local #37

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

Open
develth opened this issue Apr 8, 2025 · 13 comments
Open

Missmatch with 'local/bin/php' on remote & local #37

develth opened this issue Apr 8, 2025 · 13 comments

Comments

@develth
Copy link

develth commented Apr 8, 2025

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?

@develth
Copy link
Author

develth commented Apr 8, 2025

Updated with case 3

@kszymukowicz
Copy link
Contributor

@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.

@develth
Copy link
Author

develth commented Apr 9, 2025

[...] 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?

@kszymukowicz
Copy link
Contributor

kszymukowicz commented Apr 9, 2025

@develth
You can try:
composer req "sourcebroker/deployer-extended-database":"dev-local_php_fix as 20.0.0"

@develth
Copy link
Author

develth commented Apr 10, 2025

Thanks. For clearification:
Is local/bin/php the php path for the local instance, or the one on the current host definition?

@kszymukowicz
Copy link
Contributor

kszymukowicz commented Apr 10, 2025

@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

@kszymukowicz
Copy link
Contributor

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');

@kszymukowicz
Copy link
Contributor

@develth

I pushed the tag 20.0.1 with this fix.

@webspin
Copy link

webspin commented May 6, 2025

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')

@kszymukowicz
Copy link
Contributor

@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.

@webspin
Copy link

webspin commented May 7, 2025

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.

@kszymukowicz
Copy link
Contributor

Yes. You right.
Setting ('local/bin/php') should be also mentioned.

@kszymukowicz
Copy link
Contributor

@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! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants