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 Predis with a cluster in PHP?
- How do I install and configure a PHP Redis DLL on a Windows machine?
- How can I use PHP and Redis to retrieve a range of values from a sorted set?
- How do I use the PHP Redis zrevrange command?
- How can I check the version of PHP and Redis I am using?
- How can I use PHP and Redis to get multiple keys?
- How do I install PHP, Redis, and XAMPP?
- How can I use the zscan command in PHP with Redis?
- How can I install and configure PHP and Redis on a Windows system?
See more codes...