How to update nginx & php

Posted December 29, 2019 13.6k views
Linux BasicsNginx

Hi there,

I would like to Update NGINX & PHP & Ubuntu to the current version’s.

**Current: **
**Server Info: nginx/1.14.0
PHP Version: *

I have already used google but in this constellation, but i haven’t figured it out clear -

How is the right way?

Would be very happy if someone could give me a tip

many thanks in advance


edited by bobbyiliev

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

Hi @danielmire,

Regarding Nginx, upgrading is fairly easy and usually doesn’t break anything. You need to add a new repo, then Nginx can be upgraded every time you run your sudo apt upgrade command.

The first steps you’ll want to do is backing up your current NGINX configs. You can run these two commands to create a backup directory and copy your config files over to it:

sudo mkdir /etc/nginx-backup/
sudo cp -r /etc/nginx/* /etc/nginx-backup/

Next we need to add the repository. For this, you’ll need to install software-properties-common if it’s not already installed. Run this command to make sure it is installed:

sudo apt-get install software-properties-common

Now we’ll add the NGINX repo by running these commands:

sudo add-apt-repository ppa:nginx/$nginx

Once done, you’ll need to update your system like so

sudo apt-get update
sudo apt-get full-upgrade

You’ll be prompted to use a new config files twice, you’ll want to answer N to those for now to keep your current version.

Now when you run sudo nginx -v you should see a new version.

Finally, you’ll want to edit your /etc/nginx/nginx.conf file and add this line just below the pid line near the top:

include /etc/nginx/modules-enabled/*.conf;

Next, run sudo nginx -t to test the new config and make any changes you need in order for it to pass the test.

Then restart your nginx service and you are good to go.


In this case rather than updating, you’ll just install a higher PHP version on your droplet.

Here are the steps, if you are on an Ubuntu.

Update Packages

Make sure your Ubuntu server is having the latest packages by running the following command.

sudo apt update
sudo apt upgrade

Add a repository for PHP 7.3

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php7.3-fpm


PHP with it’s extensions is useless so you’ll need to install them regardless which Web Service you are using. The next command will include the most common extensions

sudo apt install php7.3-common php7.3-mysql php7.3-xml php7.3-xmlrpc php7.3-curl php7.3-gd php7.3-imagick php7.3-cli php7.3-dev php7.3-imap php7.3-mbstring php7.3-opcache php7.3-soap php7.3-zip php7.3-intl -y 

If you need to add another one, just type in

sudo apt install php7.3-nameofextension

And you are ready, you now have the latest PHP version on your droplet.


  • I’m running VESTA and I have installed two php versions.

    root@mail:/etc/php# ls -lrt
    total 8
    drwxr-xr-x 6 root root 4096 Jan 17  2017 7.0
    drwxr-xr-x 7 root root 4096 Oct  9  2019 7.2
    1. 7.2 used in command line
    :~# php -v
    PHP 7.2.19-0ubuntu0.18.04.2 (cli) (built: Aug 12 2019 19:34:28) ( NTS )
    Copyright (c) 1997-2018 The PHP Group
    Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
        with Zend OPcache v7.2.19-0ubuntu0.18.04.2, Copyright (c) 1999-2018, by Zend Technologies
    1. But 7.0 is used in web pages:

    phpInfo image

    How can I setup it so phpinfo uses php v7.2?