Skip to content

Instantly share code, notes, and snippets.

@whatafunc
Forked from raphaelstolt/redis-glue-test.php
Last active August 7, 2024 09:19
Show Gist options
  • Save whatafunc/57a0ae9aa1a5b1b80c475c4b45af8884 to your computer and use it in GitHub Desktop.
Save whatafunc/57a0ae9aa1a5b1b80c475c4b45af8884 to your computer and use it in GitHub Desktop.
Redis installation test script
<?php
define('TEST_KEY', 'are_we_glued');
$redis = new Redis();
try {
$redis->connect('localhost', 6379);
$redis->set(TEST_KEY, 'yes');
$glueStatus = $redis->get(TEST_KEY);
if ($glueStatus) {
$testKey = TEST_KEY;
echo "Glued with the Redis key value store:" . PHP_EOL;
echo "1. Got value '{$glueStatus}' for key '{$testKey}'." . PHP_EOL;
if ($redis->delete(TEST_KEY)) {
echo "2. And already removed the key/value pair again." . PHP_EOL;
}
} else {
echo "Not glued with the Redis key value store." . PHP_EOL;
}
} catch (RedisException $e) {
$exceptionMessage = $e->getMessage();
echo "{$exceptionMessage}. Not glued with the Redis key value store." . PHP_EOL;
}
@whatafunc
Copy link
Author

Complete Command Sequence

Here is the complete sequence of commands to run inside your running PHP container to install the Redis extension and restart PHP-FPM:

Install necessary dependencies and the Redis extension:

bash

**apt-get update && apt-get install -y \ libcurl4-openssl-dev \ pkg-config \ libssl-dev \ libz-dev \ wget \ gnupg**

**pecl install redis**

echo "extension=redis.so" > /usr/local/etc/php/conf.d/redis.ini

Restart PHP-FPM using pkill:

bash

**pkill -o -USR2 php-fpm**

Verify the Redis extension is enabled:

bash

**php -m | grep redis**

Explanation

Installing dependencies and the Redis extension: These commands ensure that all necessary packages are installed and the Redis extension is added via PECL.
Enabling the Redis extension: This command creates a configuration file that tells PHP to load the Redis extension.
Restarting PHP-FPM using pkill: The pkill -o -USR2 php-fpm command sends a signal to the PHP-FPM process to reload its configuration and restart gracefully.

This method ensures that the Redis extension is installed and enabled in your PHP-FPM container without relying on the service or systemctl commands.

@whatafunc
Copy link
Author

docker exec -it php-container bash
service redis-server status

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment