How to update PHP on my LEMP stack droplet (ubuntu)?

Posted February 18, 2018 4.7k views
PHPSystem ToolsLEMPUbuntu 16.04

I have a LEMP stack droplet, but I guess DO uses custom versioning or something since php -v returns a message that I don’t have php. I do have it though, its just version 5.5.9 and I’d need at least 5.6 or later.

How could I update php to the latest stable version, or at least to 5.6, without breaking existing stuff on my droplet?

Many thanks

apt-get upgrade does for the reason above

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

How and when have you deployed LEMP stack Droplet? As far as I know, the latest ones are based on Ubuntu 16.04, therefore should have PHP v7.0+.

If you’re running older version, such as Ubuntu 14.04, you can follow the How To Upgrade to PHP 7 on Ubuntu 14.04.

Make sure your applications is ready for migration. For example, mysql_* functions have been removed in PHP 7, so if your applications are dependent on them, they’ll not work.

by Brennen Bearnes
PHP 7.0 was released on December 3, 2015. It promises substantial speed improvements over previous versions of the language, along with new features like scalar type hinting. This guide explains how to quickly upgrade a PHP 5.x installation on an Ubuntu 14.04 system with Apache or Nginx, using community-provided packages.
  • I deployed it like 2 years ago, auto installed with DO’s LEMP stack droplet installation

    • That’s okay then, it’s based on Ubuntu 14.04 which is coming with PHP 5.

      You can’t upgrade with plain apt-get upgrade, as Ubuntu 14.04 repositories don’t contain version 7.

      You can follow the above linked tutorial to add the appropriate repository and then perform upgrade. You need to follow instructions for nginx.

      Just make sure your app will work correctly after upgrading. You can even create a test Droplet (e.g. from Snapshot) and perform upgrade there, before you do it in the production.

      • Thanks!!

        Do you think I should update ubuntu to 16.04 too or it doesn’t really have benefits?

        • That mostly depends on your needs. Ubuntu 14.04 is supported til April 2019, so you’re good to go with 14.04 for now.

          One of the biggest changes is that all packages are upgraded to the newer version. This is great, but on the other side this can be risky, as you can get into compatability problems.

          If you want to upgrade, I usually recommend to start with new Droplet and then install and test all needed packages. Going this way, you can get sure everything is working well after upgrade.

          You can also check out the How To Upgrade to Ubuntu 16.04 LTS tutorial for more details.

          by Brennen Bearnes
          Ubuntu's next Long Term Support release, version 16.04 (Xenial Xerus), is due to be released on April 21, 2016. This guide explains the upgrade process for systems including (but not limited to) DigitalOcean Droplets running Ubuntu 15.10.