Kinsta PHP Management


Coming from WP Engine, Kinsta PHP options are amazing. Each site with Kinsta can run a wide range of PHP versions from 5.6 to 7.3 beta. That said, with greater control comes additional responsibility. Here are some tips for keeping PHP up to date while managing over 250 sites on Kinsta. 

Gathering current PHP versions over SSH

Within my toolkit, CaptainCore, there are 2 commands, captaincore site list and captaincore ssh, which makes this really simple to script. That said, you could implement the same approach with some additional bash scripting. To begin create a file named php_version.sh with the following content. This will use a fancy regex to output only the numbers for PHP as shown here.

wp eval 'echo phpversion();' --skip-wordpress | perl -n -e '/(\b\d+.\d+.\d+(-)?(\d+)?\b)/&& print $1'

Next create a file named gather_kinsta_php_versions.sh with the following.

# Loops through all Kinsta sites and outputs CSV containing sites and PHP versions
for site in $( captaincore site list --provider=kinsta ); do
  printf "${site},"; 
  captaincore ssh $site --script=php_version.sh; echo ""; 
done > kinsta_php_versions.csv

# Pretty prints the CSV sorted by PHP version number
cat kinsta_php_versions.csv | sort -k2 -t',' -n | column -t -s,

Running gather_kinsta_php_versions.sh will loop through each site and generate a csv file kinsta_php_versions.csv. At this point taking the CSV into something like Google Sheets is good way to sort and track PHP upgrades. The script also will output a sorted pretty version for quick review.

site123         5.6.36-1
site532         5.6.38-3
site657         7.0.30-1
site650         7.0.31-1
site405         7.1.19-1
site256         7.2.7-1
site250         7.2.11-3

Kinsta doesn’t support bulk PHP upgrades however PHP upgrades do stack.

Some things in the Kinsta portal are blocking. For example if you clear the cache you can’t also apply a Let’s Encrypt SSL until it finishes clearing the cache. Applying PHP upgrades stack and are not blocked. That means you can update as many sites concurrently as fast as you click through the Kinsta portal. From my experience updating 6 sites per minute is doable. So within an hour a batch of 250 sites could be rolled out to the latest and greatest version of PHP.