predisHow can I install and configure php-redis on CentOS?
- Install Redis server on CentOS. The installation process is very simple, just execute the following command:
sudo yum install redis
- Start the Redis service and enable it to start at boot:
sudo systemctl start redis
sudo systemctl enable redis
- Install php-redis extension. Execute the following command to install the extension:
sudo yum install php-pecl-redis
- Configure php-redis extension. Open the php.ini configuration file and add the following line:
extension=redis.so
- Restart the Apache service for the changes to take effect:
sudo systemctl restart httpd
- Test the installation. Create a file called test.php in the web root directory and add 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";
}
?>
- Open the test.php file in the browser. You should see the following output:
Connection to server sucessfully
## Helpful links
More of Predis
- How can I use the zscan command in PHP with Redis?
- How can I use PHP and Redis to retrieve a range of values from a sorted set?
- How can I use PHP and Redis to retrieve data from a sorted set using ZRANGEBYSCORE?
- How can I use PHP and Redis to get a reverse range of scores?
- How can I install and configure PHP and Redis on a Windows system?
- How can I check the version of PHP and Redis I am using?
- How can I use Redis with the Yii PHP framework?
- 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 do I install PHP Redis on Ubuntu 20.04?
See more codes...