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
- 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
- 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
- Check the new version with nginx -V.
Use ondrej/php
- Add the repo:
add-apt-repository ppa:ondrej/php
- Update repo list cache:
apt update -y
- 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
- Install your custom module (such as ioncube-loader). Remember to load your ini at both fpm and cli folder.
- Set Default PHP version to 7.2:
update-alternatives --set php /usr/bin/php7.2
- 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
- Done, test, enjoy (or debug :-P)