Laravel Homestead 安装 Redis 扩展

看了一下 Homestead 里面没有Redis 扩展,所以直接照着 Homestead 目录下的 script/install-mongo.sh 写了个安装redis 的shell,内容如下:


#!/usr/bin/env bash
export DEBIAN_FRONTEND=noninteractive

cd /home/vagrant

if [ ! -d "redis-4.1.1.tgz"]; then
wget https://pecl.php.net/get/redis-4.1.1.tgz
tar -zxf redis-4.1.1.tgz
fi

cd redis-4.1.1

sudo DEBIAN_FRONTEND=noninteractive apt-get -y install php5.6-dev
phpize5.6 
./configure --with-php-config=/usr/bin/php-config5.6 > /dev/null
make clean > /dev/null
make >/dev/null 2>&1
sudo make install
sudo chmod 644 /usr/lib/php/20131226/redis.so
sudo bash -c "echo 'extension=redis.so' > /etc/php/5.6/mods-available/redis.ini"
sudo rm -rf /etc/php/5.6/cli/conf.d/20-redis.ini /etc/php/5.6/fpm/conf.d/20-redis.ini
sudo ln -s /etc/php/5.6/mods-available/redis.ini /etc/php/5.6/cli/conf.d/20-redis.ini
sudo ln -s /etc/php/5.6/mods-available/redis.ini /etc/php/5.6/fpm/conf.d/20-redis.ini
sudo service php5.6-fpm restart

sudo DEBIAN_FRONTEND=noninteractive apt-get -y install php7.0-dev
phpize7.0
./configure --with-php-config=/usr/bin/php-config7.0 > /dev/null
make clean > /dev/null
make >/dev/null 2>&1
sudo make install
sudo chmod 644 /usr/lib/php/20151012/redis.so
sudo bash -c "echo 'extension=redis.so' > /etc/php/7.0/mods-available/redis.ini"
sudo rm -rf /etc/php/7.0/cli/conf.d/20-redis.ini /etc/php/7.0/fpm/conf.d/20-redis.ini
sudo ln -s /etc/php/7.0/mods-available/redis.ini /etc/php/7.0/cli/conf.d/20-redis.ini
sudo ln -s /etc/php/7.0/mods-available/redis.ini /etc/php/7.0/fpm/conf.d/20-redis.ini
sudo service php7.0-fpm restart

sudo DEBIAN_FRONTEND=noninteractive apt-get -y install php7.1-dev
phpize7.1
./configure --with-php-config=/usr/bin/php-config7.1 > /dev/null
make clean > /dev/null
make >/dev/null 2>&1
sudo make install
sudo chmod 644 /usr/lib/php/20160303/redis.so
sudo bash -c "echo 'extension=redis.so' > /etc/php/7.1/mods-available/redis.ini"
sudo rm -rf /etc/php/7.1/cli/conf.d/20-redis.ini /etc/php/7.1/fpm/conf.d/20-redis.ini
sudo ln -s /etc/php/7.1/mods-available/redis.ini /etc/php/7.1/cli/conf.d/20-redis.ini
sudo ln -s /etc/php/7.1/mods-available/redis.ini /etc/php/7.1/fpm/conf.d/20-redis.ini
sudo service php7.1-fpm restart

phpize7.2
./configure --with-php-config=/usr/bin/php-config7.2 > /dev/null
make clean > /dev/null
make >/dev/null 2>&1
sudo make install
sudo chmod 644 /usr/lib/php/20160303/redis.so
sudo bash -c "echo 'extension=redis.so' > /etc/php/7.2/mods-available/redis.ini"
sudo rm -rf /etc/php/7.2/cli/conf.d/20-redis.ini /etc/php/7.2/fpm/conf.d/20-redis.ini
sudo ln -s /etc/php/7.2/mods-available/redis.ini /etc/php/7.2/cli/conf.d/20-redis.ini
sudo ln -s /etc/php/7.2/mods-available/redis.ini /etc/php/7.2/fpm/conf.d/20-redis.ini
sudo service php7.2-fpm restart

phpize7.3
./configure --with-php-config=/usr/bin/php-config7.3 > /dev/null
make clean > /dev/null
make >/dev/null 2>&1
sudo make install
sudo chmod 644 /usr/lib/php/20160303/redis.so
sudo bash -c "echo 'extension=redis.so' > /etc/php/7.3/mods-available/redis.ini"
sudo rm -rf /etc/php/7.3/cli/conf.d/20-redis.ini /etc/php/7.3/fpm/conf.d/20-redis.ini
sudo ln -s /etc/php/7.3/mods-available/redis.ini /etc/php/7.3/cli/conf.d/20-redis.ini
sudo ln -s /etc/php/7.3/mods-available/redis.ini /etc/php/7.3/fpm/conf.d/20-redis.ini
sudo service php7.3-fpm restart
  • 复制 shell 保存到 /vagrant/home/ 目录 比方说命名为 redis_install.sh
  • 给予执行权限 sudo chmod +x redis_install.sh
  • 执行 ./redis_install.sh
  • php[版本] -m | grep redis 验证

amorZhu has written 2 articles

该作者很低调,还没有自我介绍~

积分:337 等级:P4 职业:未设置 城市:未设置

1 条回复

  1. amorZhu amorZhu says:

    如果想在本地链接 Homestead 的redis ,请修改redis 配置文件的 bind 属性,

    sudo vim /etc/redis/redis.conf
    bind xxx.xxx.xxx.xxx   # 本地的homestead   ip  地址

登录后才能进行评论,立即登录?