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.txt8 saat diminta
Jika Anda telah menginstal phpMyAdmin, Anda mungkin akan disajikan dengan layar ini
Jika diminta dengan pesan di atas, pilih dpkg -l | grep php | tee packages.txt_9 dan tekan dpkg -l | grep php | tee packages.txt8
Anda mungkin juga diminta untuk menghapus database
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.txt8
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.txt8 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 (//php.net/supported-versions.php) for Supported Ubuntu Releases (//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: //deb.sury.org/#debian-dpa You can get more information about the packages at //deb.sury.org IMPORTANT: The -backports is now required on older Ubuntu releases. BUGS&FEATURES: This PPA now has a issue tracker: //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: //donate.sury.org/ WARNING: add-apt-repository is broken with non-UTF-8 locales, see //github.com/oerdnj/deb.sury.org/issues/56 for workaround: # LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php More info: //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.txt8 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