Install PHP on Ubuntu 20.04

Install php pada ubuntu 20.04

  • Tambahkan repository ondrej PHP pada ubuntu 20.04
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:ondrej/php
sudp apt update
  • Install PHP, vilih versi php yang akan di install
sudo apt install php5.6 -y
sudo apt install php7.0 -y
sudo apt install php7.1 -y
sudo apt install php7.2 -y
sudo apt install php7.3 -y
sudo apt install php7.4 -y
sudo apt install php8.0 -y
  • Install PHP Module, ubah versi php dan sesuaikan dengan versi php yang sudah di install.
apt install -y php7.4-{common,cli,gd,curl,mysql,xml,mbstring,zip,ldap,xmlrpc,curl,intl,fpm,imagick,dev,imap,opcache,soap,memcached,mcrypt,apcu}
  • Cek versi php
php -v
PHP 8.0.11 (cli) (built: Sep 23 2021 21:26:24) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.11, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.11, Copyright (c), by Zend Technologies
  • Ganti versi antar php
sudo update-alternatives --config php

There are 7 choices for the alternative php (providing /usr/bin/php).

  Selection    Path             Priority   Status
------------------------------------------------------------
* 0            /usr/bin/php8.0   80        auto mode
  1            /usr/bin/php5.6   56        manual mode
  2            /usr/bin/php7.0   70        manual mode
  3            /usr/bin/php7.1   71        manual mode
  4            /usr/bin/php7.2   72        manual mode
  5            /usr/bin/php7.3   73        manual mode
  6            /usr/bin/php7.4   74        manual mode
  7            /usr/bin/php8.0   80        manual mode

Press <enter> to keep the current choice[*], or type selection number: 1
  • Cek versi kembali, versi php sudah berganti
php -v
PHP 5.6.40-54+ubuntu20.04.1+deb.sury.org+1 (cli)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
  • Cek lokasi file konfigurasi php
/etc/php/5.6/apache2/php.ini
/etc/php/7.0/apache2/php.ini
/etc/php/7.1/apache2/php.ini
/etc/php/7.2/apache2/php.ini
/etc/php/7.3/apache2/php.ini
/etc/php/7.4/apache2/php.ini
/etc/php/8.0/apache2/php.ini

herdiana3389

A system administrator with skills in system administration, virtualization, linux, windows, networking, cloud computing, container, etc.