Install PHP 8.0 Ubuntu 22.04 | 20.04 | 18.04

Install PHP 8.0 Ubuntu 22.04. Php (Hypertext Preprocessor), merupakan salah satu pemograman disisi server yang sangat penting untuk dipelajari. Jenis server yang sering menggunakan PHP antara lain Apache, Nginx, dan LiteSpeed.

PHP merupakan bahasa pemograman yang bersifat OpenSource, yang artinya user bebas mengunduh, memodifikasi, dan mengembangkan sesuai dengan kebutuhan. PHP ini merupakan salah satu jenis bahasa pemograman yang sangat banyak digunakan termasuk di web dinamis maupun rensponsif. Contoh platform yang populer menggunakan PHP yakni WordPress, Drupal, dan Magento.

Berikut beberapa faktor yang membuat PHP begitu populer.

  • Mudah dipelajari
  • Sumber untuk belajar melimpah
  • Bersifat OpenSource
  • Kecepatan tinggi
  • Pilihan database yang beragam
  • Kompatibilitas yang baik dengan HTML 
  • Multi-platform 
  • Selalu Update
  • Mendukung layanan cloud

Dalam penulisannya Kode PHP juga dibagi dua, yaitu PHP Native dan PHP Framework. PHP Native adalah penulisan kode PHP dari nol ketika melakukan perancangan sebuah website sendangkan PHP Framework, developer dapat memanfaatkan kerangka pengelolaan website yang sudah jadi.

Langkah 1 – Update & Upgrade System Ubuntu

Sebelum memulai installasi, harap untuk melakukan Update dan Upgrade pada System, agar nantinya package yang terinstall nantinya juga update.

apt update && apt upgrade

Tunggu hingga update dan upgrade hingga selesai. Jika sudah selesai, makan reboot system terlebih dulu.

reboot

Langkah 2 – Add Repository

Untuk Ubuntu 22.04 tidak perlu lagi menggunakan atau menambahkan Repository, karena pada Ubuntu 22.04 pada systemnya sudah dapat pembaruan untuk PHP 8.0. Jika Anda menggunakan PHP 8.0 | 18.04, harus menambahkan Repository. Untuk menambahkan Repository, dapat menggunakan perintah dibawah ini.

Untuk Ubuntu 20.04 | 18.04

ini hanya perulu digunakan pada Ubuntu 20.04 dan 18.04.

apt update
apt install lsb-release ca-certificates apt-transport-https software-properties-common -y

tambahkan Repository

add-apt-repository ppa:ondrej/php

Tekan Enter pada saat menambahkan Repository.

Debian oldstable and stable packages are provided as well: https://deb.sury.org/#debian-dpa

You can get more information about the packages at https://deb.sury.org

IMPORTANT: The <foo>-backports is now required on older Ubuntu releases.

BUGS&FEATURES: This PPA now has a issue tracker:
https://deb.sury.org/#bug-reporting

CAVEATS:
1. If you are using php-gearman, you need to add ppa:ondrej/pkg-gearman
2. If you are using apache2, you are advised to add ppa:ondrej/apache2
3. If you are using nginx, you are advised to add ppa:ondrej/nginx-mainline
   or ppa:ondrej/nginx

PLEASE READ: If you like my work and want to give me a little motivation, please consider donating regularly: https://donate.sury.org/

WARNING: add-apt-repository is broken with non-UTF-8 locales, see
https://github.com/oerdnj/deb.sury.org/issues/56 for workaround:

# LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
More info: https://launchpad.net/~ondrej/+archive/ubuntu/php
Adding repository.
Press [ENTER] to continue or Ctrl-c to cancel.Adding deb entry to /etc/apt/sources.list.d/ondrej-ubuntu-php-jammy.list

Berikut tampilan penambahan Repository pada Ubuntu 20.04 | 18.04

Langkah 3 – Instal PHP 8.0 Ubuntu 22.04 | 20.04 | 18.04

Jika Repository sudah ditambahkan, kembali lakukan Update pada System dan untuk memastikan package yang ditambahkan sebelumnya tidak bermasalah.

apt update

Kemudian lalukan Install PHP 8.0 Ubuntu 22.04 | 20.04 | 18.04

apt install php8.0 -y

Lalu pilih Y, untuk memulai install PHP8.0

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils bzip2 file
  libapache2-mod-php8.0 libapr1 libaprutil1 libaprutil1-dbd-sqlite3
  libaprutil1-ldap libjansson4 liblua5.3-0 libmagic-mgc libmagic1 libsodium23
  mailcap mime-support php-common php8.0-cli php8.0-common php8.0-opcache
  php8.0-readline psmisc ssl-cert
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser ufw
  bzip2-doc php-pear
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils bzip2 file
  libapache2-mod-php8.0 libapr1 libaprutil1 libaprutil1-dbd-sqlite3
  libaprutil1-ldap libjansson4 liblua5.3-0 libmagic-mgc libmagic1 libsodium23
  mailcap mime-support php-common php8.0 php8.0-cli php8.0-common
  php8.0-opcache php8.0-readline psmisc ssl-cert
0 upgraded, 26 newly installed, 0 to remove and 2 not upgraded.
Need to get 7712 kB of archives.
After this operation, 37.3 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Konfirmasi versi PHP dengan menggunakn perintah berikut ini

php -v

Output

php -v
PHP 8.0.21 (cli) (built: Jul 13 2022 08:26:57) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.21, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.21, Copyright (c), by Zend Technologies

Langkah 4 : Install Ektensi PHP 8 Ubuntu 22.04 | 20.04 | 18.04

Untuk installasi PHP dengan Develop Website tidak hanya PHP saja, tentunya kita perlu menginstall Ektensi dari PHP tersebut. Untuk menginstall PHP Extentsion gunakan perintah berikut ini .

apt install php8.0 php8.0-amqp php8.0-common php8.0-gd php8.0-ldap php8.0-odbc php8.0-readline php8.0-sqlite3 php8.0-xsl php8.0-curl php8.0-gmp php8.0-mailparse php8.0-opcache php8.0-redis php8.0-sybase php8.0-ast php8.0-dba php8.0-igbinary php8.0-mbstring php8.0-pgsql php8.0-rrd php8.0-tidy php8.0-yaml php8.0-bcmath php8.0-dev php8.0-imagick php8.0-memcached php8.0-phpdbg php8.0-smbclient php8.0-uuid php8.0-zip php8.0-bz2 php8.0-ds php8.0-imap php8.0-msgpack php8.0-pspell php8.0-snmp php8.0-xdebug php8.0-zmq php8.0-cgi php8.0-enchant php8.0-interbase php8.0-mysql php8.0-psr php8.0-soap php8.0-xhprof php8.0-cli php8.0-fpm php8.0-intl php8.0-oauth php8.0-raphf php8.0-solr php8.0-xml

Output

Dan tunggu proses Install Extension, mungkin akan memakan waktu, karena Extension yang akan diinstall lumayan banyak

Untuk melihat daftar Extentison PHP yang diinstall, gunakan perintah berikut.

php -m

Jika sudah selesai dalam Installasi PHP, Anda konfirmasi Status PHP dengan menggunakan perintah berikut ini.

systemctl status php*

Output

php8.0-fpm.service - The PHP 8.0 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php8.0-fpm.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2022-07-18 06:56:31 UTC; 16min ago
       Docs: man:php-fpm8.0(8)
    Process: 34818 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/8.0/fpm/pool.d/www.conf 80 (code=exited, status=0/SUCCESS)
   Main PID: 34815 (php-fpm8.0)
     Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
      Tasks: 3 (limit: 2241)
     Memory: 18.6M
        CPU: 277ms
     CGroup: /system.slice/php8.0-fpm.service
             ├─34815 "php-fpm: master process (/etc/php/8.0/fpm/php-fpm.conf)" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ├─34816 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             └─34817 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Jul 18 06:56:31 dixmata systemd[1]: Starting The PHP 8.0 FastCGI Process Manager...
Jul 18 06:56:31 dixmata php-fpm8.0[34815]: Created directory: /var/lib/snmp/cert_indexes
Jul 18 06:56:31 dixmata systemd[1]: Started The PHP 8.0 FastCGI Process Manager.

● phpsessionclean.timer - Clean PHP session files every 30 mins
     Loaded: loaded (/lib/systemd/system/phpsessionclean.timer; enabled; vendor preset: enabled)
     Active: active (waiting) since Mon 2022-07-18 06:34:23 UTC; 38min ago
    Trigger: Mon 2022-07-18 07:39:00 UTC; 26min left
   Triggers: ● phpsessionclean.service

Jul 18 06:34:23 dixmata systemd[1]: Started Clean PHP session files every 30 mins.

Source :