PHP version change not maintained for CLI?

Zanzo

Verified User
Joined
Jun 16, 2024
Messages
9
I'm in the process of moving from cPanel to DA. I had a question regarding PHP version per domain that I can't find the answer to. Here's how it currently works for me in cPanel and would like to replicate this:

1. Default PHP version on the server is 8.1.
2. Main account domain mysite.com has a docroot of /home/mysite/public_html
3. I set mysite.com to use PHP 7.4 in cPanel
- 1. If I visit a phpinfo file at mysite.com/info.php, I see PHP 7.4
- 2. If I SSH to the server, cd to /home/mysite/public_html, and `php -v`, I see PHP 7.4
4. Create a subdomain new.mysite.com, which has a docroot of /home/mysite/domains/new.mysite.com
5. I set new.mysite.com to use PHP 8.3 in cPanel
- 1. If I visit a phpinfo file at mysite.com/info.php, I see PHP 8.3
- 2. If I SSH to the server, cd to /home/mysite/domains/new.mysite.com, and `php -v`, I see PHP 8.3
6. `php -v` in any other directory displays the server default 8.1

So long story short, setting PHP version in cPanel sets it for both apache and CLI.

I have created a similar setup in DA and set the PHP versions exactly as above. While this works perfectly fine for web requests, I find that no matter what directory I'm in while using CLI, the php version is always the server default 8.1.

Does this sound like I've set this up wrong? Should the above be possible with DA?
 
nope, DA will links ( php ) command to php_version of main domain per account.
 
I must have set something up wrong.
  • Account name is "mysite"
  • Login to DA using "mysite" which only has user view
  • Primary domain is "mysite.com" with PHP 7.1 set as version on /user/domains/domain/mysite.com using PHP Version Selector
  • Subdomain is "new.mysite.com" with PHP 7.2 set as the version on /user/subdomains.
If I ssh to the server, either as the mysite user or root, no matter what directory i am in, `php -v` is PHP 8.2
 
I don't follow what you mean by cronjob. I click the Save button in both cases if that's what you mean.

Screenshot 2024-06-24 at 8.11.23 PM.png

In actual fact, i just found that the subdomain php selection does not work at an apache level. phpinfo() shows PHP 7.1 (the primary domain version). If I change the primary version and refresh the phpinfo() page in the subdomain docroot, the PHP version changes instantly.

So the two issues are:

1. Subdomain PHP version is ignored by webserver
2. Main domain and subdomain PHP is ignored in CLI

Am I missing a cron job somewhere?
 
main domain = default domain of that's user.
Yes. That's exactly what I'm referring to also.

Setting PHP version on subdomains does not work for me.

Setting PHP version for main domain for that user does not work for CLI
 
if still not work, then you need to create support ticket.

"php" cmd should same with php_version of default domain.
 
Thanks for your help. I'll create a ticket and see if we can get to the bottom of it. I must have something set up wrong as it sounds like it should work the way I expect.
 
OK got to the bottom of this.

PHP not changing in subdomain after changing version: My misunderstanding on expecting the change to be instant. It actually does update to the selected version after around a minute. I'm coming from cPanel, which is instant. But I don't need it to be.

PHP version not being that of the account's main domain in CLI: My mistake. I was going to SSH via an elevated server user and doing `sudo -su mysite` to "Login" as that user. This does not have the same affect as logging in as the actual user and I think it just uses the first PHP version that is set up. If I login to SSH as the user direct, `php -v` reports the correct version per the account main domain.

Thanks for all the assistance.
 
correct ways for "su"

Code:
su -l user
this will be using same env of the user.
 
  • Like
Reactions: twv
Back
Top