I've been using this script as part of a server migration solution that I've built, but if you're using PHP-FPM I don't recommend it.
If there exists a single PHP process with that user when the script runs, it will fail:
usermod: user example is currently used by process 29258
groupmod: group 'example' does not exist
At the point it fails, it's already deleted the group of the same name, so you'll need to re-create the group or PHP will fail to start.
My theory is that it may work if you stop PHP first, run the script and then start PHP again:
/bin/systemctl stop php-fpm74.service
/usr/local/directadmin/scripts/change_username.sh user_old user_new ; /usr/local/directadmin/dataskq
/bin/systemctl start php-fpm74.service
If there exists a single PHP process with that user when the script runs, it will fail:
usermod: user example is currently used by process 29258
groupmod: group 'example' does not exist
At the point it fails, it's already deleted the group of the same name, so you'll need to re-create the group or PHP will fail to start.
My theory is that it may work if you stop PHP first, run the script and then start PHP again:
/bin/systemctl stop php-fpm74.service
/usr/local/directadmin/scripts/change_username.sh user_old user_new ; /usr/local/directadmin/dataskq
/bin/systemctl start php-fpm74.service