Configuring Object Cache on a Server with Fastpanel: A Step-by-Step Guide
Setting up an object cache (such as Redis) on a server running Fastpanel can seem like a daunting task, especially when you need to properly configure different versions of PHP and integrate caching into your environment. In this article we will explain in detail how to configure Redis, how to properly install the necessary PHP modules and solve a few problems that may arise. Let’s leave behind brackets the very necessity of such customization. If you’re reading this, you probably need it. Well, let’s get started!
Introduction to object cache and Redis
Object cache is a mechanism for storing data in memory to speed up query processing. Redis is one of the most popular object cache solutions. It works as an in-memory key-value store, which allows you to significantly speed up web applications, It works as an in-memory key-value store to significantly speed up web applications by reducing database load and speeding up site response time.
Installing Redis on a server with Fastpanel
First we need to install Redis on the server to use it for caching. To do this, we followed a few steps:
Redis installation:
sudo apt update sudo apt install redis-server
If Redis installed without problems, let’s check its status using the command:
sudo systemctl status redis
Configuring Redis
Redis can be configured to work with the server by changing its configuration in the file /etc/redis/redis.conf
. Важно убедиться, что Redis слушает на локальном хосте, чтобы избежать ненужных проблем с безопасностью. В случае работы с Fastpanel Redis должен работать как локальный сервис.
Problems with PHP and Redis configuration
The server is likely to use several versions of PHP. It is necessary to separate the manually installed versions from those installed via Fastpanel. One of the main problems that can be encountered is the need to properly install and configure the PHP extension php-redis
. The thing is that sites use PHP installed by the panel, and they have non-standard paths.
Problem with different versions of PHP:
- The PHPversion installed by Fastpanel is not the same as the default version. Fastpanel often has multiple versions of PHP installed (for example, PHP 8.2 and PHP 8.3). However, the command defaults to the older version, and the correct version of Redis may not be installed for this version of PHP.
- The need to use the correct paths: Since Fastpanel uses its own directory structure, it is important to make sure, that the version of PHP you are using has the Redis extension activated.
Solution:
- Let’s install the
php8.3-redis
extension via the command:sudo apt install php8.3-redis
- The next step is to make sure that Redis is properly activated for a particular version of PHP. In Fastpanel, PHP 8.3 is installed in the
/opt/php83
directory. However, Redis was not activated correctly due to an incorrect configuration. - We manually plugged Redis into the PHP configuration file by adding a line to
php.ini
for an activated version of PHP:extension=redis.so
- Restart PHP-FPM to apply the changes:
sudo systemctl restart fp2-php83-fpm.service
Redis has now started working correctly with PHP 8.3.
Checking and configuring caching
After installing Redis and configuring PHP, we have verified that the caching is working correctly:
- We used the
php -m | grep redis
command to make sure that the Redis extension is properly loaded and working. - We also verified Redis logging and configuration settings to work correctly with web applications by checking Redis availability via command:
redis-cli ping
The result should be:
PONG
Conclusion
Setting up an object cache with Redis on a server running Fastpanel may require several steps to properly install and configure PHP extensions. The main issues are related to different PHP versions, misconfigured paths, and lack of extensions for Redis. But with step-by-step instructions, proper configuration and restarting the services, all problems can be solved. After we made sure that Redis works correctly with Fastpanel and PHP 8.3, the server started processing requests much faster, which improved site performance. Now, if you want to speed up your application or website by customizing the object cache, Redis is one of the most powerful solutions worth using. If you have any questions or problems during the customization process, don’t hesitate to get help!