As I have spent the last few posts explaining, I recently undertook the task of upgrading my home servers, and it quickly became a very painful process. One of the main purposes of my server is to host my own Nextcloud instance, which my wife and I use as a means to avoid Google. Everything you normally would use Google to do on your cell phone, we do through our Nextcloud. Calendar sync, photo backup, contact sync, document sharing and backup, document editing from your phone or online, maps, phone tracking, etc., if you do it with Google, you can probably do it with Nextcloud.

As I mentioned before, through a grievous oversight on my part, our Nextcloud instance had fallen behind by not one, not two, but five versions! I kept logging into the server, to which it would check for updates on the admin panel, and said that it was up to date, leaving me to believe we were on the current version, for YEARS. Finally I realized that there were newer versions and that the admin panel wasn’t telling me the whole story.

Anyways, we were on Nextcloud version 25, and in the last post I mentioned how I just copied it all over from the old server, which was running Ubuntu 20 and PHP 7.4 to this new server, running Ubuntu 24 and PHP 8.3. Well, after I enabled the website, it wouldn’t work. Oh, the apache2 server served up the site, but it just gave me error and wouldn’t continue to load. Turns out that Nextcloud 25 doesn’t support PHP 8.3. Actually, it only supported PHP 7.4!

I monkeyed with this for quite some time. I found what I needed to do was update Nextcloud from the command line, but I couldn’t because it would only work with PHP 7.4. Further complicating matters, you have to update Nextcloud one version at a time, so to get to the latest, NC 30 at the time of this post, I needed to update 25 to 26 to 27 to 28 to 29 to 30. And to make matters even worse, PHP 7.4 only works with 25. Then you need PHP 8.0 for 26 to 27, after which you can switch to PHP 8.2 to carry you through 28, 29 and 30. Yes, this was painful!

I almost gave up and started over, just wanting to move the pictures and backed up stuff manually. But I didn’t.

Fortunately, you can download and install other versions of PHP with Ondrej’s[1] ppa for Ubuntu:

$ sudo add-apt-repository ppa:ondrej/php 

Once that was installed and you run apt update and apt upgrade, you can start the process. So, I had to install every PHP7.4 package, and PHP8.0 package, and PHP8.2 package. You probably don’t need every PHP package of each version, but if you don’t and run into an issue, you have to go install yet another thing. Actually, even these lists exclude a few of the packages, because some are in conflict with each other. It will look like this example of 8.0 taken from my history list, but I did this for all three, 7.4, 8.0, and 8.2:

745  sudo apt purge libapache2-mod-php8.0 libphp8.0-embed php8.0 php8.0-amqp php8.0-apcu php8.0-ast php8.0-bcmath php8.0-bz2 php8.0-cgi php8.0-cli php8.0-common php8.0-curl php8.0-dba php8.0-dev php8.0-dio php8.0-ds php8.0-enchant php8.0-excimer php8.0-fpm php8.0-gd php8.0-gearman php8.0-gmp php8.0-gnupg php8.0-grpc php8.0-http php8.0-igbinary php8.0-imagick php8.0-imap php8.0-inotify php8.0-interbase php8.0-intl php8.0-ldap php8.0-libvirt-php php8.0-lz4 php8.0-mailparse php8.0-maxminddb php8.0-mbstring php8.0-mcrypt php8.0-memcache php8.0-memcached php8.0-mongodb php8.0-msgpack php8.0-mysql php8.0-oauth php8.0-odbc php8.0-opcache php8.0-pcov php8.0-pgsql php8.0-phpdbg php8.0-pinba php8.0-protobuf php8.0-ps php8.0-pspell php8.0-psr php8.0-raphf php8.0-rdkafka php8.0-readline php8.0-redis php8.0-rrd php8.0-smbclient php8.0-snmp php8.0-soap php8.0-solr php8.0-sqlite3 php8.0-ssh2 php8.0-stomp php8.0-swoole php8.0-sybase php8.0-tideways php8.0-tidy php8.0-uopz php8.0-uploadprogress php8.0-uuid php8.0-vips php8.0-xdebug php8.0-xhprof php8.0-xml php8.0-xmlrpc php8.0-xsl php8.0-yaml php8.0-zip php8.0-zmq php8.0-zstd

After this I had to set my default PHP to be 7.4, like so:

$ sudo update-alternatives --config php

Then, I had to move my nextcloud folder from /var/www/nextcloud to /var/www/nextcloud25. I then downloaded Nextcloud 26, unzipped it and move that folder to /var/www/nextcloud, and copied my configuration file from nextcloud25 to the new nextcloud folder. Of course, you then have to chown everything to www-data:www-data, and then you can enter the command line in the new nextcloud folder and run the nextcloud upgrade command.

$ sudo -u www-data php occ upgrade

This would upgrade my next cloud from version 25 to 26. Then I would set my alternatives again to be the newer PHP 8.0, and move the now current nextcloud folder from /var/www/nextcloud to /var/www/nextcloud26, download the new Nextcloud 27 zip, unzip it, and move it to /var/www/nextcloud. After I copied the config file from the nextcloud26, I could change directory to the /var/www/nextcloud folder and run the upgrade command again.

Once I was on Nextcloud 27, I had to update the alternatives for PHP again to now be PHP8.2, and I could repeat the process for Nextcloud 28, 29, and 30. Needless to say, after about an hour of doing this, I finally got to Nextcloud 30! Here is an excerpt for the commands starting at Nextcloud 27, just so you can get the idea. Oh, and I forgot, I had to run commands like maintenance repair and updating missing idices all along the way.

  662  sudo mv ./nextcloud ./nextcloud27
  663  sudo cp /home/alaskalinuxuser/Downloads/nextcloud-28.0.10.tar.bz2 ./
  664  sudo tar -xvf ./nextcloud-28.0.10.tar.bz2 
  665  cd nextcloud
  666  ls
  667  sudo cp ../nextcloud27/config/config.php ./config/config.php
  668  sudo -u www-data php occ upgrade
  669  cd ..
  670  history |grep chown
  671  sudo chown -R www-data:www-data ./nextcloud
  672  cd nextcloud
  673  sudo -u www-data php occ upgrade
  674  cd ..
  675  sudo systemctl start apache2
  676  cd nextcloud
  677  history |grep occ
  678  sudo -u www-data php occ db:add-missing-indices
  679  exit
  680  sudo ls
  681  ls
  682  cd /var/www/nextcloud
  683  sudo -u www-data php occ maintenance:repair --include-expensive
  684  cd /var2/www/
  685  ls
  686  nano /etc/php/8.2/apache2/php.ini 
  687  sudo nano /etc/php/8.2/apache2/php.ini 
  688  sudo systemctl stop apache2
  689  ls
  690  sudo mv nextcloud ./nextcloud28
  691  sudo cp /home/alaskalinuxuser/Downloads/nextcloud-29.0.7.tar.bz2 ./
  692  sudo tar -xvf ./nextcloud-29.0.7.tar.bz2 
  693  sudo cp ./nextcloud28/config/config.php ./nextcloud/config/config.php
  694  sudo chown -R www-data:www-data ./nextcloud
  695  cd nextcloud
  696  history |grep upgrade
  697  sudo -u www-data php occ upgrade
  698  sudo systemctl start apache2
  699  sudo -u www-data php occ db:add-missing-indices
  700  cd ..
  701  ls
  702  sudo rm *.bz2
  703  ls
  704  cd nextcloud
  705  history |grep occ
  706  sudo -u www-data php occ maintenance:repair --include-expensive
  707  cd ..
  708  sudo systemctl stop apache2
  709  sudo mv ./nextcloud ./nextcloud29
  710  sudo cp /home/alaskalinuxuser/Downloads/nextcloud-30.0.0.tar.bz2 ./
  711  sudo tar -xvf ./nextcloud-30.0.0.tar.bz2 
  712  sudo cp ./nextcloud29/config/config.php ./nextcloud/config/config.php
  713  sudo chown -R www-data:www-data ./nextcloud
  714  cd nextcloud
  715  sudo -u www-data php occ upgrade
  716  cd ..
  717  sudo systemctl start apache2
  718  cd nextcloud
  719  sudo -u www-data php occ maintenance:repair --include-expensive
  720  sudo -u www-data php occ db:add-missing-indices
  721  exit
  722  ls
  723  cd /var/www/nextcloud
  724  sudo -u www-data php occ config:system:set maintenance_window_start --type=integer --value=1
  725  crontab -u www-data
  726  sudo crontab -u www-data
  727  sudo crontab -u www-data -e
  728  sudo nano /etc/php/8.2/apache2/php.ini 
  729  sudo systemctl restart apache2
  730  sudo nano ./config/config.php 
  731  cat /var2/www/nextcloud25/config/config.php 
  732  sudo cat /var2/www/nextcloud25/config/config.php 
  733  sudo nano ./config/config.php 
  734  sudo systemctl restart apache2

This was time consuming, but in Nextcloud’s defense, most people update every version, or two max. I was the one who waited five versions before applying an update! I will also note that Nextcloud’s documentation makes it very clear that you cannot skip versions while updating. I believe that the update process only takes in account one version at a time, so if A changed to B, and B changes to C, and C changes to D with each upgrade, the upgrade command for D to E will not look for A, B, or C, but that’s just my best guess.

Then the question now becomes, which version of PHP to use going forward? PHP 8.2 or 8.3? At this moment in our story, I was on version 8.2, and was very thankful, actually literally praising God that my Nextcloud seemed to be working and all my data was saved! But, the latest version of PHP is 8.3, but as we will see in the next post, I’ll talk about my WordPress blog software and PHP versions, because this caused a lot of trouble.

Linux – keep it simple.

[1] https://deb.sury.org/

2 Replies to “Major Upgrade Part 3: PHP problems and updating Nextcloud”

  1. Hey there!
    I was wondering why don’t you use docker. It should really simply your workload and easen out stuff when you have to do upgrades or just any other changes to the application or OS.

    1. That’s a great question and good observation. I am vaguely familiar with docker, but I don’t use it enough, or as much as I should. Perhaps that is a direction I should go in the future. Just old school I guess! 😉

Leave a Reply

Your email address will not be published. Required fields are marked *