果如 发表于 2025-4-19 10:42:01

Oneinstack开启WebP图片支持的方法

什么是WebP?Webp是Google于2010年发布的一种同时提供了有损压缩和无损压缩的图片文件格式,以BSD授权条款发布(意味着它是免费开放的图片格式),它的优点是同等画质下,体积比JPG、PNG少了25%以上。WebP还支持动画、ICC色彩配置、XMP诠释数据、Alpha透明通道。经过多年的发展,目前全球主流浏览器如Chrome、微软EDGE、Firefox、苹果Safari等都已经支持WebP图片格式。为什么用WebP?大家都知道在互联网上,一个页面往往有一张或多张图片,过去JPG和PNG是互联网上最常见的图片格式,改用WebP后在不降低图片质量的前提下大大减少图片的大小,对用户而言,最直观的体验就是大大提升了页面加载速度,对于互联网提供商而言,使用WebP除了提升了用户体验,还能大大减少磁盘和宽带的成本,正因如此,国内越来越多的大型互联网产品包括微信公众号、百度图片等已经改用WebP。OneinStack是一键PHP/JAVA安装脚本工具,是国内比较流行的Linux服务器安装和管理LNMP/LAMP的工具,本文介绍OneinStack开启WebP图片支持的方法。首先在浏览器访问服务器IP地址/phpinfo.php,找到gd,看有没有WebP Support enable,没有说明服务器不支持WebP,则需要卸载已经安装的PHP,修改PHP安装脚本重新编译安装PHP以启用对WebP的支持,下面介绍具体步骤,为了安全起见,操作前备份网站数据。Image
https://atuwe.com/sites/default/files/styles/wide/public/2023-01/oneinstack_webp_1.png.webp?itok=k8Bpup1v


1.SSH连接服务器,执行cd oneinstack,再执行 ./uninstall.sh 输入 5 回车 接着 y 回车 卸载已经安装的PHP。Image
https://atuwe.com/sites/default/files/styles/wide/public/2023-01/oneinstack_webp_3.png.webp?itok=a1tDe4LB


2.进入/root/oneinstack/include目录,找到要安装的PHP版本对应的文件打开,比如要安装PHP8.1.x则打开php-8.1.sh,在--with-zlib后面添加--with-webp(有两处):Image
https://atuwe.com/sites/default/files/styles/wide/public/2023-01/oneinstack_webp_5.png.webp?itok=xo9NbhfB


./configure --prefix=${php_install_dir} --with-config-file-path=${php_install_dir}/etc \    --with-config-file-scan-dir=${php_install_dir}/etc/php.d \    --with-apxs2=${apache_install_dir}/bin/apxs ${phpcache_arg} --disable-fileinfo \    --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \    --with-iconv=/usr/local --with-freetype --with-jpeg --with-zlib --with-webp \    --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-exif \    --enable-sysvsem ${php81_with_curl} --enable-mbregex \    --enable-mbstring --with-password-argon2 --with-sodium=/usr/local --enable-gd ${php81_with_openssl} \    --with-mhash --enable-pcntl --enable-sockets --enable-ftp --enable-intl --with-xsl \    --with-gettext --with-zip=/usr/local --enable-soap --disable-debug ${php_modules_options}else    ./configure --prefix=${php_install_dir} --with-config-file-path=${php_install_dir}/etc \    --with-config-file-scan-dir=${php_install_dir}/etc/php.d \    --with-fpm-user=${run_user} --with-fpm-group=${run_group} --enable-fpm ${phpcache_arg} --disable-fileinfo \    --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \    --with-iconv=/usr/local --with-freetype --with-jpeg --with-zlib --with-webp \    --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-exif \    --enable-sysvsem ${php81_with_curl} --enable-mbregex \    --enable-mbstring --with-password-argon2 --with-sodium=/usr/local --enable-gd ${php81_with_openssl} \    --with-mhash --enable-pcntl --enable-sockets --enable-ftp --enable-intl --with-xsl \    --with-gettext --with-zip=/usr/local --enable-soap --disable-debug ${php_modules_options}修改后如图:Image
https://atuwe.com/sites/default/files/styles/wide/public/2023-01/oneinstack_webp_6.png.webp?itok=xUIuW1Iw


3.进入/root/oneinstack/src目录,删除所有包含要安装PHP版本的文件夹和文件,如本教程要安装PHP8.1则删除php-8.1.12和php-8.1.12.tar.gz。Image
https://atuwe.com/sites/default/files/styles/wide/public/2023-01/oneinstack_webp_7.png.webp?itok=1ftzOBfz


Image
https://atuwe.com/sites/default/files/styles/wide/public/2023-01/oneinstack_webp_8.png.webp?itok=iZ3Cw6tA


4.执行cd ~/oneinstack 命令返回oneinstack目录,再执行./install.sh进入安装流程,除了Do you want to install PHP? : 输入y回车,然后输入要安装的PHP版本序号,其他的都输入n或0跳过,如下:Image
https://atuwe.com/sites/default/files/styles/wide/public/2023-01/oneinstack_webp_9.png.webp?itok=rwjg6Er1


Please input SSH port(Default: 22):回车
Do you want to install Web server? : n
Do you want to install Database? : n
Do you want to install PHP? : y
Please select a version of the PHP:
      1. Install php-5.3
      2. Install php-5.4
      3. Install php-5.5
      4. Install php-5.6
      5. Install php-7.0
      6. Install php-7.1
      7. Install php-7.2
      8. Install php-7.3
      9. Install php-7.4
       10. Install php-8.0
       11. Install php-8.1
       12. Install php-8.2
Please input a number:(Default 7 press Enter) 11
Do you want to install opcode cache of the PHP? : y
Please select a opcode cache of the PHP:
       1. Install Zend OPcache
       2. Install APCU
Please input a number:(Default 1 press Enter) 1
Please select PHP extensions:
      0. Do not install
      1. Install zendguardloader(PHP<=5.6)
      2. Install ioncube
      3. Install sourceguardian(PHP<=7.2)
      4. Install imagick
      5. Install gmagick
      6. Install fileinfo
      7. Install imap
      8. Install ldap
      9. Install phalcon(PHP>=5.5)
       10. Install yaf(PHP>=7.0)
       11. Install redis
       12. Install memcached
       13. Install memcache
       14. Install mongodb
       15. Install swoole
       16. Install xdebug(PHP>=5.5)
Please input numbers:(Default '4 11 12' press Enter) 0
Do you want to install Nodejs? : n
Do you want to install Pure-FTPd? : n
Do you want to install phpMyAdmin? : n
Do you want to install redis-server? :n如果安装PHP提示“No package 'libwebp' found ”如图:Image
https://atuwe.com/sites/default/files/styles/wide/public/2023-01/php_error_1.png.webp?itok=BbSJasu4


则根据《安装PHP提示 No package 'libWebP' found 的解决方法》安装好libwebp后重新执行 ./install.sh 按照上面的步骤操作。安装完PHP,再在浏览器访问 IP/phpinfo.php 找到gd可以看到已经有 WebP Support enable,说明已经启用对WebP图片格式的支持。Image
https://atuwe.com/sites/default/files/styles/wide/public/2023-01/oneinstack_webp_10.png.webp?itok=BpcG7txR


页: [1]
查看完整版本: Oneinstack开启WebP图片支持的方法