Upgrade to the latest PHP version in ubuntu 16.04

yaylitzis

I am using NextCloud in my server and NextCloud informs me that:

You are currently running PHP 7.0.32-0ubuntu0.16.04.1. Upgrade your PHP version to take advantage of performance and security updates provided by the PHP Group as soon as your distribution supports it.

So, I tried to upgrade me OS (Ubuntu 16.04), by executing:

apt-get update apt-get dist-update

Then I restarted the server and I re-executed the above commands. After all these, when I connect from terminal I am getting:

Welcome to Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-83-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

0 packages can be updated.
0 updates are security updates.

and my PHP version is still PHP 7.0.32-0ubuntu0.16.04.1 (cli) ( NTS ).

This means that PHP 7.0.32 is the latest possible version that I can install in ubuntu 16.04;

pa4080

The default PHP version for Ubuntu 16.04 is 7.0. If you want to install a new version of PHP on 16.04 you need to use an additional PPA (as it is shown below) or you must compile it on your own.

My server with Ubuntu 16.04 currently uses PHP 7.2 and there are several operational instances of WordPress and MediaWiki. The web server is Apache 2.4. The commands that I've used to migrate from PHP 7.0 to 7.2 are:

# Add the repository 'ppa:ondrej/php'
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

# Install PHP 7.2
sudo apt install -y php7.2 php7.2-cli libapache2-mod-php7.2
sudo apt install -y php-imagick php-gettext php-memcache php-apcu php-pear php-xml php-xmlrpc
sudo apt install -y php-memcached php-mysql php-intl php-mbstring php-curl php-gd php-imagick
sudo apt install -y php7.2-common php7.2-mysql php7.2-cgi 
sudo apt install -y php7.2-curl php7.2-zip php7.2-mbstring php7.2-xmlrpc php7.2-gd php7.2-xml php7.2-xsl
sudo apt install -y php7.2-dev php7.2-bz2 php7.2-intl php7.2-json php7.2-opcache php7.2-readline 
sudo apt install -y php7.2-imap php7.2-pspell php7.2-recode php7.2-sqlite3 php7.2-tidy php7.2-bcmath #php7.2-mcrypt

# Update the Apache's PHP version
sudo a2dismod php7.0
sudo a2enmod php7.2
sudo systemctl restart apache2.service

# Update the CLI PHP version
sudo update-alternatives --set php /usr/bin/php7.2

In the repository ppa:ondrej/php PHP 7.3 is also available, I think to migrate soon to this latest version.

If there is a problem with the public key of the repository, you can use this solution.

Here are the additional tweaks of my /etc/php/7.2/apache2/php.ini that are made according to few WordPress and MediaWiki manuals:

zlib.output_compression = On
max_execution_time = 600
max_input_vars = 3000
memory_limit = 512M
post_max_size = 256M
upload_max_filesize = 128M
allow_url_fopen = Off
pcre.backtrack_limit=1000000
session.cookie_secure = True
session.gc_maxlifetime = 14400
session.cache_expire = 540
mbstring.encoding_translation = On

Update 04.2019

I've used the above set of commands to install PHP 7.3 on Ubuntu 16.04 and everything went completely fine. Just replace 7.2 with 7.3 within these commands - the entire process took about 7 minutes.


Update 02.2020

I've migrated to PHP 7.4 and everything went well, during that process I've used the following steps (note, at this date NextCloud doesn't support php7.4 yet):

# Absolutely mandatory step
sudo apt update
# Generate list of php7.4 packages on tbe base of the installed 7.3 ones
# Remove 'echo' to install the packages
for pkg in $(sudo apt-cache policy *php7.3* | grep -P '^(lib.*|php)7.3.*:$' | sed -e 's/:$//' -e 's/7.3/7.4/');
do
    echo sudo apt install "$pkg" -y;
done 2>/tmp/php7.4.install.error.log
# Inspect the error log for some fatal errors, 
# Some old dependencies could missing - it's normal
cat /tmp/php7.4.install.error.log
# Mandatory step; If there is a trouble, tray: sudo apt install -f
sudo apt update && sudo apt upgrade
# Create a backup copy of the new php.ini 
sudo cp /etc/php/7.4/apache2/php.ini{,.default}
# Compare the old and the new php.ini files
# Apply the necessary changes to 7.4/apache2/php.ini
# Compare the files again in order to inspect for typos 
colordiff --side-by-side --left-column --width=240 --show-c-function /etc/php/7.{3,4}/apache2/php.ini | less -R
# Switch the version within Apache
sudo a2dismod php7.3 && sudo a2enmod php7.4
sudo systemctl restart apache2
# Switch the CLI version
sudo update-alternatives --set php /usr/bin/php7.4

Update 06.2020

Now I'm using Ubuntu 20.04 Server, it comes by default with php7.4, but I need php7.3. The method above, by using ppa:ondrej/php, solves my issue.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Latest scipy version on ubuntu

From Dev

Upgrade WordPress to latest version in Linux

From Dev

php version in apt - does it correspond to version on php.net and if not how to upgrade to latest release

From Dev

Why Ubuntu doesn't upgrade to the latest version of GnuPG?

From Dev

How to upgrade VirtualBox to the latest version?

From Dev

How to upgrade to the latest GNOME version?

From Dev

How i can upgrade my Ubuntu python3.7 to python3.8 latest version?

From Dev

How do I upgrade PHP version to the latest stable released version?

From Dev

Will it be possible to upgrade to the latest Ubuntu from an older version

From Dev

How to upgrade VirtualBox to the latest version?

From Dev

Why Ubuntu doesn't upgrade to the latest version of GnuPG?

From Dev

How to upgrade to the latest GNOME version?

From Dev

How does one upgrade ubuntu (any version to latest version) using an ISO image?

From Dev

How to upgrade to the latest BlueZ version on Ubuntu 12.04 LTS?

From Dev

Upgrade scipy to the latest version

From Dev

How to upgrade SAMBA to latest version?

From Dev

Why does apt-get upgrade not install the latest PHP version?

From Dev

Upgrade PCRE version on Ubuntu with PHP5

From Dev

upgrade ubuntu to the latest released version

From Dev

Latest scipy version on ubuntu

From Dev

How do I upgrade Vagrant to the latest version in Ubuntu?

From Dev

Upgrade WordPress to latest version in Linux

From Dev

Cannot upgrade git to the latest version in Ubuntu 14.04

From Dev

Upgrade to latest Ubuntu cannot boot

From Dev

How to update/upgrade PHP 7.2 to latest version safely?

From Dev

ubuntu 16: having trouble installing ffmpeg (latest version)

From Dev

upgrade filezilla to latest version

From Dev

Upgrade Pylint Version 1.9.2 to latest Version

From Dev

How to upgrade to latest version of Ubuntu software in 20.04

Related Related

  1. 1

    Latest scipy version on ubuntu

  2. 2

    Upgrade WordPress to latest version in Linux

  3. 3

    php version in apt - does it correspond to version on php.net and if not how to upgrade to latest release

  4. 4

    Why Ubuntu doesn't upgrade to the latest version of GnuPG?

  5. 5

    How to upgrade VirtualBox to the latest version?

  6. 6

    How to upgrade to the latest GNOME version?

  7. 7

    How i can upgrade my Ubuntu python3.7 to python3.8 latest version?

  8. 8

    How do I upgrade PHP version to the latest stable released version?

  9. 9

    Will it be possible to upgrade to the latest Ubuntu from an older version

  10. 10

    How to upgrade VirtualBox to the latest version?

  11. 11

    Why Ubuntu doesn't upgrade to the latest version of GnuPG?

  12. 12

    How to upgrade to the latest GNOME version?

  13. 13

    How does one upgrade ubuntu (any version to latest version) using an ISO image?

  14. 14

    How to upgrade to the latest BlueZ version on Ubuntu 12.04 LTS?

  15. 15

    Upgrade scipy to the latest version

  16. 16

    How to upgrade SAMBA to latest version?

  17. 17

    Why does apt-get upgrade not install the latest PHP version?

  18. 18

    Upgrade PCRE version on Ubuntu with PHP5

  19. 19

    upgrade ubuntu to the latest released version

  20. 20

    Latest scipy version on ubuntu

  21. 21

    How do I upgrade Vagrant to the latest version in Ubuntu?

  22. 22

    Upgrade WordPress to latest version in Linux

  23. 23

    Cannot upgrade git to the latest version in Ubuntu 14.04

  24. 24

    Upgrade to latest Ubuntu cannot boot

  25. 25

    How to update/upgrade PHP 7.2 to latest version safely?

  26. 26

    ubuntu 16: having trouble installing ffmpeg (latest version)

  27. 27

    upgrade filezilla to latest version

  28. 28

    Upgrade Pylint Version 1.9.2 to latest Version

  29. 29

    How to upgrade to latest version of Ubuntu software in 20.04

HotTag

Archive