0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[小ネタ]AmazonLinux2 PHP8にphpredisを入れる

Posted at

#PHP8 on AmazonLinux2 一発でphp-redisが入らない(2021/08/1現在)ので調べてみた。

##前提として
amazon-linux-extrasでPHP8をインストール済み
Nginx + PHP-FPM + Laravel

peclでインストールするらしいので、Pearをインストール
sudo yum install php-pear

peclでインストール
sudo pecl install redis

ビルドエラーが起きるので、php-develとgccをインストール
sudo yum install gcc
sudo yum install php-devel

php.iniに追加
echo "extension=redis.so" > /etc/php.d/redis.ini

php-fpmを再起動
systemctl restart php-fpm

Laravelの場合
.envに追加

SESSION_DRIVER=redis
SESSION_LIFETIME=120
MEMCACHED_HOST=ygd-dev.u2ark4.ng.0001.apne1.cache.amazonaws.com
REDIS_HOST=ygd-dev.u2ark4.ng.0001.apne1.cache.amazonaws.com
REDIS_PASSWORD=null
REDIS_PORT=6379

とりあえず、setとgetするだけサンプル

use Illuminate\Support\Facades\Redis;
Redis::set('name', 'Taylor:'.date('Y-m-d H:i:s'));
echo "Name = ".Redis::get('name')."\n";
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?