Solved How to change multiple users php selection? But php1_select= missing so.... how? Bug?

I'm not a scripter, but as far as I can see, this greps php1_select
And the answer why it greps it lies in the 2nd line you've posted :) It adds php1_select there if it is not in the file yet.
 
It adds php1_select there if it is not in the file yet.
The second line says put in a php1_select=2.

Sorry but I still don't understand fully how this catches empty php1 lines as source. Suppose I have it like this in the options.conf

php 1 version = php 7.3
php 2 version = php 8.0
php 3 version = php 7.4

Now I want to put all users which are using php 7.3 (so php 1) to php 7.4, so 3rd choice.
There are several of these domains which do not yet have any php1_select= in their httpd.conf file.

So you say if I would do it with the script and change:
echo php1_select=2 >> $i
to
echo php1_select=3 >> $i
then also the domains which do not have any php1_select= in their httpd.conf will still get the php1_select=3 in their httpd.conf is that correct?

Or am I missing or confusing something?
 
https://docs.directadmin.com/webservices/php/multiple-php.html#swapping-all-users-php-selection guide (which was discussed in the thread) is to "switch all users to the desired version of PHP ", it's a different thing, and I see no problems with that guide. What you're looking for is "how-to switch users using a specific version of PHP to the desired version of PHP".

Regarding your question, if you want to change main version of PHP to 7.4 and you have 7.3 defined as php1, you'd just do:
Code:
/usr/local/directadmin/custombuild/build set php1_release 7.4
/usr/local/directadmin/custombuild/build set php3_release no
/usr/local/directadmin/custombuild/build php

Everyone who ran 7.3 would run 7.4, everyone who ran 7.4 would still run 7.4. Am I missing something here?
 
"switch all users to the desired version of PHP
Ahaaa... oke I understand thats where the misunderstanding is coming from. I thought all users which now have php1_select=1 set. But in fact it only switches all users TO php1_select=1???

Everyone who ran 7.3 would run 7.4, everyone who ran 7.4 would still run 7.4. Am I missing something here?
Yes if you put all users to php1 select, you can't have 7.4 at position 1 and 3 right?
But if I move all users to php1 so to the newly php 7.4, then all php 8 users would also go to php 8 right?

I still find the docs also very confusing as I'm no scripter (most of us aren't). In the example in the docs, are all users swapped to use php1_select=2 or all php1_select=2 users swapped to php1_select=1?

Regarding your question,
That wasn't my question. ;) I know how to switch php versions like that. But I wanted to move the users using it to another selection.
 
But I wanted to move the users using it to another selection.
I'm sorry, but.. it seems I've already explained how to do it. May you explain what exactly do you want to do? If I had something like "I want all users using 2nd version of PHP to start using 3rd version of PHP" it'd be clear :) At this time you've mentioned you want all of your customers using PHP 7.3 to run PHP 7.4 - I have a solution to this in my previous post, didn't it work? Anyway, I understand that your needs might be different, so, just explain what exactly would you like to do and I'll try providing you a solution for it. Thank you.
 
May you explain what exactly do you want to do? If I had something like "I want all users using 2nd version of PHP to start using 3rd version of PHP" it'd be clear :)
Ehmz..... I already did that in my initial post. :)

How do we change this for all default users?
As php1_select=1 is not present for default users in their domain.tld.conf file we can't use any command which says "move everybody who has php_select=1 to php_select=3 (for example).
So I want all users, using 1st version of PHP to start using 3rd version of PHP.

I don't know if the example in the docs, swappes all users using 2nd php version to 1st.
And secondly, not all domains http.conf has a "php1_select=" line in their httpd.conf so it's not just "choose everybody using php1_select=1" because not every domain has even such line in the conf.

I hope it's more clear to you this way?
 
I first want to swap users to the 3rd php option.

After that, I want to change the default php version, but I know how to do this. At least that was my initial question.

However, what you suggest now might be more interesting or easier to for me now, so now you given me some new idea.

At this moment i have it like this in options.conf
php1 = php 7.4
php 2 = php 8.1
php 3 = php 8.0

I want to exchange php 7.4 and php 8.0 but I want all users now using php 7.4 to keep 7.4 So php 1 also needs to be placed to php 3.

So it will look like this:
php 1 = php 8.0
php 2 = php 8.1
php 3 = php 7.4 and everybody which used php1 before) users get here php 3 now.
 
I want to exchange php 7.4 and php 8.0 but I want all users now using php 7.4 to keep 7.4
Heh, I think there is the root cause of the confusion :) So, you don't want to change PHP version for any of the customers. Am I right? You just want to change the system default version to 8.0, and all new users/domains would use it as well. Please confirm, as I don't yet have a clear picture of what would you'd like to achieve :)
 
Am I right? You just want to change the system default version to 8.0, and all new users/domains would use it as well.
Lol yes, that is almost right. :)

I want to change the system default to version 8.0, that is correct. I know how to do that, so that is no problem.
But all users are at this moment using php 7.4 which is the current system default.

I want all new users/domains to use the new 8.0 system default, but all current system default users (php 7.4) to keep using 7.4 which will move to php choice 3.

I'll try again.

Current situation:

php 1 = php 7.4 system default, most users are here now.
php 2 = php 8.1
php 3 = php 8.0 only 3 users using this currently, I can change those manually afterwards.

Newly requested situation, so what I want to achieve:
php 1 = php 8.0 system default, only for new users (and the 3 I will move manually)
php 2 = php 8.1
php 3 = php 7.4 everybody else, so every existing user which had this as system default in the old situation.

Seems to me, to reach this situation, all current php 7.4 users need to have their choice changed to choice 3, correct?

I hope this is more clear? I know it can be a bit of a puzzle sometimes as we are both not native English, but we will get there. :)
 
@Richard G This is exactly the scenario that my php-version-selections was written for. It will update the customer configs so they get the correct PHP version after you rearrange them in options.conf.
 
Yep that is correct Kristian, but I'm also looking to correct the docs (and make more clear how to use) also or integrate your script in there.
 
Current situation:

php 1 = php 7.4 system default, most users are here now.
php 2 = php 8.1
php 3 = php 8.0 only 3 users using this currently, I can change those manually afterwards.

Newly requested situation, so what I want to achieve:
php 1 = php 8.0 system default, only for new users (and the 3 I will move manually)
php 2 = php 8.1
php 3 = php 7.4 everybody else, so every existing user which had this as system default in the old situation.

1. You do:
Code:
cd /usr/local/directadmin/custombuild
./build set php1_release 8.0
./build set php3_release 7.4
./build php

2. Now you want to move all the users who used php1 to use php3, so, you execute this script:
Code:
#!/bin/sh
for i in `ls /usr/local/directadmin/data/users/*/domains/*.conf`; do
{
       if ! grep -q ^php1_select $i; then
               echo php1_select=3 >> $i
               continue
       fi

       perl -pi -e "s/^php1_select=1/php1_select=3/" $i
};
done
exit 0

3. Update config files:
Code:
cd /usr/local/directadmin/custombuild
./build update
./build rewrite_confs

That's it.
 
That's it.
Thank you, So that includes users which don't have any php1_select= lines in their configuration, right?

As for point 2.) do you want me to open a seperate topic for that? Or try to solve it here?
It might disturb good working of the script if a php version is removed and not replaced by another one. Then they have old lines which point to nothing.
 
I'm not sure what's left there to solve?
Well the thing I pointed it out as 2.) in post #16 and you reply'd in post #18 that was a different issue and first solve the first one (which is now solved).

So whats left to solve, but has sideways to do with this. So that's why I asked if I should open a different thread for that issue?
 
It would be convenient if it was User interface in DirectAdmin to select multiple users and set new default php
 
2.) Odd things can happen if you remove a php version and add one later. See my link to the other post. If you have for example 3 php versions and you remove 3. Then all users with choice 3 will automatically be using in fact choice 1 (the default) but in the config still choice 3 is present.
If you add later on another php version on 3 (for example very new or for testing) then these users will suddenly have a totally different PHP version active, while choice 3 is still active in their config.

You can just do the following after the change:
Code:
perl -pi -e "s/^php1_select=3/php1_select=1/" /usr/local/directadmin/data/users/*/domains/*.conf

Then execute:
Code:
/usr/local/directadmin/custombuild/build rewrite_confs
 
Back
Top