On upgrading to Laravel 6 we ran into issues locally running predis. This as no client was set in .env and now config was going for native PHP Redis or phpredis.
'redis' => [ 'client' => env('REDIS_CLIENT', 'phpredis'), 'options' => [ 'cluster' => env('REDIS_CLUSTER', 'redis'), 'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'), ],
Local Fix
To fix this locally and keep on using Homebrew we added a simple line to our local .env to keep on using predis and Homebrew based Predis instead of PHP Redis:
REDIS_CLIENT=predis
Forge Servers
Updating our Forge provisioned servers we ran into the same issue. Though I do believe newly provisioned servers do have PHP Redis installed. Our servers hadn’t had this pleasure. So doing a dep deploy staging we hit:
The command "cd /home/forge/staging.domain.com/releases/327 && php artisan queue:restart" failed. Exit Code: 1 (General error) Host Name: staging ================ In PhpRedisConnector.php line 76: Please make sure the PHP Redis extension is installed and enabled.
So predis was no longer used and PHP Redis could not be found.
PHP Redis Forge Recipe
I Googled some and found this tweet https://twitter.com/laravelphp/status/1181248181235044352?lang=en . Looking for recipes I found https://github.com/irazasyed/awesome-laravel-forge-recipes/blob/master/recipes/install-phpredis.sh which would do the trick as long as we tweaked it some and used the proper PHP verison.
Our current version is:
php --version PHP 7.3.7-2+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Jul 25 2019 11:44:59) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.7, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.7-2+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
Another recipe by Monooso: https://github.com/monooso/forge-recipe-php-redis/blob/master/recipe.sh seemed shorter. Probably due to use of pecl. And it uses the PHP command line tool to detect the PHP version:
# Install the Redis extension from PECL
sudo pecl install redis
# Figure out the PHP MAJOR.MINOR version
php_version=php -r "echo PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION;"
# Register and enable the PHP extension
echo 'extension=redis.so' | sudo tee "/etc/php/${php_version}/mods-available/redis.ini"
sudo phpenmod redis
# Restart PHP-FPM and nginx, just to be on the safe side
sudo service "php${php_version}-fpm" restart
sudo service nginx restart
running it as root I did run into an error
cat: /root/.forge/provision-823163.output: No such file or directory Close
But in the email report most other things did run well:
Server: app-staging (xxx.xxx.xxx.xx) WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update downloading redis-5.1.1.tgz … Starting to download redis-5.1.1.tgz (245,205 bytes) ……………………………………………done: 245,205 bytes Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in PEAR/PackageFile/v2/Validator.php on line 1933 PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /usr/share/php/PEAR/PackageFile/v2/Validator.php on line 1933 25 source files, building running: phpize Configuring for: PHP Api Version: 20180731 Zend Module Api No: 20180731 Zend Extension Api No: 320180731 enable igbinary serializer support? [no] : enable lzf compression support? [no] : enable zstd compression support? [no] : building in /tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1 running: /tmp/pear/temp/redis/configure --with-php-config=/usr/bin/php-config --enable-redis-igbinary=no --enable-redis-lzf=no --enable-redis-zstd=no checking for grep that handles long lines and -e… /bin/grep checking for egrep… /bin/grep -E checking for a sed that does not truncate output… /bin/sed checking for cc… cc checking whether the C compiler works… yes checking for C compiler default output file name… a.out checking for suffix of executables… checking whether we are cross compiling… no checking for suffix of object files… o checking whether we are using the GNU C compiler… yes checking whether cc accepts -g… yes checking for cc option to accept ISO C89… none needed checking how to run the C preprocessor… cc -E checking for icc… no checking for suncc… no checking whether cc understands -c and -o together… yes checking for system library directory… lib checking if compiler supports -R… no checking if compiler supports -Wl,-rpath,… yes checking build system type… x86_64-pc-linux-gnu checking host system type… x86_64-pc-linux-gnu checking target system type… x86_64-pc-linux-gnu checking for PHP prefix… /usr checking for PHP includes… -I/usr/include/php/20180731 -I/usr/include/php/20180731/main -I/usr/include/php/20180731/TSRM -I/usr/include/php/20180731/Zend -I/usr/include/php/20180731/ext -I/usr/include/php/20180731/ext/date/lib checking for PHP extension directory… /usr/lib/php/20180731 checking for PHP installed headers prefix… /usr/include/php/20180731 checking if debug is enabled… no checking if zts is enabled… no checking for re2c… no configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers. checking for gawk… gawk checking whether to enable redis support… yes, shared checking whether to disable sessions… yes checking whether to disable json serializer support… yes checking whether to enable igbinary serializer support… no checking whether to enable msgpack serializer support… no checking whether to enable lzf compression… no checking use system liblzf… no checking whether to enable Zstd compression… no checking use system libsztd… yes checking for json includes… /usr/include/php/20180731 checking for redis json support… enabled checking for redis igbinary support… disabled .... checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries… yes checking whether -lc should be explicitly linked in… no checking dynamic linker characteristics… GNU/Linux ld.so checking how to hardcode library paths into programs… immediate checking whether stripping libraries is possible… yes checking if libtool supports shared libraries… yes checking whether to build shared libraries… yes checking whether to build static libraries… no configure: creating ./config.status config.status: creating config.h config.status: executing libtool commands running: make /bin/bash /tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1/libtool --mode=compile cc -I. -I/tmp/pear/temp/redis -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1/include -I/tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1/main -I/tmp/pear/temp/redis -I/usr/include/php/20180731 -I/usr/include/php/20180731/main -I/usr/include/php/20180731/TSRM -I/usr/include/php/20180731/Zend -I/usr/include/php/20180731/ext -I/usr/include/php/20180731/ext/date/lib -I/usr/include/php/20180731/ext -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/redis/redis.c -o redis.lo libtool: compile: cc -I. -I/tmp/pear/temp/redis -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1/include -I/tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1/main -I/tmp/pear/temp/redis -I/usr/include/php/20180731 -I/usr/include/php/20180731/main -I/usr/include/php/20180731/TSRM -I/usr/include/php/20180731/Zend -I/usr/include/php/20180731/ext -I/usr/include/php/20180731/ext/date/lib -I/usr/include/php/20180731/ext -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/redis/redis.c -fPIC -DPIC -o .libs/redis.o /bin/bash /tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1/libtool --mode=compile cc -I. -I/tmp/pear/temp/redis -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1/include -I/tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1/main - .... /bin/bash /tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1/libtool --mode=compile cc -I. -I/tmp/pear/temp/redis -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1/include -I/tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1/main -I/tmp/pear/temp/redis -I/usr/include/php/20180731 -I/usr/include/php/20180731/main -I/usr/include/php/20180731/TSRM -I/usr/include/php/20180731/Zend -I/usr/include/php/20180731/ext -I/usr/include/php/20180731/ext/date/lib -I/usr/include/php/20180731/ext -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/redis/cluster_library.c -o cluster_library.lo libtool: compile: cc -I. -I/tmp/pear/temp/redis -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1/include -I/tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1/main -I/tmp/pear/temp/redis -I/usr/include/php/20180731 -I/usr/include/php/20180731/main -I/usr/include/php/20180731/TSRM -I/usr/include/php/20180731/Zend -I/usr/include/php/20180731/ext -I/usr/include/php/20180731/ext/date/lib -I/usr/include/php/20180731/ext -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/redis/cluster_library.c -fPIC -DPIC -o .libs/cluster_library.o /bin/bash /tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1/libtool --mode=link cc -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1/include -I/tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1/main -I/tmp/pear/temp/redis -I/usr/include/php/20180731 -I/usr/include/php/20180731/main -I/usr/include/php/20180731/TSRM -I/usr/include/php/20180731/Zend -I/usr/include/php/20180731/ext -I/usr/include/php/20180731/ext/date/lib -I/usr/include/php/20180731/ext -DHAVE_CONFIG_H -g -O2 -o redis.la -export-dynamic -avoid-version -prefer-pic -module -rpath /tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1/modules redis.lo redis_commands.lo library.lo redis_session.lo redis_array.lo redis_array_impl.lo redis_cluster.lo cluster_library.lo libtool: link: cc -shared -fPIC -DPIC .libs/redis.o .libs/redis_commands.o .libs/library.o .libs/redis_session.o .libs/redis_array.o .libs/redis_array_impl.o .libs/redis_cluster.o .libs/cluster_library.o -g -O2 -Wl,-soname -Wl,redis.so -o .libs/redis.so libtool: link: ( cd ".libs" && rm -f "redis.la" && ln -s "../redis.la" "redis.la" ) /bin/bash /tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1/libtool --mode=install cp ./redis.la /tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1/modules libtool: install: cp ./.libs/redis.so /tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1/modules/redis.so libtool: install: cp ./.libs/redis.lai /tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1/modules/redis.la libtool: finish: PATH="/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/sbin" ldconfig -n /tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1/modules Libraries have been installed in: /tmp/pear/temp/pear-build-root4IDNnA/redis-5.1.1/modules If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the '-LLIBDIR' flag during linking and do at least one of the following: add LIBDIR to the 'LD_LIBRARY_PATH' environment variable during execution add LIBDIR to the 'LD_RUN_PATH' environment variable during linking use the '-Wl,-rpath -Wl,LIBDIR' linker flag have your system administrator add LIBDIR to '/etc/ld.so.conf' See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. Build complete. Don't forget to run 'make test'. running: make INSTALL_ROOT="/tmp/pear/temp/pear-build-root4IDNnA/install-redis-5.1.1" install Installing shared extensions: /tmp/pear/temp/pear-build-root4IDNnA/install-redis-5.1.1/usr/lib/php/20180731/ running: find "/tmp/pear/temp/pear-build-root4IDNnA/install-redis-5.1.1" | xargs ls -dils 96792 4 drwxr-xr-x 3 root root 4096 Feb 12 02:18 /tmp/pear/temp/pear-build-root4IDNnA/install-redis-5.1.1 96796 4 drwxr-xr-x 3 root root 4096 Feb 12 02:18 /tmp/pear/temp/pear-build-root4IDNnA/install-redis-5.1.1/usr 96797 4 drwxr-xr-x 3 root root 4096 Feb 12 02:18 /tmp/pear/temp/pear-build-root4IDNnA/install-redis-5.1.1/usr/lib 96798 4 drwxr-xr-x 3 root root 4096 Feb 12 02:18 /tmp/pear/temp/pear-build-root4IDNnA/install-redis-5.1.1/usr/lib/php 96799 4 drwxr-xr-x 2 root root 4096 Feb 12 02:18 /tmp/pear/temp/pear-build-root4IDNnA/install-redis-5.1.1/usr/lib/php/20180731 29161 2596 -rwxr-xr-x 1 root root 2657936 Feb 12 02:18 /tmp/pear/temp/pear-build-root4IDNnA/install-redis-5.1.1/usr/lib/php/20180731/redis.so Build process completed successfully Installing '/usr/lib/php/20180731/redis.so' install ok: channel://pecl.php.net/redis-5.1.1 configuration option "php_ini" is not set to php.ini location You should add "extension=redis.so" to php.ini extension=redis.so WARNING: Module redis ini file doesn't exist under /etc/php/7.2/mods-available WARNING: Module redis ini file doesn't exist under /etc/php/7.2/mods-available % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
And post this upgrade the deployment ran well.
NB Reason to use phpredis https://medium.com/@akalongman/phpredis-vs-predis-comparison-on-real-production-data-a819b48cbadb PHP Redis up to 6 times faster