php upgrade - is there a better way to do?

Hi there

At the moment I'm doing php upgrade by collecting information about existing php packages then deleting them and installing newer versions. Is there a better way to do that ?

A small script that I'm using so far:
Bash:
#!/bin/sh

cfg_ver_cur="php81"
cfg_ver_new="php82"

cfg_log="php-upgrade-script-$( date "+%Y-%m-%d-%H-%M-%S" ).log"


# Get current package list
#pkg_php_start=$( pkg query -e '%n ~php*' '%o' )

# List packages depending on current php port
pkg_php_start=$( pkg query '%ro' "$cfg_ver_cur" | sort )


# generate package names for new version
todo="Replace: $cfg_ver_cur ====> $cfg_ver_new"
todelete="$cfg_ver_cur"
toinstall="$cfg_ver_new"


for p in $pkg_php_start; do

  # check if pacage has php name and version it it
  echo "$p" | grep -qE "$cfg_ver_cur"
  has=$?

  if [ "$has" -eq 0 ]; then
    # substitute pkg name for phpxx included
    newname=$( echo $p | sed "s/$cfg_ver_cur/$cfg_ver_new/g" )
  else
    # add flavor for those who doesn't
    newname="$p@$cfg_ver_new"
  fi

  # Build lists
  todo="$( printf "%s\n%s" "$todo" "Replace: $p ----> $newname" )"
  todelete="$todelete $p"
  toinstall="$toinstall $newname"

done

# log
echo
echo "Logs will be save into: $cfg_log"
echo
echo "$todo" > $cfg_log

# Make sure it is clear what we actually doing
echo "========================================"
echo "$todo"
echo

echo "========================================"
echo "$todelete"
echo

echo "========================================"
echo "$toinstall"
echo

echo "========================================"
echo
echo -n "Please review content and confirm lists above is correct [N/y]: "
read yn
[ "$yn" != 'y' -a "$yn" != 'Y' ] && exit 0

pkg delete $todelete && pkg install $toinstall
 
Not that I know of.

Sometimes newer versions of PHP will pull extensions into the core (and vice versa) so there’s always a bit of manual oversight required.

Watch out for mod_php if you use it (make sure any patterns include it).
 
I compile my own PHP from source as I can run several versions of PHP on same server due to some web apps being dependent on older version.
 
Back
Top