Hướng dẫn how do i install another version of php? - làm cách nào để cài đặt một phiên bản php khác?

PHP (Từ viết tắt đệ quy cho PHP: Bộ tiền xử lý siêu văn bản) là một ngôn ngữ kịch bản đa năng phổ biến, phổ biến được sử dụng rộng rãi và phù hợp nhất để phát triển các trang web và các ứng dụng dựa trên web. Đây là ngôn ngữ kịch bản phía máy chủ có thể được nhúng trong HTML. (recursive acronym for PHP: Hypertext Preprocessor) is an open-source, popular general-purpose scripting language that is widely used and best suited for developing websites and web-based applications. It is a server-side scripting language that can be embedded in HTML.

Hiện tại, có ba phiên bản được hỗ trợ của PHP, tức là PHP 5.6, 7.0 và 8.0. Có nghĩa là Php 5.3, 5.4 và 5.5 đều đã đến cuối đời; Chúng không còn được hỗ trợ với các bản cập nhật bảo mật.PHP, i.e PHP 5.6, 7.0, and 8.0. Meaning PHP 5.3, 5.4, and 5.5 have all reached the end of life; they are no longer supported with security updates.

Trong bài viết này, chúng tôi sẽ giải thích cách cài đặt tất cả các phiên bản PHP được hỗ trợ trong Ubuntu và các dẫn xuất của nó với các phần mở rộng PHP được yêu cầu nhiều nhất cho cả máy chủ Web Apache và NGINX bằng PPA Ondřej Surý. Chúng tôi cũng sẽ giải thích cách đặt phiên bản PHP mặc định sẽ được sử dụng trên hệ thống Ubuntu.PHP in Ubuntu and its derivatives with the most requested PHP extensions for both Apache and Nginx web servers using an Ondřej Surý PPA. We will also explain how to set the default version of PHP to be used on the Ubuntu system.

Lưu ý rằng PHP 7.x là phiên bản ổn định được hỗ trợ trong kho phần mềm Ubuntu, bạn có thể xác nhận điều này bằng cách chạy lệnh APT bên dưới.PHP 7.x is the supported stable version in the Ubuntu software repositories, you can confirm this by running the apt command below.

$ sudo apt show php
OR
$ sudo apt show php -a

Hiển thị thông tin phiên bản PHP

Package: php
Version: 1:7.0+35ubuntu6
Priority: optional
Section: php
Source: php-defaults (35ubuntu6)
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: Debian PHP Maintainers <[email protected]>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 11.3 kB
Depends: php7.0
Supported: 5y
Download-Size: 2,832 B
APT-Sources: http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages
Description: server-side, HTML-embedded scripting language (default)
 PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used
 open source general-purpose scripting language that is especially suited
 for web development and can be embedded into HTML.
 .
 This package is a dependency package, which depends on Debian's default
 PHP version (currently 7.0).

Để cài đặt phiên bản PHP mặc định từ kho phần mềm Ubuntu, hãy sử dụng lệnh bên dưới.

$ sudo apt install php

Cài đặt PHP (5.6, 7.x, 8.0) trên Ubuntu bằng PPA

1. Đầu tiên bắt đầu bằng cách thêm PPA Ondřej Surý để cài đặt các phiên bản khác nhau của PHP - PHP 5.6, PHP 7.X và PHP 8.0 trên hệ thống Ubuntu. First start by adding Ondřej Surý PPA to install different versions of PHP – PHP 5.6, PHP 7.x, and PHP 8.0 on the Ubuntu system.

$ sudo apt install software-properties-common
$ sudo add-apt-repository ppa:ondrej/php
Add PPA ở Ubuntu
Hướng dẫn how do i install another version of php? - làm cách nào để cài đặt một phiên bản php khác?
Add PPA in Ubuntu

2. Tiếp theo, cập nhật hệ thống như sau. Next, update the system as follows.

$ sudo apt-get update

3. Bây giờ cài đặt các phiên bản PHP được hỗ trợ khác nhau như sau. Now install different supported versions of PHP as follows.

Cho máy chủ web Apache

$ sudo apt install php5.6   [PHP 5.6]
$ sudo apt install php7.0   [PHP 7.0]
$ sudo apt install php7.1   [PHP 7.1]
$ sudo apt install php7.2   [PHP 7.2]
$ sudo apt install php7.3   [PHP 7.3]
$ sudo apt install php7.4   [PHP 7.4]
$ sudo apt install php8.0   [PHP 8.0]

Cho máy chủ web nginx

$ sudo apt install php5.6-fpm   [PHP 5.6]
$ sudo apt install php7.0-fpm   [PHP 7.0]
$ sudo apt install php7.1-fpm   [PHP 7.1]
$ sudo apt install php7.2-fpm   [PHP 7.2]
$ sudo apt install php7.3-fpm   [PHP 7.3]
$ sudo apt install php7.4-fpm   [PHP 7.4]
$ sudo apt install php8.0-fpm   [PHP 8.0]

4. Để cài đặt bất kỳ mô-đun PHP nào, chỉ cần chỉ định phiên bản PHP và sử dụng chức năng tự động hoàn thành để xem tất cả các mô-đun như sau. To install any PHP modules, simply specify the PHP version and use the auto-completion functionality to view all modules as follows.

------------ press Tab key for auto-completion ------------ 
$ sudo apt install php5.6 
$ sudo apt install php7.0 
$ sudo apt install php7.1
$ sudo apt install php7.2
$ sudo apt install php7.3 
$ sudo apt install php7.4
$ sudo apt install php8.0
Các mô -đun PHP PHP
Hướng dẫn how do i install another version of php? - làm cách nào để cài đặt một phiên bản php khác?
Search PHP Modules

5. Bây giờ bạn có thể cài đặt các mô -đun PHP cần thiết nhất từ ​​danh sách. Now you can install the most required PHP modules from the list.

------------ Install PHP Modules ------------
$ sudo apt install php5.6-cli php5.6-xml php5.6-mysql 
$ sudo apt install php7.0-cli php7.0-xml php7.0-mysql 
$ sudo apt install php7.1-cli php7.1-xml php7.1-mysql
$ sudo apt install php7.2-cli php7.2-xml php7.2-mysql 
$ sudo apt install php7.3-cli php7.3-xml php7.3-mysql 
$ sudo apt install php7.3-cli php7.4-xml php7.4-mysql  
$ sudo apt install php7.3-cli php8.0-xml php8.0-mysql  

6. Cuối cùng, hãy xác minh phiên bản PHP mặc định của bạn được sử dụng trên hệ thống của bạn như thế này. Finally, verify your default PHP version used on your system like this.

$ php -v 
Kiểm tra phiên bản PHP mặc định trong ubuntu
Hướng dẫn how do i install another version of php? - làm cách nào để cài đặt một phiên bản php khác?
Check Default PHP Version in Ubuntu

Đặt phiên bản PHP mặc định trong ubuntu

7 You can set the default PHP version to be used on the system with the update-alternatives command, after setting it, check the PHP version to confirm as follows.

Package: php
Version: 1:7.0+35ubuntu6
Priority: optional
Section: php
Source: php-defaults (35ubuntu6)
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: Debian PHP Maintainers <[email protected]>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 11.3 kB
Depends: php7.0
Supported: 5y
Download-Size: 2,832 B
APT-Sources: http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages
Description: server-side, HTML-embedded scripting language (default)
 PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used
 open source general-purpose scripting language that is especially suited
 for web development and can be embedded into HTML.
 .
 This package is a dependency package, which depends on Debian's default
 PHP version (currently 7.0).
0Set Php 5.6 Phiên bản trong Ubuntu
Package: php
Version: 1:7.0+35ubuntu6
Priority: optional
Section: php
Source: php-defaults (35ubuntu6)
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: Debian PHP Maintainers <[email protected]>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 11.3 kB
Depends: php7.0
Supported: 5y
Download-Size: 2,832 B
APT-Sources: http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages
Description: server-side, HTML-embedded scripting language (default)
 PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used
 open source general-purpose scripting language that is especially suited
 for web development and can be embedded into HTML.
 .
 This package is a dependency package, which depends on Debian's default
 PHP version (currently 7.0).
1Set Php 7.0 Phiên bản trong Ubuntu
Package: php
Version: 1:7.0+35ubuntu6
Priority: optional
Section: php
Source: php-defaults (35ubuntu6)
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: Debian PHP Maintainers <[email protected]>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 11.3 kB
Depends: php7.0
Supported: 5y
Download-Size: 2,832 B
APT-Sources: http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages
Description: server-side, HTML-embedded scripting language (default)
 PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used
 open source general-purpose scripting language that is especially suited
 for web development and can be embedded into HTML.
 .
 This package is a dependency package, which depends on Debian's default
 PHP version (currently 7.0).
2Set Php 7.1 Phiên bản trong Ubuntu
Package: php
Version: 1:7.0+35ubuntu6
Priority: optional
Section: php
Source: php-defaults (35ubuntu6)
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: Debian PHP Maintainers <[email protected]>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 11.3 kB
Depends: php7.0
Supported: 5y
Download-Size: 2,832 B
APT-Sources: http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages
Description: server-side, HTML-embedded scripting language (default)
 PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used
 open source general-purpose scripting language that is especially suited
 for web development and can be embedded into HTML.
 .
 This package is a dependency package, which depends on Debian's default
 PHP version (currently 7.0).
3Set Php 8 phiên bản
Hướng dẫn how do i install another version of php? - làm cách nào để cài đặt một phiên bản php khác?
Set PHP 5.6 Version in Ubuntu
Package: php
Version: 1:7.0+35ubuntu6
Priority: optional
Section: php
Source: php-defaults (35ubuntu6)
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: Debian PHP Maintainers <[email protected]>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 11.3 kB
Depends: php7.0
Supported: 5y
Download-Size: 2,832 B
APT-Sources: http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages
Description: server-side, HTML-embedded scripting language (default)
 PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used
 open source general-purpose scripting language that is especially suited
 for web development and can be embedded into HTML.
 .
 This package is a dependency package, which depends on Debian's default
 PHP version (currently 7.0).
1
Hướng dẫn how do i install another version of php? - làm cách nào để cài đặt một phiên bản php khác?
Set PHP 7.0 Version in Ubuntu
Package: php
Version: 1:7.0+35ubuntu6
Priority: optional
Section: php
Source: php-defaults (35ubuntu6)
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: Debian PHP Maintainers <[email protected]>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 11.3 kB
Depends: php7.0
Supported: 5y
Download-Size: 2,832 B
APT-Sources: http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages
Description: server-side, HTML-embedded scripting language (default)
 PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used
 open source general-purpose scripting language that is especially suited
 for web development and can be embedded into HTML.
 .
 This package is a dependency package, which depends on Debian's default
 PHP version (currently 7.0).
2
Hướng dẫn how do i install another version of php? - làm cách nào để cài đặt một phiên bản php khác?
Set PHP 7.1 Version in Ubuntu
Package: php
Version: 1:7.0+35ubuntu6
Priority: optional
Section: php
Source: php-defaults (35ubuntu6)
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: Debian PHP Maintainers <[email protected]>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 11.3 kB
Depends: php7.0
Supported: 5y
Download-Size: 2,832 B
APT-Sources: http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages
Description: server-side, HTML-embedded scripting language (default)
 PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used
 open source general-purpose scripting language that is especially suited
 for web development and can be embedded into HTML.
 .
 This package is a dependency package, which depends on Debian's default
 PHP version (currently 7.0).
3
Hướng dẫn how do i install another version of php? - làm cách nào để cài đặt một phiên bản php khác?
Set PHP 8 Version

8. Để đặt phiên bản PHP sẽ hoạt động với máy chủ web Apache, hãy sử dụng các lệnh bên dưới. Đầu tiên, vô hiệu hóa phiên bản hiện tại với lệnh A2Dismod và sau đó kích hoạt phiên bản bạn muốn với lệnh A2enMod. To set the PHP version that will work with the Apache web server, use the commands below. First, disable the current version with the a2dismod command and then enable the one you want with the a2enmod command.

Package: php
Version: 1:7.0+35ubuntu6
Priority: optional
Section: php
Source: php-defaults (35ubuntu6)
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: Debian PHP Maintainers <[email protected]>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 11.3 kB
Depends: php7.0
Supported: 5y
Download-Size: 2,832 B
APT-Sources: http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages
Description: server-side, HTML-embedded scripting language (default)
 PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used
 open source general-purpose scripting language that is especially suited
 for web development and can be embedded into HTML.
 .
 This package is a dependency package, which depends on Debian's default
 PHP version (currently 7.0).
4 có thể tắt các mô -đun PHP cho Apache
Hướng dẫn how do i install another version of php? - làm cách nào để cài đặt một phiên bản php khác?
Enable Disable PHP Modules for Apache

9. Sau khi chuyển từ phiên bản này sang phiên bản khác, bạn có thể tìm thấy tệp cấu hình PHP của mình, bằng cách chạy lệnh bên dưới. After switching from one version to another, you can find your PHP configuration file, by running the command below.

Package: php
Version: 1:7.0+35ubuntu6
Priority: optional
Section: php
Source: php-defaults (35ubuntu6)
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: Debian PHP Maintainers <[email protected]>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 11.3 kB
Depends: php7.0
Supported: 5y
Download-Size: 2,832 B
APT-Sources: http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages
Description: server-side, HTML-embedded scripting language (default)
 PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used
 open source general-purpose scripting language that is especially suited
 for web development and can be embedded into HTML.
 .
 This package is a dependency package, which depends on Debian's default
 PHP version (currently 7.0).
5find Tệp cấu hình PHP
Hướng dẫn how do i install another version of php? - làm cách nào để cài đặt một phiên bản php khác?
Find PHP Configuration File

Bạn cũng có thể thích:

  1. Cách sử dụng và thực thi mã PHP trong dòng lệnh Linux
  2. 12 Sử dụng dòng lệnh PHP hữu ích, mỗi người dùng Linux phải biết
  3. Cách ẩn phiên bản PHP trong tiêu đề HTTP

Trong bài viết này, chúng tôi đã chỉ ra cách cài đặt tất cả các phiên bản được hỗ trợ của PHP trong Ubuntu và các dẫn xuất của nó. Nếu bạn có bất kỳ truy vấn hoặc suy nghĩ nào để chia sẻ, hãy làm như vậy thông qua mẫu phản hồi dưới đây.

Nếu bạn đánh giá cao những gì chúng tôi làm ở đây trên tecmint, bạn nên xem xét:

Tecmint là trang web cộng đồng phát triển nhanh nhất và đáng tin cậy nhất cho bất kỳ loại bài viết, hướng dẫn và sách Linux nào trên web. Hàng triệu người ghé thăm Tecmint! Để tìm kiếm hoặc duyệt hàng ngàn bài báo được xuất bản có sẵn tự do cho tất cả.

Nếu bạn thích những gì bạn đang đọc, vui lòng xem xét việc mua cho chúng tôi một ly cà phê (hoặc 2) như một dấu hiệu đánh giá cao.

Hướng dẫn how do i install another version of php? - làm cách nào để cài đặt một phiên bản php khác?

Chúng tôi rất biết ơn vì sự hỗ trợ không bao giờ kết thúc của bạn.

Làm cách nào để cài đặt một phiên bản cụ thể của PHP?

Tóm lại những gì bạn cần làm là:..
Đảm bảo các gói PHP cho phiên bản bạn muốn được cài đặt ..
Cập nhật bất kỳ cấu hình nào cho phiên bản PHP đó ..
Cập nhật cấu hình máy chủ web của bạn để trỏ đến phiên bản PHP chính xác ..
Điểm PHP CLI đến phiên bản PHP chính xác ..
Khởi động lại máy chủ web và PHP-FPM của bạn ..
Mặt nạ Daemon PHP-FPM cũ ..

Làm cách nào để cài đặt nhiều phiên bản PHP trên Windows?

Các bước để thay đổi cổng:..
Thay đổi tệp cấu hình cho MySQL trong My My. Tệp Ini ”..
Thay đổi cổng thành 3307 ..
Chạy mã: PHP. ....
Lưu mã trên trong thư mục của HT HTDOCS của thư mục XAMPP cho phiên bản mới và cũ hơn ..
Lưu trong thư mục HTDOCS của thư mục XAMPP ..
Tương tự với XAMPP_1_8_2 ..

Tôi có thể chạy một số phiên bản PHP cùng một lúc không?

Có, chúng tôi có thể chạy một số phiên bản của PHP.Để làm điều đó, chúng ta phải kiểm tra tệp cài đặt, nếu nó được bao gồm trong phân phối nguồn PHP.. To do that we must have to check the INSTALL file, if it is included in PHP source distribution.

Làm cách nào để tải xuống phiên bản PHP cũ hơn?

Nếu bạn cần một bản rollback của PHP, hãy xem lịch sử phiên bản của ứng dụng trên Uptodown.Nó bao gồm tất cả các phiên bản tệp có sẵn để tải xuống TẮT UPTODOWN cho ứng dụng đó.Tải xuống rollback của PHP cho Windows.Bất kỳ phiên bản PHP nào được phân phối trên Uptodown hoàn toàn không có virus và miễn phí tải xuống miễn phí.check out the app's version history on Uptodown. It includes all the file versions available to download off Uptodown for that app. Download rollbacks of PHP for Windows. Any version of PHP distributed on Uptodown is completely virus-free and free to download at no cost.