Giải thích này dựa trên Ubuntu 16.04 nhưng cũng được dự kiến sẽ làm việc cho các phiên bản khác
Hầu hết các câu trả lời ở đây thao tác phiên bản PHP bằng cách sử dụng lệnh
sudo update-alternatives --set ...
Mặc dù lệnh khá hữu ích nhưng nó không bao giờ giải thích chính xác những gì nó làm. Đây là lời giải thích, bao gồm sao lưu và một số tùy chọn:
Nhận thông tin
- Lệnh
2 đang hiển thị hoặc thay đổi các liên kết symlink nằm trong một hướng thay thế trong ubuntu thường được định nghĩa là$ ls -al /etc/alternatives/php* lrwxrwxrwx 1 root root 15 Jan 19 02:58 /etc/alternatives/php -> /usr/bin/php7.2 lrwxrwxrwx 1 root root 31 Jan 19 02:58 /etc/alternatives/php.1.gz -> /usr/share/man/man1/php7.2.1.gz lrwxrwxrwx 1 root root 19 Jan 19 03:00 /etc/alternatives/php-cgi -> /usr/bin/php-cgi7.2 lrwxrwxrwx 1 root root 35 Jan 19 03:00 /etc/alternatives/php-cgi.1.gz -> /usr/share/man/man1/php-cgi7.2.1.gz lrwxrwxrwx 1 root root 23 Jan 19 03:00 /etc/alternatives/php-cgi-bin -> /usr/lib/cgi-bin/php7.2
3 nhưng cũng có thể thay đổi.$ ls -al /etc/alternatives/php* lrwxrwxrwx 1 root root 15 Jan 19 02:58 /etc/alternatives/php -> /usr/bin/php7.2 lrwxrwxrwx 1 root root 31 Jan 19 02:58 /etc/alternatives/php.1.gz -> /usr/share/man/man1/php7.2.1.gz lrwxrwxrwx 1 root root 19 Jan 19 03:00 /etc/alternatives/php-cgi -> /usr/bin/php-cgi7.2 lrwxrwxrwx 1 root root 35 Jan 19 03:00 /etc/alternatives/php-cgi.1.gz -> /usr/share/man/man1/php-cgi7.2.1.gz lrwxrwxrwx 1 root root 23 Jan 19 03:00 /etc/alternatives/php-cgi-bin -> /usr/lib/cgi-bin/php7.2
- Một danh sách đầy đủ các tùy chọn liên quan đến
2 có thể được hiển thị với lệnh$ ls -al /etc/alternatives/php* lrwxrwxrwx 1 root root 15 Jan 19 02:58 /etc/alternatives/php -> /usr/bin/php7.2 lrwxrwxrwx 1 root root 31 Jan 19 02:58 /etc/alternatives/php.1.gz -> /usr/share/man/man1/php7.2.1.gz lrwxrwxrwx 1 root root 19 Jan 19 03:00 /etc/alternatives/php-cgi -> /usr/bin/php-cgi7.2 lrwxrwxrwx 1 root root 35 Jan 19 03:00 /etc/alternatives/php-cgi.1.gz -> /usr/share/man/man1/php-cgi7.2.1.gz lrwxrwxrwx 1 root root 23 Jan 19 03:00 /etc/alternatives/php-cgi-bin -> /usr/lib/cgi-bin/php7.2
5, một lời giải thích sâu hơn có thể được hiển thị với$ ls -al /etc/alternatives/php* lrwxrwxrwx 1 root root 15 Jan 19 02:58 /etc/alternatives/php -> /usr/bin/php7.2 lrwxrwxrwx 1 root root 31 Jan 19 02:58 /etc/alternatives/php.1.gz -> /usr/share/man/man1/php7.2.1.gz lrwxrwxrwx 1 root root 19 Jan 19 03:00 /etc/alternatives/php-cgi -> /usr/bin/php-cgi7.2 lrwxrwxrwx 1 root root 35 Jan 19 03:00 /etc/alternatives/php-cgi.1.gz -> /usr/share/man/man1/php-cgi7.2.1.gz lrwxrwxrwx 1 root root 23 Jan 19 03:00 /etc/alternatives/php-cgi-bin -> /usr/lib/cgi-bin/php7.2
6.$ ls -al /etc/alternatives/php* lrwxrwxrwx 1 root root 15 Jan 19 02:58 /etc/alternatives/php -> /usr/bin/php7.2 lrwxrwxrwx 1 root root 31 Jan 19 02:58 /etc/alternatives/php.1.gz -> /usr/share/man/man1/php7.2.1.gz lrwxrwxrwx 1 root root 19 Jan 19 03:00 /etc/alternatives/php-cgi -> /usr/bin/php-cgi7.2 lrwxrwxrwx 1 root root 35 Jan 19 03:00 /etc/alternatives/php-cgi.1.gz -> /usr/share/man/man1/php-cgi7.2.1.gz lrwxrwxrwx 1 root root 23 Jan 19 03:00 /etc/alternatives/php-cgi-bin -> /usr/lib/cgi-bin/php7.2
- Vì lệnh
2 là các liên kết chính thay đổi chính trong một thư mục đặc biệt, nội dung của thư mục đó cũng có thể được hiển thị với các lệnh chung, sau tất cả các mục bắt đầu bằng$ ls -al /etc/alternatives/php* lrwxrwxrwx 1 root root 15 Jan 19 02:58 /etc/alternatives/php -> /usr/bin/php7.2 lrwxrwxrwx 1 root root 31 Jan 19 02:58 /etc/alternatives/php.1.gz -> /usr/share/man/man1/php7.2.1.gz lrwxrwxrwx 1 root root 19 Jan 19 03:00 /etc/alternatives/php-cgi -> /usr/bin/php-cgi7.2 lrwxrwxrwx 1 root root 35 Jan 19 03:00 /etc/alternatives/php-cgi.1.gz -> /usr/share/man/man1/php-cgi7.2.1.gz lrwxrwxrwx 1 root root 23 Jan 19 03:00 /etc/alternatives/php-cgi-bin -> /usr/lib/cgi-bin/php7.2
8 được hiển thị:$ ls -al /etc/alternatives/php* lrwxrwxrwx 1 root root 15 Jan 19 02:58 /etc/alternatives/php -> /usr/bin/php7.2 lrwxrwxrwx 1 root root 31 Jan 19 02:58 /etc/alternatives/php.1.gz -> /usr/share/man/man1/php7.2.1.gz lrwxrwxrwx 1 root root 19 Jan 19 03:00 /etc/alternatives/php-cgi -> /usr/bin/php-cgi7.2 lrwxrwxrwx 1 root root 35 Jan 19 03:00 /etc/alternatives/php-cgi.1.gz -> /usr/share/man/man1/php-cgi7.2.1.gz lrwxrwxrwx 1 root root 23 Jan 19 03:00 /etc/alternatives/php-cgi-bin -> /usr/lib/cgi-bin/php7.2
$ ls -al /etc/alternatives/php* lrwxrwxrwx 1 root root 15 Jan 19 02:58 /etc/alternatives/php -> /usr/bin/php7.2 lrwxrwxrwx 1 root root 31 Jan 19 02:58 /etc/alternatives/php.1.gz -> /usr/share/man/man1/php7.2.1.gz lrwxrwxrwx 1 root root 19 Jan 19 03:00 /etc/alternatives/php-cgi -> /usr/bin/php-cgi7.2 lrwxrwxrwx 1 root root 35 Jan 19 03:00 /etc/alternatives/php-cgi.1.gz -> /usr/share/man/man1/php-cgi7.2.1.gz lrwxrwxrwx 1 root root 23 Jan 19 03:00 /etc/alternatives/php-cgi-bin -> /usr/lib/cgi-bin/php7.2
- Để hiển thị các mục với lệnh
2, hãy sử dụng lệnh này:$ ls -al /etc/alternatives/php* lrwxrwxrwx 1 root root 15 Jan 19 02:58 /etc/alternatives/php -> /usr/bin/php7.2 lrwxrwxrwx 1 root root 31 Jan 19 02:58 /etc/alternatives/php.1.gz -> /usr/share/man/man1/php7.2.1.gz lrwxrwxrwx 1 root root 19 Jan 19 03:00 /etc/alternatives/php-cgi -> /usr/bin/php-cgi7.2 lrwxrwxrwx 1 root root 35 Jan 19 03:00 /etc/alternatives/php-cgi.1.gz -> /usr/share/man/man1/php-cgi7.2.1.gz lrwxrwxrwx 1 root root 23 Jan 19 03:00 /etc/alternatives/php-cgi-bin -> /usr/lib/cgi-bin/php7.2
$ update-alternatives --list php /usr/bin/php7.0 /usr/bin/php7.2
- Để hiển thị thêm chi tiết, bạn có thể thực hiện điều này:
$ update-alternatives --display php php - auto mode link best version is /usr/bin/php7.2 link currently points to /usr/bin/php7.2 link php is /usr/bin/php slave php.1.gz is /usr/share/man/man1/php.1.gz /usr/bin/php7.0 - priority 70 slave php.1.gz: /usr/share/man/man1/php7.0.1.gz /usr/bin/php7.2 - priority 72 slave php.1.gz: /usr/share/man/man1/php7.2.1.gz
Cuối cùng, chúng tôi vẫn muốn biết chúng tôi có thể liên kết với những người tham gia PHP nào. Lệnh sau đây hiển thị danh sách các phiên bản PHP hiện có trong
$ update-alternatives --list php
/usr/bin/php7.0
/usr/bin/php7.2
0:$ ls -al /usr/bin/php* lrwxrwxrwx 1 root root 21 Jan 1 19:47 /usr/bin/php -> /etc/alternatives/php -rwxr-xr-x 1 root root 4385840 Apr 5 18:13 /usr/bin/php7.0 -rwxr-xr-x 1 root root 4875488 Apr 5 18:10 /usr/bin/php7.2 lrwxrwxrwx 1 root root 25 Jan 1 19:47 /usr/bin/php-cgi -> /etc/alternatives/php-cgi -rwxr-xr-x 1 root root 4279672 Apr 5 18:13 /usr/bin/php-cgi7.0 -rwxr-xr-x 1 root root 4769272 Apr 5 18:10 /usr/bin/php-cgi7.2 -rwxr-xr-x 1 root root 663 Feb 29 2016 /usr/bin/phpunit
Sao lưu thông tin
- Để tạo bản sao lưu thông tin của các SymLinks này, chỉ cần lưu danh sách trong một tệp và lưu nó trên máy tính để bàn của bạn với lệnh này [điều chỉnh tên tệp
1 theo nhu cầu của bạn]:$ update-alternatives --list php /usr/bin/php7.0 /usr/bin/php7.2
$ echo "command: update-alternatives --list php" > ~/Desktop/alternatives-php.txt $ update-alternatives --display php >> ~/Desktop/alternatives-php.txt $ echo "command: update-alternatives --display php" >> ~/Desktop/alternatives-php.txt $ update-alternatives --display php >> ~/Desktop/alternatives-php.txt
Nếu bạn thích bạn vẫn có thể thêm kết quả của lệnh
2 như được hiển thị ở trên:$ update-alternatives --list php /usr/bin/php7.0 /usr/bin/php7.2
$ echo "command: ls -al /etc/alternatives/php*" >> ~/Desktop/alternatives-php.txt $ ls -al /etc/alternatives/php* >> ~/Desktop/alternatives-php.txt
... và các Php-Versions có sẵn:
$ echo "command: ls -al /usr/bin/php*" >> ~/Desktop/alternatives-php.txt $ ls -al /usr/bin/php* >> ~/Desktop/alternatives-php.txt
Thay đổi phiên bản PHP cho dòng lệnh
- Nếu chúng ta lọc trước ____ 23-DOCUMENT, danh sách trong
4 bao gồm 3 dòng:$ update-alternatives --list php /usr/bin/php7.0 /usr/bin/php7.2
$ ls -al /etc/alternatives/php* lrwxrwxrwx 1 root root 15 Jan 19 02:58 /etc/alternatives/php -> /usr/bin/php7.2 lrwxrwxrwx 1 root root 19 Jan 19 03:00 /etc/alternatives/php-cgi -> /usr/bin/php-cgi7.2 lrwxrwxrwx 1 root root 23 Jan 19 03:00 /etc/alternatives/php-cgi-bin -> /usr/lib/cgi-bin/php7.2
- Mặc dù một mặt, mặt khác, có thể hữu ích khi có các liên kết nhất quán cho toàn bộ hệ thống, thực tế là một số phiên bản PHP tồn tại trên hệ thống ngụ ý rằng nó được sử dụng để phát triển và PHP cho
5,$ update-alternatives --list php /usr/bin/php7.0 /usr/bin/php7.2
6 và$ update-alternatives --list php /usr/bin/php7.0 /usr/bin/php7.2
7 có thể được cấu hình khác nhau. Symlink nào phải được thay đổi? PHP cho Web thường không được cấu hình bằng cách sử dụng các liên kết symlink trong$ update-alternatives --list php /usr/bin/php7.0 /usr/bin/php7.2
3 và ____ 25 [Lệnh] thường không sử dụng phiên bản CGI hoặc CGI. Vì vậy, có thể giả định rằng việc chỉ thay đổi symlink cho$ ls -al /etc/alternatives/php* lrwxrwxrwx 1 root root 15 Jan 19 02:58 /etc/alternatives/php -> /usr/bin/php7.2 lrwxrwxrwx 1 root root 31 Jan 19 02:58 /etc/alternatives/php.1.gz -> /usr/share/man/man1/php7.2.1.gz lrwxrwxrwx 1 root root 19 Jan 19 03:00 /etc/alternatives/php-cgi -> /usr/bin/php-cgi7.2 lrwxrwxrwx 1 root root 35 Jan 19 03:00 /etc/alternatives/php-cgi.1.gz -> /usr/share/man/man1/php-cgi7.2.1.gz lrwxrwxrwx 1 root root 23 Jan 19 03:00 /etc/alternatives/php-cgi-bin -> /usr/lib/cgi-bin/php7.2
8 sẽ hoạt động cho dòng lệnh, thay đổi$ ls -al /etc/alternatives/php* lrwxrwxrwx 1 root root 15 Jan 19 02:58 /etc/alternatives/php -> /usr/bin/php7.2 lrwxrwxrwx 1 root root 31 Jan 19 02:58 /etc/alternatives/php.1.gz -> /usr/share/man/man1/php7.2.1.gz lrwxrwxrwx 1 root root 19 Jan 19 03:00 /etc/alternatives/php-cgi -> /usr/bin/php-cgi7.2 lrwxrwxrwx 1 root root 35 Jan 19 03:00 /etc/alternatives/php-cgi.1.gz -> /usr/share/man/man1/php-cgi7.2.1.gz lrwxrwxrwx 1 root root 23 Jan 19 03:00 /etc/alternatives/php-cgi-bin -> /usr/lib/cgi-bin/php7.2
1 và$ update-alternatives --display php php - auto mode link best version is /usr/bin/php7.2 link currently points to /usr/bin/php7.2 link php is /usr/bin/php slave php.1.gz is /usr/share/man/man1/php.1.gz /usr/bin/php7.0 - priority 70 slave php.1.gz: /usr/share/man/man1/php7.0.1.gz /usr/bin/php7.2 - priority 72 slave php.1.gz: /usr/share/man/man1/php7.2.1.gz
2 có thể không bắt buộc. Thông thường phiên bản gần đây nhất được liên kết theo mặc định, vì vậy lệnh bên dưới đang sử dụng phiên bản cũ hơn được lấy từ danh sách trong$ update-alternatives --display php php - auto mode link best version is /usr/bin/php7.2 link currently points to /usr/bin/php7.2 link php is /usr/bin/php slave php.1.gz is /usr/share/man/man1/php.1.gz /usr/bin/php7.0 - priority 70 slave php.1.gz: /usr/share/man/man1/php7.0.1.gz /usr/bin/php7.2 - priority 72 slave php.1.gz: /usr/share/man/man1/php7.2.1.gz
0:$ update-alternatives --list php /usr/bin/php7.0 /usr/bin/php7.2
Which symlink has to be changed?
PHP for web is usually not configured by usage of the symlinks in
3 and$ ls -al /etc/alternatives/php* lrwxrwxrwx 1 root root 15 Jan 19 02:58 /etc/alternatives/php -> /usr/bin/php7.2 lrwxrwxrwx 1 root root 31 Jan 19 02:58 /etc/alternatives/php.1.gz -> /usr/share/man/man1/php7.2.1.gz lrwxrwxrwx 1 root root 19 Jan 19 03:00 /etc/alternatives/php-cgi -> /usr/bin/php-cgi7.2 lrwxrwxrwx 1 root root 35 Jan 19 03:00 /etc/alternatives/php-cgi.1.gz -> /usr/share/man/man1/php-cgi7.2.1.gz lrwxrwxrwx 1 root root 23 Jan 19 03:00 /etc/alternatives/php-cgi-bin -> /usr/lib/cgi-bin/php7.2
5[commandline] is usually not using the cgi-version or cgi-configuration. So it can be assumed that changing only the symlink for$ update-alternatives --list php /usr/bin/php7.0 /usr/bin/php7.2
8 will work for commandline, change of$ ls -al /etc/alternatives/php* lrwxrwxrwx 1 root root 15 Jan 19 02:58 /etc/alternatives/php -> /usr/bin/php7.2 lrwxrwxrwx 1 root root 31 Jan 19 02:58 /etc/alternatives/php.1.gz -> /usr/share/man/man1/php7.2.1.gz lrwxrwxrwx 1 root root 19 Jan 19 03:00 /etc/alternatives/php-cgi -> /usr/bin/php-cgi7.2 lrwxrwxrwx 1 root root 35 Jan 19 03:00 /etc/alternatives/php-cgi.1.gz -> /usr/share/man/man1/php-cgi7.2.1.gz lrwxrwxrwx 1 root root 23 Jan 19 03:00 /etc/alternatives/php-cgi-bin -> /usr/lib/cgi-bin/php7.2
1 and$ update-alternatives --display php php - auto mode link best version is /usr/bin/php7.2 link currently points to /usr/bin/php7.2 link php is /usr/bin/php slave php.1.gz is /usr/share/man/man1/php.1.gz /usr/bin/php7.0 - priority 70 slave php.1.gz: /usr/share/man/man1/php7.0.1.gz /usr/bin/php7.2 - priority 72 slave php.1.gz: /usr/share/man/man1/php7.2.1.gz
2 is probably not required. Usually the most recent version is linked by default, so the command below is using an older version taken from the list in$ update-alternatives --display php php - auto mode link best version is /usr/bin/php7.2 link currently points to /usr/bin/php7.2 link php is /usr/bin/php slave php.1.gz is /usr/share/man/man1/php.1.gz /usr/bin/php7.0 - priority 70 slave php.1.gz: /usr/share/man/man1/php7.0.1.gz /usr/bin/php7.2 - priority 72 slave php.1.gz: /usr/share/man/man1/php7.2.1.gz
0:$ update-alternatives --list php /usr/bin/php7.0 /usr/bin/php7.2
$ sudo update-alternatives --set php /usr/bin/php7.0 update-alternatives: using /usr/bin/php7.0 to provide /usr/bin/php [php] in manual mode
Điều khiển
Kiểm tra thay đổi:
0$ ls -al /etc/alternatives/php* lrwxrwxrwx 1 root root 15 Jan 19 02:58 /etc/alternatives/php -> /usr/bin/php7.2 lrwxrwxrwx 1 root root 31 Jan 19 02:58 /etc/alternatives/php.1.gz -> /usr/share/man/man1/php7.2.1.gz lrwxrwxrwx 1 root root 19 Jan 19 03:00 /etc/alternatives/php-cgi -> /usr/bin/php-cgi7.2 lrwxrwxrwx 1 root root 35 Jan 19 03:00 /etc/alternatives/php-cgi.1.gz -> /usr/share/man/man1/php-cgi7.2.1.gz lrwxrwxrwx 1 root root 23 Jan 19 03:00 /etc/alternatives/php-cgi-bin -> /usr/lib/cgi-bin/php7.2
Sự thay đổi đã được chấp nhận và phiên bản đã sử dụng là phiên bản cũ hơn bây giờ.
- Bây giờ chúng tôi kiểm tra phiên bản, trang người được viết cho:
1$ ls -al /etc/alternatives/php* lrwxrwxrwx 1 root root 15 Jan 19 02:58 /etc/alternatives/php -> /usr/bin/php7.2 lrwxrwxrwx 1 root root 31 Jan 19 02:58 /etc/alternatives/php.1.gz -> /usr/share/man/man1/php7.2.1.gz lrwxrwxrwx 1 root root 19 Jan 19 03:00 /etc/alternatives/php-cgi -> /usr/bin/php-cgi7.2 lrwxrwxrwx 1 root root 35 Jan 19 03:00 /etc/alternatives/php-cgi.1.gz -> /usr/share/man/man1/php-cgi7.2.1.gz lrwxrwxrwx 1 root root 23 Jan 19 03:00 /etc/alternatives/php-cgi-bin -> /usr/lib/cgi-bin/php7.2
Điều này có nghĩa là phiên bản PHP phù hợp với trang Man và lệnh
$ update-alternatives --display php
php - auto mode
link best version is /usr/bin/php7.2
link currently points to /usr/bin/php7.2
link php is /usr/bin/php
slave php.1.gz is /usr/share/man/man1/php.1.gz
/usr/bin/php7.0 - priority 70
slave php.1.gz: /usr/share/man/man1/php7.0.1.gz
/usr/bin/php7.2 - priority 72
slave php.1.gz: /usr/share/man/man1/php7.2.1.gz
4 trả về các mô tả đúng cho phiên bản PHP hiện tại và không cần điều chỉnh thủ công liên quan đến trang MAN.no manual adjustments concerning the man-page have been required.
Làm cách nào để cập nhật phiên bản PHP từ dòng lệnh?
Cập nhật PHP cho Windows Run PHP -V từ dòng lệnh để kiểm tra phiên bản PHP của bạn. Nếu bạn không muốn cập nhật PHP theo cách thủ công, bạn có thể sử dụng Trình quản lý gói sô cô la để cài đặt và cập nhật phiên bản PHP cho bạn. Sô cô la là một người quản lý gói cho máy tính Windows, nó hoạt động như homebrew cho máy tính MAC.Run php -v from the command line to check your PHP version. If you don't want to update PHP manually, you can use the Chocolatey package manager to install and update PHP version for you. Chocolatey is a package manager for Windows computers, it works like Homebrew for Mac computers.
Làm cách nào để thay đổi phiên bản PHP trong ubuntu?
Cuộn đến dòng cuối cùng và nhập mã sau:..
ChangePhversion [] {.
cục bộ is_php7 = `Php -version | grep" Php 7.2 "`.
nếu [[-z $ is_php7]]; sau đó..
Echo "Chuyển đổi ... vui lòng đợi".
sudo a2dismod PHP7. ....
sudo a2enmod PHP7. ....
Dịch vụ sudo APACHE2 Khởi động lại ..
Sudo Update-Alternative--SET PHP/USR/BIN/PHP7 ..
Phiên bản CLI của PHP là gì?
Giao diện dòng lệnh của PHP [CLI] cho phép bạn thực thi các tập lệnh PHP khi đăng nhập vào máy chủ của bạn thông qua SSH.ServerPilot cài đặt nhiều phiên bản PHP trên máy chủ của bạn để có nhiều tệp thực thi PHP có sẵn để chạy.Bạn cũng có thể định cấu hình phiên bản PHP được sử dụng khi bạn gọi chỉ là PHP lệnh.allows you to execute PHP scripts when logged in to your server through SSH. ServerPilot installs multiple versions of PHP on your server so there are multiple PHP executables available to run. You can also configure the PHP version used when you call just the command php.
Làm cách nào để cập nhật phiên bản PHP trên máy chủ Linux?
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ũ ..