在Ubuntu 20.04 | 18.04上安裝PHP mcrypt擴展

這是續集。
您可以通過以下鏈接以PDF格式下載本文,以為我們提供支持。

以PDF格式下載指南


這是續集。

這是續集。
這是續集。

我該如何解決E:軟件包“ php-mcrypt”沒有候選安裝Ubuntu 20.04 / 18.04?今天的指南是關於在Ubuntu 20.04 / 18.04上安裝PHP mcrypt擴展。 PHP mcrypt擴展是mcrypt加密庫的接口,並支持各種塊算法,例如DES,TripleDES,Blowfish(默認),3-WAY,SAFER-SK64,SAFER-SK128,TWOFISH,TEA和RC2。在做。 CBC,OFB,CFB,ECB密碼模式的GOST。

當我嘗試使用apt安裝mcrypt時,出現錯誤。

$ sudo apt install php-mcrypt
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package php-mcrypt is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'php-mcrypt' has no installation candidate

mcrypt擴展已移至PECL存儲庫,自PHP 7.2.0起不再與PHP捆綁在一起。 PECL是所有已知PHP擴展的存儲庫,您可以下載並託管自己的PHP擴展。

告訴操作系統獲取存儲庫中可用於安裝的軟件包的最新列表。

sudo apt update

在Ubuntu上安裝開發工具。

sudo apt update
sudo apt install -y build-essential

檢查品牌和gcc。

$ gcc --version
gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ make --version
GNU Make 4.2.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

首先,您需要在Ubuntu 20.04 | 18.04上安裝PHP,dev和pear擴展。

sudo apt install php php-pear php-dev libmcrypt-dev

驗證pecl命令在系統上可用。

$ which pecl 
/usr/bin/pecl

PECL的用法:

$ pecl help
Commands:
build                  Build an Extension From C Source
bundle                 Unpacks a Pecl Package
channel-add            Add a Channel
channel-alias          Specify an alias to a channel name
channel-delete         Remove a Channel From the List
channel-discover       Initialize a Channel from its server
channel-info           Retrieve Information on a Channel
channel-login          Connects and authenticates to remote channel server
channel-logout         Logs out from the remote channel server
channel-update         Update an Existing Channel
clear-cache            Clear Web Services Cache
config-create          Create a Default configuration file
config-get             Show One Setting
config-help            Show Information About Setting
config-set             Change Setting
config-show            Show All Settings
convert                Convert a package.xml 1.0 to package.xml 2.0 format
cvsdiff                Run a "cvs diff" for all files in a package
cvstag                 Set CVS Release Tag
download               Download Package
download-all           Downloads each available package from the default channel
info                   Display information about a package
install                Install Package
list                   List Installed Packages In The Default Channel
list-all               List All Packages
list-channels          List Available Channels
list-files             List Files In Installed Package
list-upgrades          List Available Upgrades
login                  Connects and authenticates to remote server [Deprecated in favor of channel-login]
logout                 Logs out from the remote server [Deprecated in favor of channel-logout]
makerpm                Builds an RPM spec file from a PEAR package
package                Build Package
package-dependencies   Show package dependencies
package-validate       Validate Package Consistency
pickle                 Build PECL Package
remote-info            Information About Remote Packages
remote-list            List Remote Packages
run-scripts            Run Post-Install Scripts bundled with a package
run-tests              Run Regression Tests
search                 Search remote package database
shell-test             Shell Script Test
sign                   Sign a package distribution file
svntag                 Set SVN Release Tag
uninstall              Un-install Package
update-channels        Update the Channel List
upgrade                Upgrade Package
upgrade-all            Upgrade All Packages [Deprecated in favor of calling upgrade with no parameters]
Usage: pecl [options] command [command-options] 
Type "pecl help options" to list all options.
Type "pecl help shortcuts" to list all command shortcuts.
Type "pecl help version" or "pecl version" to list version information.
Type "pecl help " to get the help for the specified command.

更新頻道:

$ sudo pecl channel-update pecl.php.net
Updating channel "pecl.php.net"
Update of Channel "pecl.php.net" succeeded

$ sudo pecl update-channels
Updating channel "doc.php.net"
Update of Channel "doc.php.net" succeeded
Updating channel "pear.php.net"
Update of Channel "pear.php.net" succeeded
Updating channel "pecl.php.net"
Channel "pecl.php.net" is up to date

讓我們搜索mcrypt擴展。

$ sudo pecl search mcrypt
Matched packages, channel pecl.php.net:
=======================================
Package       Stable/(Latest) Local
mcrypt        1.0.3 (stable)        Bindings for the libmcrypt library
mcrypt_filter 0.1.0 (beta)          Applies mcrypt symmetric encryption using stream filters

您可以使用帶有安裝選項的pecl命令安裝mcrypt擴展。

$ sudo pecl install mcrypt
downloading mcrypt-1.0.3.tgz ...
Starting to download mcrypt-1.0.3.tgz (33,590 bytes)
.........done: 33,590 bytes
6 source files, building
running: phpize
Configuring for:
PHP Api Version:         20190902
Zend Module Api No:      20190902
Zend Extension Api No:   320190902
........

提示時

libmcrypt prefix? [autodetect] :

輸入 自動檢測。

如果在Ubuntu 20.04 Linux機器上完全安裝了mcrypt擴展,則將獲得類似於以下內容的輸出:

Build process completed successfully
Installing '/usr/lib/php/20190902/mcrypt.so'
install ok: channel://pecl.php.net/mcrypt-1.0.3
configuration option "php_ini" is not set to php.ini location
You should add "extension=mcrypt.so" to php.ini

在您的php.ini文件中啟用擴展名。

Ubuntu 20.04:

$ sudo vim /etc/php/7.4/cli/php.ini
extension=mcrypt.so

$ sudo vim /etc/php/7.4/apache2/php.ini
extension=mcrypt.so

Ubuntu 18.04:

$ sudo vim /etc/php/7.2/cli/php.ini
extension=mcrypt.so

$ sudo vim /etc/php/7.2/apache2/php.ini
extension=mcrypt.so

您可以使用以下命令來驗證模塊是否已安裝並啟用。

$ php -m | grep mcrypt
mcrypt

如果您正在使用Apache或Nginx Web服務器上託管的應用程序,請重新啟動它們。

--- Restart Apache web server ---
$ sudo systemctl restart apache2

--- Restart nginx web server ---
$ sudo systemctl restart nginx

這是在Ubuntu 20.4和Ubuntu 18.04 Linux系統上安裝mcrypt PHP擴展的簡單方法。

PHP學習課程:


完整的Web開發人員課程2.0

★★★★★
(60896)

$ 16.80

$ 223.99

有現貨

立即購買

在Ubuntu 20.04 | 18.04上安裝PHP mcrypt擴展Udemy.com

這是續集。
這是續集。

這是續集。
您可以通過以下鏈接以PDF格式下載本文,以為我們提供支持。

以PDF格式下載指南


這是續集。

這是續集。
這是續集。

Sidebar