[教程][笔记]Centos7宝塔下安装ImageMagick,无法安装webp扩展解决办法

前言

在安装Lsky Pro 图床的时候,发现web文件上传异常,报错代码如下

[2023-11-27 23:26:22] prod.ERROR: Web 上传文件时发生异常 {"file":"/www/wwwroot/img.***.cc/vendor/intervention/image/src/Intervention/Image/Imagick/Decoder.php","line":29,"message":"Unable to read image from path (/tmp/phpt7XawF).","trace":"#0 /www/wwwroot/img.***.cc/vendor/intervention/image/src/Intervention/Image/AbstractDecoder.php(329): Intervention\Image\Imagick\Decoder->initFromPath()
#1 /www/wwwroot/img.***.cc/vendor/intervention/image/src/Intervention/Image/AbstractDriver.php(66): Intervention\Image\AbstractDecoder->init()
#2 /www/wwwroot/img.***.cc/vendor/intervention/image/src/Intervention/Image/ImageManager.php(54): Intervention\Image\AbstractDriver->init()
#3 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(338): Intervention\Image\ImageManager->make()
#4 /www/wwwroot/img.***.cc/app/Services/ImageService.php(230): Illuminate\Support\Facades\Facade::__callStatic()
#5 /www/wwwroot/img.***.cc/app/Services/ImageService.php(240): App\Services\ImageService->App\Services\{closure}()
#6 /www/wwwroot/img.***.cc/app/Http/Controllers/IndexController.php(132): App\Services\ImageService->store()
#7 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): App\Http\Controllers\IndexController->upload()
#8 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(43): Illuminate\Routing\Controller->callAction()
#9 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Routing/Route.php(260): Illuminate\Routing\ControllerDispatcher->dispatch()
#10 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Routing/Route.php(205): Illuminate\Routing\Route->runController()
#11 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Routing/Router.php(798): Illuminate\Routing\Route->run()
#12 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#13 /www/wwwroot/img.***.cc/app/Http/Middleware/CheckIsInstalled.php(24): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#14 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): App\Http\Middleware\CheckIsInstalled->handle()
#15 /www/wwwroot/img.***.cc/app/Http/Middleware/SetViewVariables.php(172): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#16 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): App\Http\Middleware\SetViewVariables->handle()
#17 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#18 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Routing\Middleware\SubstituteBindings->handle()
#19 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(78): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#20 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle()
#21 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#22 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\View\Middleware\ShareErrorsFromSession->handle()
#23 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#24 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Session\Middleware\StartSession->handleStatefulRequest()
#25 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Session\Middleware\StartSession->handle()
#26 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#27 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle()
#28 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#29 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Cookie\Middleware\EncryptCookies->handle()
#30 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#31 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Routing/Router.php(799): Illuminate\Pipeline\Pipeline->then()
#32 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Routing/Router.php(776): Illuminate\Routing\Router->runRouteWithinStack()
#33 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Routing/Router.php(740): Illuminate\Routing\Router->runRoute()
#34 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Routing/Router.php(729): Illuminate\Routing\Router->dispatchToRoute()
#35 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(190): Illuminate\Routing\Router->dispatch()
#36 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}()
#37 /www/wwwroot/img.***.cc/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(59): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#38 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Barryvdh\Debugbar\Middleware\InjectDebugbar->handle()
#39 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#40 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#41 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull->handle()
#42 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#43 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#44 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\TrimStrings->handle()
#45 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#46 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle()
#47 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#48 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle()
#49 /www/wwwroot/img.***.cc/vendor/fruitcake/laravel-cors/src/HandleCors.php(38): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#50 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Fruitcake\Cors\HandleCors->handle()
#51 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(39): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#52 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Http\Middleware\TrustProxies->handle()
#53 /www/wwwroot/img.***.cc/app/Http/Middleware/TrustIp.php(26): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#54 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): App\Http\Middleware\TrustIp->handle()
#55 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#56 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(165): Illuminate\Pipeline\Pipeline->then()
#57 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(134): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter()
#58 /www/wwwroot/img.***.cc/public/index.php(52): Illuminate\Foundation\Http\Kernel->handle()
#59 {main}"} 
[2023-11-27 23:27:14] prod.ERROR: Web 上传文件时发生异常 {"file":"/www/wwwroot/img.***.cc/vendor/intervention/image/src/Intervention/Image/Imagick/Decoder.php","line":29,"message":"Unable to read image from path (/tmp/phprII5Mi).","trace":"#0 /www/wwwroot/img.***.cc/vendor/intervention/image/src/Intervention/Image/AbstractDecoder.php(329): Intervention\Image\Imagick\Decoder->initFromPath()
#1 /www/wwwroot/img.***.cc/vendor/intervention/image/src/Intervention/Image/AbstractDriver.php(66): Intervention\Image\AbstractDecoder->init()
#2 /www/wwwroot/img.***.cc/vendor/intervention/image/src/Intervention/Image/ImageManager.php(54): Intervention\Image\AbstractDriver->init()
#3 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(338): Intervention\Image\ImageManager->make()
#4 /www/wwwroot/img.***.cc/app/Services/ImageService.php(230): Illuminate\Support\Facades\Facade::__callStatic()
#5 /www/wwwroot/img.***.cc/app/Services/ImageService.php(240): App\Services\ImageService->App\Services\{closure}()
#6 /www/wwwroot/img.***.cc/app/Http/Controllers/IndexController.php(132): App\Services\ImageService->store()
#7 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): App\Http\Controllers\IndexController->upload()
#8 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(43): Illuminate\Routing\Controller->callAction()
#9 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Routing/Route.php(260): Illuminate\Routing\ControllerDispatcher->dispatch()
#10 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Routing/Route.php(205): Illuminate\Routing\Route->runController()
#11 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Routing/Router.php(798): Illuminate\Routing\Route->run()
#12 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#13 /www/wwwroot/img.***.cc/app/Http/Middleware/CheckIsInstalled.php(24): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#14 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): App\Http\Middleware\CheckIsInstalled->handle()
#15 /www/wwwroot/img.***.cc/app/Http/Middleware/SetViewVariables.php(172): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#16 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): App\Http\Middleware\SetViewVariables->handle()
#17 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#18 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Routing\Middleware\SubstituteBindings->handle()
#19 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(78): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#20 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle()
#21 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#22 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\View\Middleware\ShareErrorsFromSession->handle()
#23 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#24 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Session\Middleware\StartSession->handleStatefulRequest()
#25 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Session\Middleware\StartSession->handle()
#26 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#27 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle()
#28 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#29 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Cookie\Middleware\EncryptCookies->handle()
#30 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#31 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Routing/Router.php(799): Illuminate\Pipeline\Pipeline->then()
#32 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Routing/Router.php(776): Illuminate\Routing\Router->runRouteWithinStack()
#33 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Routing/Router.php(740): Illuminate\Routing\Router->runRoute()
#34 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Routing/Router.php(729): Illuminate\Routing\Router->dispatchToRoute()
#35 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(190): Illuminate\Routing\Router->dispatch()
#36 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}()
#37 /www/wwwroot/img.***.cc/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(59): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#38 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Barryvdh\Debugbar\Middleware\InjectDebugbar->handle()
#39 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#40 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#41 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull->handle()
#42 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#43 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#44 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\TrimStrings->handle()
#45 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#46 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle()
#47 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#48 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle()
#49 /www/wwwroot/img.***.cc/vendor/fruitcake/laravel-cors/src/HandleCors.php(38): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#50 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Fruitcake\Cors\HandleCors->handle()
#51 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(39): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#52 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Http\Middleware\TrustProxies->handle()
#53 /www/wwwroot/img.***.cc/app/Http/Middleware/TrustIp.php(26): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#54 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): App\Http\Middleware\TrustIp->handle()
#55 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#56 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(165): Illuminate\Pipeline\Pipeline->then()
#57 /www/wwwroot/img.***.cc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(134): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter()
#58 /www/wwwroot/img.***.cc/public/index.php(52): Illuminate\Foundation\Http\Kernel->handle()
#59 {main}"}

在和群友询问后发现是 ImageMagick webp模块没有安装,导致这种报错,php info关于imagick里面是没有webp选项的

[教程][笔记]Centos7宝塔下安装ImageMagick,无法安装webp扩展解决办法-小绵羊的小窝

然后进行手动编译,发现webp模块依旧无法安装,会提示

WEBP --with-webp=yes no

然后在编译完成后,检查也是没有webp模块的

在深度了解后,发现造成这种问题的情况如下

  • Centos7系统的官方rpm包里面的libwep模块太老了,无法使用,不符合ImageMagick编译webp模块的要求
  • 宝塔面板太垃圾了
  • gcc编译器太老了(但是不是硬性要求)

解决方法

然后针对这种的情况,我们一步一步开始解决

  1. 先卸载干净服务器里面的 ImageMagick 和libwebp等,保证环境干净
    yum remove libwebp
    rm -rf /usr/local/imagemagick

    然后到

    /www/server/php/81/lib/php/extensions/no-debug-non-zts-******/

    确保里面没有imagick.so这个文件,宝塔面板里面的 ImageMagick 已经卸载了

  2. 然后开始安装libwep,官方版本已经到了1.3.2,而Centos7的官方库提供的还是0.3.0的版本,这会导致编译的时候,无法通过检测,因为ImageMagick的最低要求是大等于0.4.1,根据官方教程
    wget https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.3.2.tar.gz
    tar xvzf libwebp-1.3.2.tar.gz
    cd libwebp-1.3.2
    ./configure
    make
    make install

    这个时候就完成了libwebp的安装,接下来要 LD_LIBRARY_PATH 环境变量

    export LD_LIBRARY_PATH=/path/to/directory:$LD_LIBRARY_PATH

    /path/to/directory替换为libwebp的路径,大部分情况是在 /usr/local/include/webp

    然后还需要再定义头文件

    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
    echo $LD_LIBRARY_PATH
    echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib" >> ~/.bashrc
    echo 'export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH' >> ~/.bashrc
    source ~/.bashrc

    这个时候,输入cwebp -version,查看是否有输出,输出结果应该为:

    [root@LittlesheepUAU imagick-3.7.0]# cwebp -version
    1.3.2
    libsharpyuv: 0.2.1
    [root@LittlesheepUAU imagick-3.7.0]#

    为libwebp的最高版本,可能后面更新,里面的数值会不一样

  3. 接下来到了重头戏,安装 ImageMagick 和webp扩展,首先先安装pkg-config
    wget  https://pkg-config.freedesktop.org/releases/pkg-config-0.29.tar.gz
    tar -zxvf pkg-config-0.29.tar.gz
    cd pkg-config-0.29
    ./configure --with-internal-glib
    make
    make check
    make install

    再安装ImageMagick

    wget https://www.imagemagick.org/download/ImageMagick.tar.gz
    tar -zxvf ImageMagick.tar.gz
    cd ImageMagick-7.*.*-**

    请看清楚下载的ImageMagick的版本是什么,然后解压文件夹名字是什么,然后替换ImageMagick-7.*.*-**

    ./configure --with-webp
    make && make install

    然后查看webp是否安装成功

    convert -list format

    [教程][笔记]Centos7宝塔下安装ImageMagick,无法安装webp扩展解决办法-小绵羊的小窝

    在输出里面会有一个WEBP,这就代表安装好了

    然后尝试使用看功能是否正常

    convert test.jpg test.webp

    能正常输出且图片正常就是成功了

  4. 接下来安装PHP扩展
    wget https://pecl.php.net/get/imagick-3.7.0.tgz
    tar xvf imagick-3.7.0
    cd imagick-3.7.0
    phpize
    ./configure
    make && make install

    可能运行到./configure会报错,提示添加php路径,命令改成

    ./configure --with-php-config=/www/server/php/81/bin/php-config

    就可以正常输出了,最后在php.ini(宝塔的配置文件)里面,在最下面添加

    extension = /www/server/php/81/lib/php/extensions/no-debug-non-zts-*********/imagick.so

    请对应好对应文件夹名字即可,最后再运行

    yum -y install libwebp-devel libwebp-tools

     

  5. 最后再重启一下php服务,到php info找到imagick,里面就能看到webp模块了
  6. [教程][笔记]Centos7宝塔下安装ImageMagick,无法安装webp扩展解决办法-小绵羊的小窝

    还有版本信息等,然后开始安装测试webp在Lsky Pro上能不能使用

    [教程][笔记]Centos7宝塔下安装ImageMagick,无法安装webp扩展解决办法-小绵羊的小窝

    也是可以上传成功的,到这里教程就结束了

 

因为已经是安装完才写的教程,所以部分地方可能会有问题,请直接评论区留言,我会直接回答怎么解决

 

引用

https://www.jianshu.com/p/b14c89b57493

https://www.xiapilu.com/web/web-tutorial/bt-imagemagick-webp.html

https://github.com/ImageMagick/ImageMagick/discussions/6897

 

温馨提示: 本文最后更新于2023-11-30 12:38:38,某些文章具有时效性,若有错误或已失效,请在下方 留言或联系 小绵羊的小窝
© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容