Introduction

In this tutorial I’ll show you how to install the latest version of PHP on Ubuntu 16.04. All the steps in this tutorial has been written as a bash shell script php-fpm.sh and is being a component of my project called proviscript, basiclly I made it for myself. However, you might as well use it to save time if you like.

Shortcut

Proviscript php-fpm.sh is hosted on a stable storage provied by GitHub pages, just two line of command in this approach. Directly install PHP-FPM 7.2.9 on your Unbuntu 16.04 server.

wget https://cdn.proviscript.sh/components/ubuntu_16.04/php-fpm.sh
./php-fpm.sh -v 7.2

By default php-fpm.sh will install all available modules automatically.

That’s it.

Install PHP 7.0

PHP 7.0 is available in the official repository of Ubuntu 16.04 and can be installed by simply using the command:

apt-get install php7

List packages associated with PHP7

apt-cache pkgnames php7

Result:

root@ubuntu-xenial:/home/vagrant# apt-cache pkgnames php7
php7.0-xmlrpc
php7.0-bz2
php7.0-cgi
php7.0-cli
php7.0-dba
php7.0-dev
php7.0-fpm
php7.0-gd
php7.0-gmp
php7.0-opcache
php7.0
php7.0-pspell
php7.0-recode
php7.0-common
php7.0-bcmath
php7.0-sqlite3
php7.0-tidy
php7.0-json
php7.0-mbstring
php7.0-readline
php7.0-xml
php7.0-xsl
php7.0-curl
php7.0-zip
php7.0-ldap
php7.0-pgsql
php7.0-mcrypt
php7.0-imap
php7.0-intl
php7.0-enchant
php7.0-odbc
php7.0-snmp
php7.0-soap
php7.0-sybase
php7.0-phpdbg
php7.0-mysql
php7.0-interbase

You can check the modules that are available for PHP 7.0 and install them if needed.

Install PHP 7.2.9

In previous post section, you probably already know that official repository of Ubuntu 16.04 provides PHP 7.0, not the lastest version. To install the lastest stable version of PHP we can use the well-known third-party PPA (Personal Package Archives) by Ondřej Surý.

You have to first install software-properties-common, which is a software written in Python. It provides an abstraction of the used apt repositories, allows you to easily manage your distribution and independent software vendor software sources.

In other words, software-properties-common provides some useful scripts for adding and removing PPAs.

sudo apt-get install software-properties-common

Add repository which provides the latest PHP version 7.2.9

add-apt-repository ppa:ondrej/php

Update repository.

apt-get update

Install PHP 7.2.9

apt-get install -y php7.2-fpm

Install PHP Pear.

apt-get install -y php-pear

Install PHP 7.2 modules.

apt-get install -y php7.2-pgsql php7.2-curl php7.2-json php7.2-mbstring php7.2-gd php7.2-intl php7.2-xml php7.2-imagick php7.2-redis php7.2-zip

To enable PHP FPM in boot.

systemctl enable php7.2-fpm

Restart PHP FPM service.

service php7.2-fpm restart

To check if PHP 7.2 is installed on your server.

php -v
Last modified: November 3, 2018

Author

Comments

Write a Reply or Comment

Your email address will not be published.