9951 explained code solutions for 126 technologies


predisHow do I install PHP Redis on Ubuntu 20.04?


  1. Install the Redis server using the apt command:
sudo apt install redis-server
  1. Once the installation is complete, you can start the Redis server using the systemctl command:
sudo systemctl start redis-server
  1. Now, you can install the PHP Redis extension with the following command:
sudo apt install php-redis
  1. 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
  2. Add the following line to the php.ini file to enable the Redis extension:
extension=redis.so
  1. Finally, restart the Apache web server to apply the changes.
    sudo systemctl restart apache2
  2. 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

Edit this code on GitHub