predisHow do I install PHP Redis on Ubuntu 20.04?
- Install the Redis server using the apt command:
sudo apt install redis-server
- Once the installation is complete, you can start the Redis server using the systemctl command:
sudo systemctl start redis-server
- Now, you can install the PHP Redis extension with the following command:
sudo apt install php-redis
- After the installation is complete, you can enable the extension by editing the php.ini file.
sudo nano /etc/php/7.4/apache2/php.ini
- Add the following line to the php.ini file to enable the Redis extension:
extension=redis.so
- Finally, restart the Apache web server to apply the changes.
sudo systemctl restart apache2
- To test the installation, create a PHP file with the following code:
<?php
$redis = new Redis();
if ($redis->connect('127.0.0.1', 6379)) {
echo "Connection to server sucessfully";
} else {
echo "Connection to server failed";
}
?>
The output should be:
Connection to server sucessfully
Helpful links
More of Predis
- How can I use PHP and Redis to retrieve a range of values from a sorted set?
- How do I use yum to install php-redis?
- How can I use PHP to increment values in Redis using ZINCRBY?
- How can I use PHP and Redis to retrieve data from a sorted set using ZRANGEBYSCORE?
- How do I use PHP and Redis together to create a transaction?
- How can I install and configure Redis on an Ubuntu server running PHP?
- How can I configure a PHP application to use Redis with a specific timeout?
- How can I set a timeout for a Redis connection using PHP?
- How can I use Redis to rate limit requests in PHP?
See more codes...