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

Run .sh or Shell Scripts on Windows 10 With Ubuntu

Check the PHP version information in Ubuntu and install the PHP Redis extension

1. Reference: Running .sh or Shell script files using WSL in Windows 10 . Ultimately unsuccessful.

2. Reference: Executed up to step 7

3. Open the Windows Terminal command line and enter the Ubuntu system following the instructions below. See Figure 1.

Open the Windows Terminal command line and enter the Ubuntu system following the instructions below
Figure 1

4. Ubuntu will mount or provide all Windows directories under /mnt. Therefore, the C drive is located at /mnt/c. There is an existing themes.sh file, with the following code:

ShellScript

#!/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. Execute the command: sh themes.sh. Error reported: LogicException : Please make sure the PHP Redis extension is installed and enabled. See Figure 2.

Execute the command: sh themes.sh. Error reported: LogicException : Please make sure the PHP Redis extension is installed and enabled.
Figure 2
Plaintext

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. Check the PHP version information in Ubuntu and install the PHP Redis extension. See Figure 3.

Check the PHP version information in Ubuntu and install the PHP Redis extension
Figure 3
Plaintext

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. Execute the command again: sh themes.sh. Error reported: RedisException : Connection refused. From this, it can be concluded that the environment configuration required for executing the .sh script must be fully prepared within Ubuntu. The Redis being connected to is no longer the Redis in Windows.

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系