Php-updater - a script to upgrade php in a safe way

php-updater is a script to upgrade (migrate php from one version to an other) on → debian based distributions ←

my motivations

I’ve been on this forum for quite some time now and have seen countless times how administrators get into trouble every time the php version needs to be changed.

Because a PHP version does not - as is common with many other packages - exclude other versions and several versions can easily be operated side by side - there are also several APIs that are used to communicate with PHP, each of which has its own configuration files one can easily imagine that switching from one version to an other using the usual means such as apt, apt-get, apt-fast, aptitude or even synaptic alone is not always successful.

Some admins have painstakingly optimized their php-fpm and, for example, adjusted the directories in which the log files should be written. For this alone, at least two, but usually three or more files have to be edited: /etc/php/<version>/fpm/php.ini, /etc/php/<version>/fpm/php-fpm.conf and /etc/logrotate.d/php<version>-fpm
Then some admins also made changes to the module’s own ini files under /etc/php/<version>/mods-available/*.ini
It’s all too understandable when one or two adjustments are forgotten and then, after an update, the server suddenly becomes just as slow and unwieldy as it was before the last optimization or even no longer works at all.
So a long time ago I scripted the entire procedure and used it to carry out my up- and downgrades. Then I started making the script publicly available so that others can also benefit from it.

It is now the most downloaded script from my library. That motivated me to continue to expand and perfect it. To set it up for all eventualities that I don’t need for my own use because I always work according to the same scheme, but of course I can’t expect that if the script is used in other environments where I’m not an admin.

It now comes with the information of all php.ini directives for as long as they can be looked up from the php.net website. An integrated awk driven function guarantees that this information is always up to date.

There are still features I want to add, such as a first installation, integrated tips for the best switches for a nextcloud system and the handling of the alternatives mechanism.

→ this Mindmap chart ← gives deeper insights, about what php-updater does.

Installation of the script:

sudo wget -qO /usr/local/bin/php-updater https://global-social.net/script/php-updater
sudo chmod +x /usr/local/bin/php-updater
Explanation:
  • the first line downloads the script into the directory /usr/local/bin
  • the second line makes it executable

You only need to install it once.
As all of my scripts, it comes signed and does an integrity check on the first run and checks for updates on every startup.

Simply run it:

php-updater

meanwhile it is self explanatory and a source of good information about the complete php realm on your server.


Restriction:

This script is intended for use on conventional “barremetal” linux server installations or dedicated virtual machines running debian based Linux. It does not work on the Virtual Machines from HanssonIT and in containerized appliances like snap, lxc, docker, aio etc.


If you have any difficulty with this script, don’t hesitate to ask me for help.


Much and good luck

ernolf

4 Likes

When I ran php-upgrader,I got some error message,why? What can I do?

root@nextcloud /var/www# php-updater 
.. loading modules - integrity
     First run, checking integrity:
     ===========================================================================
gpg:                using RSA key xxxxxxxxxxxx
     ---------------------------------------------------------------------------
     - Integrity check failed. The script may have been modified or tampered with!
     ---------------------------------------------------------------------------
     You should run:
     sudo wget -O /usr/local/bin/php-updater https://global-social.net/apps/raw/s/php-updater
     to fix this.
     ===========================================================================
exiting…

I executed

sudo wget -O /usr/local/bin/php-updater https://global-social.net/apps/raw/s/php-updater

again and the result was still the same

Could you provide some more specs of your system please?
It looks like you have a problem with sed

What says

sed --version

ernolf

root@nextcloud ~# sed --version
sed (GNU sed) 4.7
Packaged by Debian
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later https://gnu.org/licenses/gpl.html.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

OK. Even though that version is a museum, it should work.

How about:

… ?
And …
is any mandatory access control system like SELinux or AppArmor activated on your system?


ernolf