Upgrade to latest Nginx and PHP-FPM on Ubuntu 16

Ubuntu 16 might be the most popular Ubuntu version (right now), so I put more effort on it. By default, the current Ubuntu 16.04 officially support PHP 7.0.x and Nginx 1.10.x versions. However as a crazy one who always wanna try latest releases, I cannot bear with it. So, below are steps help you upgrade to the latest Nginx and PHP-FPM on Ubuntu 16.04 server.

Use Nginx Mainline

  1. Add mainline to repo list:
    echo "deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx
    deb-src http://nginx.org/packages/mainline/ubuntu/ xenial nginx" > /etc/apt/sources.list.d/nginx.list
  2. Install the new package:
    wget https://nginx.org/keys/nginx_signing.key -O - | apt-key add -
    apt-get -y update
    apt-get -y install nginx
  3. Check the new version with nginx -V.

Use ondrej/php

  1. Add the repo:
    add-apt-repository ppa:ondrej/php
  2. Update repo list cache:
    apt update -y
  3. Install PHP 7.2 and its modules:
    apt-get install php-pear php7.2-curl php7.2-dev php7.2-gd php7.2-mbstring php7.2-zip php7.2-mysql php7.2-xml php7.2-opcache php7.2-redis php7.2-fpm php7.2-imap php7.2-mcrypt
  4. Install your custom module (such as ioncube-loader). Remember to load your ini at both fpm and cli folder.
  5. Set Default PHP version to 7.2:
    update-alternatives --set php /usr/bin/php7.2
  6. Stop/Disable PHP-FPM 7.0 and Start/Enable PHP-FPM 7.2:
    systemctl stop php7.0-fpm
    systemctl start php7.2-fpm
    systemctl enable php7.2-fpm
    systemctl disable php7.0-fpm
  7. Done, test, enjoy (or debug :-P)

About NhocConan

A super lazy guy who tries to write tech blog entries in English.He is lazy, so he can only write when he is in a good mood or when he is tired of coding.

Leave a comment

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