Cách nâng cấp PHP Debian

apt update

Nếu có bất kỳ bản cập nhật nào, hãy cập nhật hệ thống và khởi động lại

apt upgrade -y && reboot

Đầu tiên tải xuống khóa GPG

apt -y install lsb-release apt-transport-https ca-certificates 
wget -O /etc/apt/trusted.gpg.d/php.gpg //packages.sury.org/php/apt.gpg

Tiếp theo, thêm SURY vào kho lưu trữ

echo "deb //packages.sury.org/php/ $[lsb_release -sc] main" | tee /etc/apt/sources.list.d/php.list

đầu ra

deb //packages.sury.org/php/ buster main

Đảm bảo gói đã thêm được cập nhật

apt update

Nếu có bất kỳ bản cập nhật nào, hãy cập nhật hệ thống và khởi động lại

apt upgrade -y && reboot

Để cài đặt PHP 7. 4

apt -y install php7.4

Để kiểm tra phiên bản PHP

________số 8_______

đầu ra

root@vps:~# php -v
PHP 7.4.6 [cli] [built: May 14 2020 10:03:28] [ NTS ]
Copyright [c] The PHP Group
Zend Engine v3.4.0, Copyright [c] Zend Technologies
    with Zend OPcache v7.4.6, Copyright [c], by Zend Technologies

GHI CHÚ

  • Các cấu hình PHP liên quan đến Apache được lưu trữ trong
    apt upgrade -y && reboot
    0 tệp này
  • Nếu bạn muốn sử dụng PHP với Nginx, bạn có thể làm theo hướng dẫn này Bấm vào đây và nếu apache đã được cài đặt, cần phải tắt nó đi
    apt upgrade -y && reboot
    1

Điều này kết thúc chủ đề cài đặt PHP 7 của chúng ta. 4 trên hệ thống Debian 10 hoặc Debian 9

Bạn phải sao lưu máy chủ của mình trước khi chạy các lệnh này vì chúng không thể đảo ngược dễ dàng. Nếu bạn đang sử dụng dịch vụ lưu trữ đám mây, hãy đảm bảo rằng bạn hình dung phiên bản của mình trước khi chạy bất kỳ lệnh nào trong số này

Để biết phiên bản PHP nào bạn đang sử dụng, hãy chạy

________số 8_______

Nếu bạn đang chạy PHP 7. x, bạn có thể tiếp tục với hướng dẫn này để nâng cấp lên PHP 8

1. Gói PHP

Nâng cấp từ PHP 7. x lên PHP 8 không chỉ liên quan đến việc nâng cấp lõi PHP mà còn tất cả các tiện ích mở rộng của nó. Ví dụ: nếu bạn sử dụng tiện ích mở rộng PHP cURL, bạn sẽ cần cài đặt thủ công phiên bản PHP 8 ở cuối hướng dẫn này

Ở cuối hướng dẫn này, tôi đã bao gồm một lệnh để cài đặt các tiện ích mở rộng PHP 8 phổ biến nhất, tuy nhiên, bạn nên kiểm tra xem PHP 7 nào. x hiện được cài đặt trên máy chủ cụ thể của bạn và lưu ý mọi thứ quan trọng đối với việc chạy ứng dụng web của riêng bạn

dpkg -l | grep php | tee packages.txt

đầu ra

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

Ví dụ trên cho thấy PHP 7. 2 tiện ích mở rộng được cài đặt trên máy chủ của riêng tôi trước khi nâng cấp lên PHP 8. Sao chép kết quả của riêng bạn vào một tệp văn bản và giữ nó an toàn trong trường hợp bạn cần cài đặt phiên bản PHP 8 sau này

2. Gỡ cài đặt/Gỡ bỏ PHP 7. x và Tiện ích mở rộng

Để gỡ cài đặt PHP 7. x và tất cả các tiện ích mở rộng của nó, hãy chạy lệnh bên dưới

sudo apt-get purge php7.*

Nhấn

dpkg -l | grep php | tee packages.txt
7 và
dpkg -l | grep php | tee packages.txt
8 khi được nhắc

Nếu bạn đã cài đặt phpMyAdmin, bạn có thể thấy màn hình này

Nếu được nhắc với thông báo trên, hãy chọn

dpkg -l | grep php | tee packages.txt
9 và nhấn
dpkg -l | grep php | tee packages.txt
8

Bạn cũng có thể được nhắc xóa cơ sở dữ liệu

Nếu được nhắc với thông báo trên, hãy chọn

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 và nhấn
dpkg -l | grep php | tee packages.txt
8

3. Autoclean và Autoremove

Sau khi gỡ cài đặt các gói khỏi Linux, bạn nên chạy hai lệnh này

sudo apt-get autoclean

sudo apt-get autoremove

Nhấn

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 và
dpkg -l | grep php | tee packages.txt
8 nếu được nhắc

4. Thêm kho lưu trữ PPA của Ondřej Surý

Nếu bạn đang chạy Ubuntu 22. 04 trở lên thì không cần thêm kho bên dưới này. Thay vào đó, hãy chuyển sang phần 5

Nếu bạn đang chạy Ubuntu 20. 04 hoặc 18. 04, các gói nhị phân PHP 8 chỉ khả dụng trong kho lưu trữ Ondřej Surý PPA. Cài đặt bên dưới

sudo add-apt-repository ppa:ondrej/php

Bạn có thể thấy một thông báo chào mừng

đầu ra

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.

Nhấn

dpkg -l | grep php | tee packages.txt
8 để thêm kho lưu trữ

5. Cài đặt PHP8

Khi viết, PHP 8. 1 hiện đã có sẵn vì vậy chúng tôi sẽ cài đặt cái đó. Nếu có phiên bản mới hơn, hãy đảm bảo thay đổi các lệnh bên dưới để phù hợp

sudo apt-get update

sudo apt-get install php8.1

đầu ra

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

Nhấn

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 và
dpkg -l | grep php | tee packages.txt
8 nếu được nhắc

Khởi động lại Apache

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

6. Cài đặt phần mở rộng PHP 8

Lệnh bên dưới bao gồm một số tiện ích mở rộng PHP phổ biến nhất, bao gồm một trang web WordPress điển hình. Tuy nhiên, nếu bạn thấy rằng một số tiện ích mở rộng bị thiếu, hãy tham khảo Bước 1 ở trên và cài đặt các gói bạn yêu cầu theo cách thủ công

Làm cách nào để cập nhật PHP lên phiên bản mới nhất trong Debian?

Cài đặt PHP 7. 4 trên Debian 10 / Debian 9 .
Bước 1. Cập nhật hệ thống. Đảm bảo hệ thống của bạn được cập nhật. cập nhật sudo apt && sudo apt -y nâng cấp đầy đủ [ -f /var/run/reboot-required ] && sudo reboot -f
Bước 2. Thêm kho lưu trữ SURY PHP PPA. .
Bước 3. Cài đặt PHP 7. 4 trên Debian 10 / Debian 9. .
Bước 4. Sử dụng PHP với Máy chủ web Nginx

Cách nâng cấp PHP 7. 4 đến 8 Debian?

Cài đặt PHP8. 0 gói . 0 từ ppa. ondrej/php được phát triển bởi OndÅ™ej Surý, một nhà phát triển Debian lâu năm. thêm ppa. kho lưu trữ ondrej/php. Cập nhật chỉ mục gói. Mô phỏng quá trình cài đặt PHP 8. 0 gói sử dụng danh sách được tạo trong phần trước

Làm cách nào để nâng cấp PHP trên Debian 10?

5 bước thực hiện PHP 8. 1 cho Apache2 trên Debian. .
Cập nhật Debian với quyền root. $ su - $ cập nhật apt $ nâng cấp apt -y && khởi động lại
Thêm Kho lưu trữ SURY PHP PPA. .
Cài đặt PHP 8. 1 trên Debian. .
Cài đặt các Mô-đun quan trọng cho PHP 8. 1 trên Debian. .
Làm PHP 8. Có sẵn 1 module cho Apache

Cách nâng cấp PHP 7. 3 đến 7. 4 trong Debian?

Hãy đảm bảo tạo bản sao lưu thích hợp cho máy chủ của bạn trước khi tiếp tục. .
Thêm ondrej/php PPA. Nhờ Ondrej, chúng tôi có PHP 7. 4 bản dựng đã sẵn sàng tại PPA của anh ấy. .
Nhận danh sách các gói PHP hiện tại. .
Cài đặt PHP 7. 4. .
Kiểm tra PHP 7. 4 cài đặt. .
Xóa các phiên bản PHP cũ

Chủ Đề