Bagaimana cara memperbarui php di terminal ubuntu?

Anda harus mencadangkan server Anda sebelum menjalankan perintah ini karena tidak dapat dibalik dengan mudah. Jika Anda menggunakan cloud hosting, pastikan Anda membuat gambar instance Anda sebelum menjalankan salah satu dari perintah ini

Untuk mengetahui versi PHP yang sedang Anda gunakan, jalankan

php -v

Jika Anda menjalankan PHP 7. x, Anda dapat melanjutkan panduan ini untuk meningkatkan ke PHP 8

1. Paket PHP

Mengupgrade dari PHP 7. x ke PHP 8 melibatkan tidak hanya pemutakhiran inti PHP, tetapi semua ekstensinya. Misalnya, jika Anda menggunakan ekstensi PHP cURL, Anda harus menginstal versi PHP 8 secara manual di bagian akhir panduan ini

Di akhir panduan ini, saya menyertakan perintah untuk menginstal ekstensi PHP 8 yang paling umum, namun, Anda harus memeriksa PHP 7 mana yang paling umum. x ekstensi saat ini dipasang di server khusus Anda dan catat semua yang penting untuk menjalankan aplikasi web Anda sendiri

dpkg -l | grep php | tee packages.txt
_

Keluaran

ii  libapache2-mod-php               1:7.2+60ubuntu1                             all          server-side, HTML-embedded scri
ii  libapache2-mod-php7.2            7.2.24-0ubuntu0.18.04.7                     amd64        server-side, HTML-embedded scri
ii  php                              1:7.2+60ubuntu1                             all          server-side, HTML-embedded scri
ii  php-bz2                          1:7.2+60ubuntu1                             all          bzip2 module for PHP [default]
ii  php-common                       1:60ubuntu1                                 all          Common files for PHP packages
ii  php-curl                         1:7.2+60ubuntu1                             all          CURL module for PHP [default]
ii  php-gd                           1:7.2+60ubuntu1                             all          GD module for PHP [default]
ii  php-mbstring                     1:7.2+60ubuntu1                             all          MBSTRING module for PHP [defaul
ii  php-mysql                        1:7.2+60ubuntu1                             all          MySQL module for PHP [default]
ii  php-pear                         1:1.10.5+submodules+notgz-1ubuntu1.18.04.3  all          PEAR Base System
ii  php-php-gettext                  1.0.12-0.1                                  all          read gettext MO files directly,
ii  php-phpseclib                    2.0.9-1                                     all          implementations of an arbitrary
ii  php-tcpdf                        6.2.13+dfsg-1ubuntu1                        all          PHP class for generating PDF fi
ii  php-xml                          1:7.2+60ubuntu1                             all          DOM, SimpleXML, WDDX, XML, and
ii  php-zip                          1:7.2+60ubuntu1                             all          Zip module for PHP [default]
ii  php7.2                           7.2.24-0ubuntu0.18.04.7                     all          server-side, HTML-embedded scri
ii  php7.2-bz2                       7.2.24-0ubuntu0.18.04.7                     amd64        bzip2 module for PHP
ii  php7.2-cli                       7.2.24-0ubuntu0.18.04.7                     amd64        command-line interpreter for th
ii  php7.2-common                    7.2.24-0ubuntu0.18.04.7                     amd64        documentation, examples and com
ii  php7.2-curl                      7.2.24-0ubuntu0.18.04.7                     amd64        CURL module for PHP
ii  php7.2-gd                        7.2.24-0ubuntu0.18.04.7                     amd64        GD module for PHP
ii  php7.2-json                      7.2.24-0ubuntu0.18.04.7                     amd64        JSON module for PHP
ii  php7.2-mbstring                  7.2.24-0ubuntu0.18.04.7                     amd64        MBSTRING module for PHP
ii  php7.2-mysql                     7.2.24-0ubuntu0.18.04.7                     amd64        MySQL module for PHP
ii  php7.2-opcache                   7.2.24-0ubuntu0.18.04.7                     amd64        Zend OpCache module for PHP
ii  php7.2-readline                  7.2.24-0ubuntu0.18.04.7                     amd64        readline module for PHP
ii  php7.2-xml                       7.2.24-0ubuntu0.18.04.7                     amd64        DOM, SimpleXML, WDDX, XML, and
ii  php7.2-zip                       7.2.24-0ubuntu0.18.04.7                     amd64        Zip module for PHP
ii  phpmyadmin                       4:4.6.6-5ubuntu0.5                          all          MySQL web administration tool

Contoh di atas menunjukkan PHP 7. 2 ekstensi dipasang di server saya sendiri sebelum memutakhirkan ke PHP 8. Salin hasil Anda sendiri ke dalam file teks dan simpan dengan aman jika Anda perlu menginstal versi PHP 8 nanti

2. Copot pemasangan/Hapus PHP 7. x dan Ekstensi

Untuk menghapus PHP 7. x dan semua ekstensinya, jalankan perintah di bawah ini

sudo apt-get purge php7.*

Tekan

dpkg -l | grep php | tee packages.txt
_7 dan
dpkg -l | grep php | tee packages.txt
8 saat diminta

Jika Anda telah menginstal phpMyAdmin, Anda mungkin akan disajikan dengan layar ini

Bagaimana cara memperbarui php di terminal ubuntu?

Jika diminta dengan pesan di atas, pilih

dpkg -l | grep php | tee packages.txt
_9 dan tekan
dpkg -l | grep php | tee packages.txt
8

Anda mungkin juga diminta untuk menghapus database

Bagaimana cara memperbarui php di terminal ubuntu?

Jika diminta dengan pesan di atas, pilih

ii  libapache2-mod-php               1:7.2+60ubuntu1                             all          server-side, HTML-embedded scri
ii  libapache2-mod-php7.2            7.2.24-0ubuntu0.18.04.7                     amd64        server-side, HTML-embedded scri
ii  php                              1:7.2+60ubuntu1                             all          server-side, HTML-embedded scri
ii  php-bz2                          1:7.2+60ubuntu1                             all          bzip2 module for PHP [default]
ii  php-common                       1:60ubuntu1                                 all          Common files for PHP packages
ii  php-curl                         1:7.2+60ubuntu1                             all          CURL module for PHP [default]
ii  php-gd                           1:7.2+60ubuntu1                             all          GD module for PHP [default]
ii  php-mbstring                     1:7.2+60ubuntu1                             all          MBSTRING module for PHP [defaul
ii  php-mysql                        1:7.2+60ubuntu1                             all          MySQL module for PHP [default]
ii  php-pear                         1:1.10.5+submodules+notgz-1ubuntu1.18.04.3  all          PEAR Base System
ii  php-php-gettext                  1.0.12-0.1                                  all          read gettext MO files directly,
ii  php-phpseclib                    2.0.9-1                                     all          implementations of an arbitrary
ii  php-tcpdf                        6.2.13+dfsg-1ubuntu1                        all          PHP class for generating PDF fi
ii  php-xml                          1:7.2+60ubuntu1                             all          DOM, SimpleXML, WDDX, XML, and
ii  php-zip                          1:7.2+60ubuntu1                             all          Zip module for PHP [default]
ii  php7.2                           7.2.24-0ubuntu0.18.04.7                     all          server-side, HTML-embedded scri
ii  php7.2-bz2                       7.2.24-0ubuntu0.18.04.7                     amd64        bzip2 module for PHP
ii  php7.2-cli                       7.2.24-0ubuntu0.18.04.7                     amd64        command-line interpreter for th
ii  php7.2-common                    7.2.24-0ubuntu0.18.04.7                     amd64        documentation, examples and com
ii  php7.2-curl                      7.2.24-0ubuntu0.18.04.7                     amd64        CURL module for PHP
ii  php7.2-gd                        7.2.24-0ubuntu0.18.04.7                     amd64        GD module for PHP
ii  php7.2-json                      7.2.24-0ubuntu0.18.04.7                     amd64        JSON module for PHP
ii  php7.2-mbstring                  7.2.24-0ubuntu0.18.04.7                     amd64        MBSTRING module for PHP
ii  php7.2-mysql                     7.2.24-0ubuntu0.18.04.7                     amd64        MySQL module for PHP
ii  php7.2-opcache                   7.2.24-0ubuntu0.18.04.7                     amd64        Zend OpCache module for PHP
ii  php7.2-readline                  7.2.24-0ubuntu0.18.04.7                     amd64        readline module for PHP
ii  php7.2-xml                       7.2.24-0ubuntu0.18.04.7                     amd64        DOM, SimpleXML, WDDX, XML, and
ii  php7.2-zip                       7.2.24-0ubuntu0.18.04.7                     amd64        Zip module for PHP
ii  phpmyadmin                       4:4.6.6-5ubuntu0.5                          all          MySQL web administration tool
1 dan tekan
dpkg -l | grep php | tee packages.txt
8

3. Autoclean dan Autoremove

Setelah menghapus paket dari Linux, disarankan untuk menjalankan kedua perintah ini

sudo apt-get autoclean

sudo apt-get autoremove

Tekan

ii  libapache2-mod-php               1:7.2+60ubuntu1                             all          server-side, HTML-embedded scri
ii  libapache2-mod-php7.2            7.2.24-0ubuntu0.18.04.7                     amd64        server-side, HTML-embedded scri
ii  php                              1:7.2+60ubuntu1                             all          server-side, HTML-embedded scri
ii  php-bz2                          1:7.2+60ubuntu1                             all          bzip2 module for PHP [default]
ii  php-common                       1:60ubuntu1                                 all          Common files for PHP packages
ii  php-curl                         1:7.2+60ubuntu1                             all          CURL module for PHP [default]
ii  php-gd                           1:7.2+60ubuntu1                             all          GD module for PHP [default]
ii  php-mbstring                     1:7.2+60ubuntu1                             all          MBSTRING module for PHP [defaul
ii  php-mysql                        1:7.2+60ubuntu1                             all          MySQL module for PHP [default]
ii  php-pear                         1:1.10.5+submodules+notgz-1ubuntu1.18.04.3  all          PEAR Base System
ii  php-php-gettext                  1.0.12-0.1                                  all          read gettext MO files directly,
ii  php-phpseclib                    2.0.9-1                                     all          implementations of an arbitrary
ii  php-tcpdf                        6.2.13+dfsg-1ubuntu1                        all          PHP class for generating PDF fi
ii  php-xml                          1:7.2+60ubuntu1                             all          DOM, SimpleXML, WDDX, XML, and
ii  php-zip                          1:7.2+60ubuntu1                             all          Zip module for PHP [default]
ii  php7.2                           7.2.24-0ubuntu0.18.04.7                     all          server-side, HTML-embedded scri
ii  php7.2-bz2                       7.2.24-0ubuntu0.18.04.7                     amd64        bzip2 module for PHP
ii  php7.2-cli                       7.2.24-0ubuntu0.18.04.7                     amd64        command-line interpreter for th
ii  php7.2-common                    7.2.24-0ubuntu0.18.04.7                     amd64        documentation, examples and com
ii  php7.2-curl                      7.2.24-0ubuntu0.18.04.7                     amd64        CURL module for PHP
ii  php7.2-gd                        7.2.24-0ubuntu0.18.04.7                     amd64        GD module for PHP
ii  php7.2-json                      7.2.24-0ubuntu0.18.04.7                     amd64        JSON module for PHP
ii  php7.2-mbstring                  7.2.24-0ubuntu0.18.04.7                     amd64        MBSTRING module for PHP
ii  php7.2-mysql                     7.2.24-0ubuntu0.18.04.7                     amd64        MySQL module for PHP
ii  php7.2-opcache                   7.2.24-0ubuntu0.18.04.7                     amd64        Zend OpCache module for PHP
ii  php7.2-readline                  7.2.24-0ubuntu0.18.04.7                     amd64        readline module for PHP
ii  php7.2-xml                       7.2.24-0ubuntu0.18.04.7                     amd64        DOM, SimpleXML, WDDX, XML, and
ii  php7.2-zip                       7.2.24-0ubuntu0.18.04.7                     amd64        Zip module for PHP
ii  phpmyadmin                       4:4.6.6-5ubuntu0.5                          all          MySQL web administration tool
_3 dan
dpkg -l | grep php | tee packages.txt
8 jika diminta

4. Tambahkan repositori PPA Ondřej Surý

Jika Anda menjalankan Ubuntu 22. 04 ke atas, Anda tidak perlu menambahkan repositori di bawah ini. Sebagai gantinya, lewati ke bagian 5

Jika Anda menjalankan Ubuntu 20. 04 atau 18. 04, paket biner PHP 8 hanya tersedia di repositori PPA Ondřej Surý. Instal di bawah

sudo add-apt-repository ppa:ondrej/php

Anda mungkin melihat pesan selamat datang

Keluaran

Co-installable PHP versions: PHP 5.6, PHP 7.x and most requested extensions are included. Only Supported Versions of PHP (http://php.net/supported-versions.php) for Supported Ubuntu Releases (https://wiki.ubuntu.com/Releases) are provided. Don't ask for end-of-life PHP versions or Ubuntu release, they won't be provided.

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 -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
Press [ENTER] to continue or Ctrl-c to cancel adding it.

Tekan

dpkg -l | grep php | tee packages.txt
_8 untuk menambahkan repositori

5. Instal PHP8

Pada saat penulisan, PHP 8. 1 sekarang tersedia jadi kami akan menginstalnya. Jika versi yang lebih baru tersedia, pastikan untuk mengubah perintah di bawah agar sesuai

sudo apt-get update

sudo apt-get install php8.1

Keluaran

dpkg -l | grep php | tee packages.txt
_0

Tekan

ii  libapache2-mod-php               1:7.2+60ubuntu1                             all          server-side, HTML-embedded scri
ii  libapache2-mod-php7.2            7.2.24-0ubuntu0.18.04.7                     amd64        server-side, HTML-embedded scri
ii  php                              1:7.2+60ubuntu1                             all          server-side, HTML-embedded scri
ii  php-bz2                          1:7.2+60ubuntu1                             all          bzip2 module for PHP [default]
ii  php-common                       1:60ubuntu1                                 all          Common files for PHP packages
ii  php-curl                         1:7.2+60ubuntu1                             all          CURL module for PHP [default]
ii  php-gd                           1:7.2+60ubuntu1                             all          GD module for PHP [default]
ii  php-mbstring                     1:7.2+60ubuntu1                             all          MBSTRING module for PHP [defaul
ii  php-mysql                        1:7.2+60ubuntu1                             all          MySQL module for PHP [default]
ii  php-pear                         1:1.10.5+submodules+notgz-1ubuntu1.18.04.3  all          PEAR Base System
ii  php-php-gettext                  1.0.12-0.1                                  all          read gettext MO files directly,
ii  php-phpseclib                    2.0.9-1                                     all          implementations of an arbitrary
ii  php-tcpdf                        6.2.13+dfsg-1ubuntu1                        all          PHP class for generating PDF fi
ii  php-xml                          1:7.2+60ubuntu1                             all          DOM, SimpleXML, WDDX, XML, and
ii  php-zip                          1:7.2+60ubuntu1                             all          Zip module for PHP [default]
ii  php7.2                           7.2.24-0ubuntu0.18.04.7                     all          server-side, HTML-embedded scri
ii  php7.2-bz2                       7.2.24-0ubuntu0.18.04.7                     amd64        bzip2 module for PHP
ii  php7.2-cli                       7.2.24-0ubuntu0.18.04.7                     amd64        command-line interpreter for th
ii  php7.2-common                    7.2.24-0ubuntu0.18.04.7                     amd64        documentation, examples and com
ii  php7.2-curl                      7.2.24-0ubuntu0.18.04.7                     amd64        CURL module for PHP
ii  php7.2-gd                        7.2.24-0ubuntu0.18.04.7                     amd64        GD module for PHP
ii  php7.2-json                      7.2.24-0ubuntu0.18.04.7                     amd64        JSON module for PHP
ii  php7.2-mbstring                  7.2.24-0ubuntu0.18.04.7                     amd64        MBSTRING module for PHP
ii  php7.2-mysql                     7.2.24-0ubuntu0.18.04.7                     amd64        MySQL module for PHP
ii  php7.2-opcache                   7.2.24-0ubuntu0.18.04.7                     amd64        Zend OpCache module for PHP
ii  php7.2-readline                  7.2.24-0ubuntu0.18.04.7                     amd64        readline module for PHP
ii  php7.2-xml                       7.2.24-0ubuntu0.18.04.7                     amd64        DOM, SimpleXML, WDDX, XML, and
ii  php7.2-zip                       7.2.24-0ubuntu0.18.04.7                     amd64        Zip module for PHP
ii  phpmyadmin                       4:4.6.6-5ubuntu0.5                          all          MySQL web administration tool
_3 dan
dpkg -l | grep php | tee packages.txt
8 jika diminta

Mulai ulang Apache

dpkg -l | grep php | tee packages.txt
_1

6. Instal Ekstensi PHP 8

Perintah di bawah menyertakan beberapa ekstensi PHP paling populer, yang seharusnya mencakup situs WordPress pada umumnya. Namun, jika Anda menemukan bahwa beberapa ekstensi hilang, lihat Langkah 1 di atas dan instal secara manual paket yang Anda perlukan

Bagaimana cara memperbarui PHP di terminal?

Singkatnya yang perlu Anda lakukan adalah. .
Pastikan paket php untuk versi yang Anda inginkan sudah diinstal
Perbarui konfigurasi apa pun untuk versi PHP itu
Perbarui konfigurasi server web Anda untuk menunjuk ke versi PHP yang benar
Arahkan PHP CLI ke versi PHP yang benar
Mulai ulang server web Anda dan php-fpm
Tutupi daemon php-fpm lama

Cara memperbarui PHP7. 4 sampai 8. 1 Ubuntu?

Paket PHP
Copot pemasangan/Hapus PHP 7. x dan Ekstensi
Autoclean dan Autoremove
Tambahkan repositori PPA Ondřej Surý
Instal PHP8
Instal Ekstensi PHP 8
Periksa versi PHP

Cara memperbarui PHP ke 7. 4 Ubuntu?

Instal PHP 7. 4 di Ubuntu 18. 04/Ubuntu 16. 04 .
Langkah 1. Tambahkan Repositori PHP PPA. Kami akan menambahkan ppa. ondrej/php Repositori PPA yang memiliki paket build PHP terbaru. .
Langkah 2. Instal PHP7. 4 di Ubuntu 18. 04/16. 04. Instal PHP7. 4 di Ubuntu 18. 04/19. 04/16. 04 menggunakan perintah. sudo apt -y instal php7. 4

Apa versi terbaru PHP di Ubuntu?

Seperti kebanyakan alat pengembang, PHP memiliki beberapa versi rilis yang berbeda. Pada saat penulisan, PHP 7. 4 . dan 8. 1 adalah versi perangkat lunak yang saat ini didukung dan paling banyak digunakan. Di Ubuntu 20. 04, perintah menginstal PHP 7. 4 sedangkan Ubuntu 22. 04 menginstal PHP versi 8. 1.