How to install redis extension for php 7
Attempting to extend PHP's capabilities with Redis often hits a wall when dealing with legacy environments or specific version constraints. While modern distributions usually bundle the php-redis package via their official repositories, installing it manually from source is frequently necessary. This process becomes particularly tricky when targeting PHP 7 on Ubuntu-based systems, as the direct download links provided by the upstream project have changed over time.
Many guides suggest downloading a specific archive named php7.zip from the GitHub releases page. However, relying on that specific URL often leads to dead ends because the repository structure has evolved. The file https://github.com/phpredis/phpredis/archive/php7.zip is no longer valid for direct download in many current workflows. Instead of chasing obsolete filenames, you need to target the actual release tags or use the versioned directories currently hosted by GitHub.
To proceed correctly on a fresh Ubuntu installation targeting PHP 7, you must first ensure your development headers are available. The php-dev package alone is insufficient for compiling C extensions; you specifically need the headers that match your exact PHP minor version. Run the following command to install the necessary dependencies:
sudo apt-get update
sudo apt-get install php7.0-dev redis-server libssl-dev autoconf libtool pkg-config
Once the system packages are ready, navigate to a temporary directory and fetch the latest stable source code. Since the generic php7.zip link is unreliable, it is safer to clone the repository directly or download the specific version that supports PHP 7.x. Using git ensures you get the correct commit history and avoids broken zip artifacts:
cd /tmp
git clone https://github.com/phpredis/phpredis.git
cd phpredis
After cloning, inspect the directory structure to identify which branch or tag corresponds to PHP 7 support. The repository typically maintains a php7 directory for older PHP versions, but it is crucial to verify that the codebase supports your specific minor version (e.g., 7.0 through 7.4).
Compile the extension using the standard build tools:
phpize
make
sudo make install
The phpize command detects your current PHP installation and generates the necessary Makefiles. It links against the installed PHP headers, ensuring compatibility without requiring a full recompile of the core interpreter. After the installation completes, you must register the extension in your PHP configuration. Create or edit the php.ini file located at /etc/php/7.0/mods-available/ and add the following line:
extension=redis.so
You may also need to enable the service globally by creating a symlink in the mods-enabled directory:
sudo ln -s /etc/php/7.0/mods-available/redis.ini /etc/php/7.0/mods-enabled/
sudo ln -s /etc/php/7.0/mods-available/redis.so /etc/php/7.0/cli/conf.d/10-redis.ini
Restart your PHP-FPM or Apache service to load the new extension:
sudo systemctl restart php7.0-fpm
Finally, verify that the installation succeeded by running php -m. If you see redis listed among the active modules, the setup is complete. It is important to note that while this manual approach works for custom or legacy setups, production environments often benefit from using precompiled packages available in official repositories when possible, as they reduce dependency conflicts and streamline upgrades. For developers working with Laravel projects specifically, ensuring the Redis extension is present before attempting to configure connection pools or caching strategies is a prerequisite step.