没有不值得去解决的问题,也没有不值得去学习的技术!

在 Windows 10 上使用 Ubuntu 执行 .sh 或 Shell 脚本文件

查看 Ubuntu 中 PHP 的版本信息,安装 PHP 的 Redis 扩展
1、参考:https://www.shuijingwanwq.com/2022/12/13/7282/ 。在 Windows 10 中使用 WSL 运行 .sh 或 Shell 脚本文件 。最终未实现。 2、参考:https://www.shuijingwanwq.com/2021/12/23/5559/ ,执行到第 7 步骤 3、打开 Windows Terminal 命令行,按照以下指示进入 Ubuntu 系统。如图1
打开 Windows Terminal 命令行,按照以下指示进入 Ubuntu 系统
图1
4、Ubuntu 将在 /mnt 下挂载或提供所有 Windows 目录。 因此 C 盘位于 /mnt/c。现有 themes.sh 文件,其代码如下


#!/bin/sh

for i in $(seq 1 200);
do
    echo "Install theme $i times"
    php artisan theme-store-db:theme:install /mnt/e/Users/Lenovo/Downloads/theme "theme$i" blade --force
done


5、执行命令:sh themes.sh,报错: LogicException : Please make sure the PHP Redis extension is installed and enabled.。如图2
执行命令:sh themes.sh,报错: LogicException  : Please make sure the PHP Redis extension is installed and enabled.
图2


wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/object$ sh themes.sh
Install theme 1 times

   LogicException  : Please make sure the PHP Redis extension is installed and enabled.

  at /mnt/e/wwwroot/object/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php:77
    73|     protected function createClient(array $config)
    74|     {
    75|         return tap(new Redis, function ($client) use ($config) {
    76|             if ($client instanceof RedisFacade) {
  > 77|                 throw new LogicException(
    78|                         extension_loaded('redis')
    79|                                 ? 'Please remove or rename the Redis facade alias in your "app" configuration file in order to avoid collision with the PHP Redis extension.'
    80|                                 : 'Please make sure the PHP Redis extension is installed and enabled.'
    81|                 );

  Exception trace:

  1   Illuminate\Redis\Connectors\PhpRedisConnector::Illuminate\Redis\Connectors\{closure}()
      /mnt/e/wwwroot/object/vendor/laravel/framework/src/Illuminate/Support/helpers.php:422

  2   tap()
      /mnt/e/wwwroot/object/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php:105

  Please use the argument -v to see more details.
Install theme 2 times
^C
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/object$


6、查看 Ubuntu 中 PHP 的版本信息,安装 PHP 的 Redis 扩展。如图3
查看 Ubuntu 中 PHP 的版本信息,安装 PHP 的 Redis 扩展
图3


wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/object$ php -v
PHP 7.4.3 (cli) (built: Nov 25 2021 23:16:22) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/object$ apt-get install php-redis
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/object$ sudo apt-get install php-redis
[sudo] password for wangqiang:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  php-igbinary
Suggested packages:
  redis-server
The following NEW packages will be installed:
  php-igbinary php-redis
0 upgraded, 2 newly installed, 0 to remove and 93 not upgraded.
Need to get 224 kB of archives.
After this operation, 941 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://archive.ubuntu.com/ubuntu focal/universe amd64 php-igbinary amd64 3.1.2+2.0.8-1build1 [87.5 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal/universe amd64 php-redis amd64 5.1.1+4.3.0-1 [137 kB]
Fetched 224 kB in 3s (72.7 kB/s)
Selecting previously unselected package php-igbinary.
(Reading database ... 32358 files and directories currently installed.)
Preparing to unpack .../php-igbinary_3.1.2+2.0.8-1build1_amd64.deb ...
Unpacking php-igbinary (3.1.2+2.0.8-1build1) ...
Selecting previously unselected package php-redis.
Preparing to unpack .../php-redis_5.1.1+4.3.0-1_amd64.deb ...
Unpacking php-redis (5.1.1+4.3.0-1) ...
Setting up php-igbinary (3.1.2+2.0.8-1build1) ...
Setting up php-redis (5.1.1+4.3.0-1) ...
Processing triggers for php7.4-cli (7.4.3-4ubuntu2.8) ...


7、再次执行命令:sh themes.sh,报错:RedisException : Connection refused。由此得出结论,.sh 脚本的执行所依赖的环境配置必须在 Ubuntu 中全部准备妥当才行。所连接的 Redis 已经不再是 Windows 中的 Redis。

Linux 服务器运维、部署与线上故障排查

如果你的网站或后端服务部署在 Linux 服务器上,遇到访问异常、Nginx 配置问题、MySQL / Redis 异常、Docker 服务不可用、磁盘占满、CPU / 内存过高等问题,可以联系我做一次远程排查。

适合以下场景:
✅ 网站打不开或访问不稳定
✅ Nginx / PHP-FPM 配置异常
✅ MySQL / Redis 性能或连接问题
✅ Docker 服务部署与维护
✅ 服务器迁移与环境配置
✅ CPU / 内存 / 磁盘异常排查

服务内容:
✅ Linux 环境检查
✅ 网站部署与迁移
✅ Nginx / PHP-FPM / MySQL / Redis 排查
✅ Docker 配置与维护
✅ 服务器性能分析
✅ 长期远程运维支持

如需咨询,请联系我,并注明:Linux 运维咨询

联系方式:
Telegram:@shuijingwan
微信:13980074657
邮箱:shuijingwanwq@gmail.com

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理