Before installing the memcache and memcached extensions, make sure you have completed the following prerequisites:
First, you need to install the libmemcache library. Download the latest stable version from the official libmemcache website, extract it, navigate to the directory, and run:
./configure make sudo make install
If libmemcache is already installed on your system, you can skip this step.
Run the following command to install the memcache extension:
pecl install memcache
After installation, add the following line to your php.ini file:
extension=memcache.so
Save the file and restart your web server to apply the changes.
Similar to memcache, installing the memcached extension requires the libmemcached library. Download the stable version, extract it, then run:
./configure make sudo make install
If the library is already installed, you may skip this step.
Use the following command to install:
pecl install memcached
Once installed, add the following line to your php.ini file:
extension=memcached.so
Save and close the file, then restart your web server.
You can verify that the extensions are working by creating a phpinfo file. Create a file named phpinfo.php with the following content:
<?php phpinfo(); ?>
Save and access the file in your browser. If you see information related to memcache and memcached, the installation was successful.
By following these steps, you have successfully installed memcache and memcached extensions in PHP7 and verified their functionality. With these caching extensions enabled, you can significantly improve the performance and response speed of your PHP applications.