Hi,
I encountered this same problem (again), and made a solution for this.
My settings were like this:
Code:
php1_release=7.2
php2_release=7.3
php3_release=7.4
Desired state was:
- Swap php1 and php3, so that php7.4 becomes the default
- Don't mass-update sites currently running 7.2 (version 1) to php 7.4 (version 3)
I made a simple bash script to update users' config, to swap it's php version selector. If you run this,
and modify the options.conf values, effectively the users' php version stays the same, but the php1_release (and therefore the default) will change.
An example will make this more clear I think:
Code:
# swap versions in users' config (custom script, see below)
./da_php_swap_version.sh 1 3
# Update DA options and rebuild php
cd /usr/local/directadmin/custombuild/
./build set php1_release 7.4
./build set php3_release 7.2
./build php n
# probably not necessary
./build rewrite_confs
The used script has the following content:
Bash:
#!/bin/bash
# Swap version index numbers in config. This might be helpful when changing the
# order of your php-fpm index numbers in the DirectAdmin configuration.
# In case version "1" has been requested, change configs with no version
# set, as "1" is the default.
set -euo pipefail
# helper functions
die() { echo "$*" >&2; exit 1;}
warn() { echo "$*" >&2; }
usage="Usage: $0 <version 1-4> <version 1-4>"
[ `id -nu` != "root" ] && die "Please execute as root"
[ "$#" -ne 2 ] && die $usage
! [[ "$1" =~ ^[1-4]$ ]] && die $usage
! [[ "$2" =~ ^[1-4]$ ]] && die $usage
version_swap1=$1
version_swap2=$2
swap_version() {
local conf=$1
local version_current
[ -f "$conf" ] || die "File does not exist: $conf"
# Get current version if set in config
set +e
version_current=$(grep -soP "php1_select=\K[0-9]" $conf)
set -e
[ $? -eq 2 ] && die "grep encountered a fatal error"
if [ -z $version_current ]; then
# current version not found in config. assume "1"
version_current=1
fi
# Is this the version we're looking for?
if [ $version_current -eq $version_swap1 ]; then
# replace or add line
sed -i '/^php1_select=/{h;s/=.*/='$version_swap2'/};${x;/^$/{s//php1_select='$version_swap2'/;H};x}' "$conf"
echo "$conf: changed"
elif [ $version_current -eq $version_swap2 ]; then
# replace or add line
sed -i '/^php1_select=/{h;s/=.*/='$version_swap1'/};${x;/^$/{s//php1_select='$version_swap1'/;H};x}' "$conf"
echo "$conf: changed"
fi
}
for f in /usr/local/directadmin/data/users/*/domains/*.conf; do
swap_version $f
done
echo "To update the running configuration, please run: /usr/local/directadmin/custombuild/build rewrite_confs"
Not needed for this, but if you would like to update users with a certain php version to a different version (replace version X with Y), you can use this script:
Bash:
#!/bin/bash
# Search for specific version (1-4) and replace with specified version. If
# replacement of version "1" has been requested, change configs with no version
# set, as "1" is the default.
set -euo pipefail
# helper functions
die() { echo "$*" >&2; exit 1;}
warn() { echo "$*" >&2; }
# Default values
confused=false
version_search=0
version_replace=0
[ `id -nu` != "root" ] && die "Please execute as root"
while getopts s:r:v c; do
case "$c" in
s) version_search="$OPTARG";;
r) version_replace="$OPTARG";;
*) confused=true;;
esac
done
shift `expr $OPTIND - 1`
$confused || [ "$version_search" -eq 0 -o "$version_replace" -eq 0 ] && die "Usage: -s <version to search for> -r <version to replace with>"
! [[ "$version_search" =~ ^[1-4]$ ]] && die "Search version should be between 1-4"
! [[ "$version_replace" =~ ^[1-4]$ ]] && die "Replacement version should be between 1-4"
replace_version() {
local conf=$1
local version_current
[ -f "$conf" ] || die "File does not exist: $conf"
# Get current version if set in config
set +e
version_current=$(grep -soP "php1_select=\K[0-9]" $conf)
set -e
[ $? -eq 2 ] && die "grep encountered a fatal error"
if [ -z $version_current ]; then
# current version not found in config. assume "1"
#echo "$conf has no version set, assume 1"
version_current=1
fi
# Is this the version we're looking for?
if [ $version_current -eq $version_search ]; then
# replace or add line
sed -i '/^php1_select=/{h;s/=.*/='$version_replace'/};${x;/^$/{s//php1_select='$version_replace'/;H};x}' "$conf"
echo "$conf: changed"
fi
}
for f in /usr/local/directadmin/data/users/*/domains/*.conf; do
replace_version $f
done
echo "To update the running configuration, please run: /usr/local/directadmin/custombuild/build rewrite_confs"