How To Upgrade to PHP 7.x on Ubuntu and Debian

Most Ubuntu servers come with PHP 5 installed. With recent updates of major PHP CMSs and platforms it requires users to update PHP to version 7.2 to benefit from latest changes and security patches.

PHP 7.2 comes with numerous improvements and new features such as:

  • Convert numeric keys in object/array casts
  • Counting of non-countable objects
  • Object typehint
  • HashContext as Object
  • Argon2 in password hash
  • Improve TLS constants to sane values
  • Mcrypt extension removed
  • New sodium extension

PHP 7.3 new changes:

  • Heredoc and Nowdoc syntax requirements are more relaxed
  • Allow trailing comma in function and method calls
  • PCRE to PCRE2 migration
  • References in list()
  • Deprecate image2wbmp() function
  • Deprecate case-insensitive constants
  • Option to make json_encode and json_decode throw exceptions on errors
  • Introduced is_countable() function
  • Introduced array_key_first() and array_key_last() functions

Install PHP 7.x on Ubuntu

If you want to upgrade your server’s PHP to the newest version and you’re running Ubuntu & Apache, the following commands will be good to use.

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.2-cli
sudo apt-get install php7.2-mysql php7.2-curl php7.2-json php7.2-cgi php7.2-xsl

Install PHP 7.x on Debian

sudo apt install lsb-release apt-transport-https ca-certificates
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg
echo "deb $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php7.3.list
sudo apt update
sudo apt-get install php7.3 php-pear

Remember to install support for MySQL with php7.3-mysql package if you are using this database engine.

sudo apt-get install php7.3-mysql

After installing new PHP version, you must restart Apache server.

Leave a Comment

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

Scroll to Top

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.