Home > Hosting > System

Installing the Memcache extension for PHP on Linux

2024-02-16 17:00:04

<p style="margin-top: 24px; margin-bottom: 24px; padding: 0px; box-sizing: border-box; line-height: 30px; color: rgb(45, 48, 55); word-break: break-all; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Microsoft Yahei&quot;, &quot;Hiragino Sans GB&quot;, &quot;Heiti SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);"><strong style="margin: 0px; padding: 0px; box-sizing: border-box;"></strong></p><p>Step 1: Install dependencies</p><p>Before installing the memcache extension, we need to install some system dependencies. Open the terminal and enter the following command:</p><div class="pre-wrapper" style="margin: 8px 0px; padding: 0px; box-sizing: border-box; position: relative; color: rgb(45, 48, 55); font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Microsoft Yahei&quot;, &quot;Hiragino Sans GB&quot;, &quot;Heiti SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);"><pre class="brush:php;toolbar:false hljs language-sql" data-copyid="1" data-highlighted="yes" style="margin-top: 8px; margin-bottom: 8px; padding: 15px; box-sizing: border-box; overflow-x: auto; background-color: rgb(240, 242, 245); font-size: 14px; border: 1px solid rgb(219, 225, 232); border-radius: 4px; text-wrap: wrap; overflow-wrap: break-word; word-break: break-all;">sudo&nbsp;apt-get&nbsp;updatesudo&nbsp;apt-get&nbsp;install&nbsp;build-essential&nbsp;libtool&nbsp;autoconf&nbsp;automake</pre><button class="ai-code-helper" style="margin: 0px; padding: 0px 8px; position: absolute; top: 2px; right: 80px; height: 24px; line-height: 24px; font-size: 12px; color: rgb(255, 239, 239); background: rgb(255, 102, 102); border-radius: 4px; outline: none; border-width: initial; border-style: none; border-color: initial; cursor: pointer; opacity: 0;">AI代码助手</button><button class="copy-code" title="复制" style="margin: 0px; padding: 0px 8px; position: absolute; top: 2px; right: 8px; background: rgb(240, 242, 245); height: 24px; line-height: 24px; font-size: 12px; color: rgb(158, 167, 179); border-radius: 4px; outline: none; border-width: initial; border-style: none; border-color: initial; cursor: pointer; opacity: 0;">复制代码</button></div><p>This will install the compiler and the required build tools.</p><p><br/></p><p>Step 2: Download and install memcached</p><p style="margin-top: 24px; margin-bottom: 24px; padding: 0px; box-sizing: border-box; line-height: 30px; color: rgb(45, 48, 55); word-break: break-all; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Microsoft Yahei&quot;, &quot;Hiragino Sans GB&quot;, &quot;Heiti SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);">Before installing the memcache extension, we need to first install memcached. Memcached is a distributed memory object caching system that stores data in memory for fast access. Download and install memcached using the following command:</p><div class="pre-wrapper" style="margin: 8px 0px; padding: 0px; box-sizing: border-box; position: relative; color: rgb(45, 48, 55); font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Microsoft Yahei&quot;, &quot;Hiragino Sans GB&quot;, &quot;Heiti SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);"><pre class="brush:php;toolbar:false hljs language-csharp" data-copyid="2" data-highlighted="yes" style="margin-top: 8px; margin-bottom: 8px; padding: 15px; box-sizing: border-box; overflow-x: auto; background-color: rgb(240, 242, 245); font-size: 14px; border: 1px solid rgb(219, 225, 232); border-radius: 4px; text-wrap: wrap; overflow-wrap: break-word; word-break: break-all;">sudo&nbsp;apt-get&nbsp;install&nbsp;memcached</pre><button class="ai-code-helper" style="margin: 0px; padding: 0px 8px; position: absolute; top: 2px; right: 80px; height: 24px; line-height: 24px; font-size: 12px; color: rgb(255, 239, 239); background: rgb(255, 102, 102); border-radius: 4px; outline: none; border-width: initial; border-style: none; border-color: initial; cursor: pointer; opacity: 0;">AI代码助手</button><button class="copy-code" title="复制" style="margin: 0px; padding: 0px 8px; position: absolute; top: 2px; right: 8px; background: rgb(240, 242, 245); height: 24px; line-height: 24px; font-size: 12px; color: rgb(158, 167, 179); border-radius: 4px; outline: none; border-width: initial; border-style: none; border-color: initial; cursor: pointer; opacity: 0;">复制代码</button></div><p style="margin-top: 24px; margin-bottom: 24px; padding: 0px; box-sizing: border-box; line-height: 30px; color: rgb(45, 48, 55); word-break: break-all; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Microsoft Yahei&quot;, &quot;Hiragino Sans GB&quot;, &quot;Heiti SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);"><strong style="margin: 0px; padding: 0px; box-sizing: border-box;"></strong></p><p><br/></p><p>Step 3: Download the memcache extension</p><p>Before installing the memcache extension for PHP, we need to download the source code. You can download the latest version from the following website:</p><div class="pre-wrapper" style="margin: 8px 0px; padding: 0px; box-sizing: border-box; position: relative; color: rgb(45, 48, 55); font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Microsoft Yahei&quot;, &quot;Hiragino Sans GB&quot;, &quot;Heiti SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);"><pre class="brush:php;toolbar:false hljs language-perl" data-copyid="3" data-highlighted="yes" style="margin-top: 8px; margin-bottom: 8px; padding: 15px; box-sizing: border-box; overflow-x: auto; background-color: rgb(240, 242, 245); font-size: 14px; border: 1px solid rgb(219, 225, 232); border-radius: 4px; text-wrap: wrap; overflow-wrap: break-word; word-break: break-all;">http://pecl.php.net/package/memcache</pre><button class="ai-code-helper" style="margin: 0px; padding: 0px 8px; position: absolute; top: 2px; right: 80px; height: 24px; line-height: 24px; font-size: 12px; color: rgb(255, 239, 239); background: rgb(255, 102, 102); border-radius: 4px; outline: none; border-width: initial; border-style: none; border-color: initial; cursor: pointer; opacity: 0;">AI代码助手</button><button class="copy-code" title="复制" style="margin: 0px; padding: 0px 8px; position: absolute; top: 2px; right: 8px; background: rgb(240, 242, 245); height: 24px; line-height: 24px; font-size: 12px; color: rgb(158, 167, 179); border-radius: 4px; outline: none; border-width: initial; border-style: none; border-color: initial; cursor: pointer; opacity: 0;">复制代码</button></div><p style="margin-top: 24px; margin-bottom: 24px; padding: 0px; box-sizing: border-box; line-height: 30px; color: rgb(45, 48, 55); word-break: break-all; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Microsoft Yahei&quot;, &quot;Hiragino Sans GB&quot;, &quot;Heiti SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);">Use the following command to download and decompress the source code:</p><div class="pre-wrapper" style="margin: 8px 0px; padding: 0px; box-sizing: border-box; position: relative; color: rgb(45, 48, 55); font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Microsoft Yahei&quot;, &quot;Hiragino Sans GB&quot;, &quot;Heiti SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);"><pre class="brush:php;toolbar:false hljs language-bash" data-copyid="4" data-highlighted="yes" style="margin-top: 8px; margin-bottom: 8px; padding: 15px; box-sizing: border-box; overflow-x: auto; background-color: rgb(240, 242, 245); font-size: 14px; border: 1px solid rgb(219, 225, 232); border-radius: 4px; text-wrap: wrap; overflow-wrap: break-word; word-break: break-all;">wget&nbsp;http://pecl.php.net/get/memcache-x.x.x.tgz tar&nbsp;-xvzf&nbsp;memcache-x.x.x.tgz</pre><button class="ai-code-helper" style="margin: 0px; padding: 0px 8px; position: absolute; top: 2px; right: 80px; height: 24px; line-height: 24px; font-size: 12px; color: rgb(255, 239, 239); background: rgb(255, 102, 102); border-radius: 4px; outline: none; border-width: initial; border-style: none; border-color: initial; cursor: pointer; opacity: 0;">AI代码助手</button><button class="copy-code" title="复制" style="margin: 0px; padding: 0px 8px; position: absolute; top: 2px; right: 8px; background: rgb(240, 242, 245); height: 24px; line-height: 24px; font-size: 12px; color: rgb(158, 167, 179); border-radius: 4px; outline: none; border-width: initial; border-style: none; border-color: initial; cursor: pointer; opacity: 0;">复制代码</button></div><p style="margin-top: 24px; margin-bottom: 24px; padding: 0px; box-sizing: border-box; line-height: 30px; color: rgb(45, 48, 55); word-break: break-all; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Microsoft Yahei&quot;, &quot;Hiragino Sans GB&quot;, &quot;Heiti SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);"><strong style="margin: 0px; padding: 0px; box-sizing: border-box;"></strong></p><p><br/></p><p>Step 4: Compile and install the memcache extension</p><p>After installing the required software packages, we can compile and install the memcache extension. Switch to the memcache source code directory and execute the following command:</p><div class="pre-wrapper" style="margin: 8px 0px; padding: 0px; box-sizing: border-box; position: relative; color: rgb(45, 48, 55); font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Microsoft Yahei&quot;, &quot;Hiragino Sans GB&quot;, &quot;Heiti SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);"><pre class="brush:php;toolbar:false hljs language-bash" data-copyid="5" data-highlighted="yes" style="margin-top: 8px; margin-bottom: 8px; padding: 15px; box-sizing: border-box; overflow-x: auto; background-color: rgb(240, 242, 245); font-size: 14px; border: 1px solid rgb(219, 225, 232); border-radius: 4px; text-wrap: wrap; overflow-wrap: break-word; word-break: break-all;">cd&nbsp;memcache-x.x.x phpize ./configure make sudo&nbsp;make&nbsp;install</pre><button class="ai-code-helper" style="margin: 0px; padding: 0px 8px; position: absolute; top: 2px; right: 80px; height: 24px; line-height: 24px; font-size: 12px; color: rgb(255, 239, 239); background: rgb(255, 102, 102); border-radius: 4px; outline: none; border-width: initial; border-style: none; border-color: initial; cursor: pointer; opacity: 0;">AI代码助手</button><button class="copy-code" title="复制" style="margin: 0px; padding: 0px 8px; position: absolute; top: 2px; right: 8px; background: rgb(240, 242, 245); height: 24px; line-height: 24px; font-size: 12px; color: rgb(158, 167, 179); border-radius: 4px; outline: none; border-width: initial; border-style: none; border-color: initial; cursor: pointer; opacity: 0;">复制代码</button></div><p style="margin-top: 24px; margin-bottom: 24px; padding: 0px; box-sizing: border-box; line-height: 30px; color: rgb(45, 48, 55); word-break: break-all; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Microsoft Yahei&quot;, &quot;Hiragino Sans GB&quot;, &quot;Heiti SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);"><strong style="margin: 0px; padding: 0px; box-sizing: border-box;"></strong></p><p><br/></p><p>Step 5: Configure PHP.ini</p><p>After installing the memcache extension, we need to add it to the PHP configuration file. Open your PHP configuration file (usually/etc/php.ini) and add the following line:</p><div class="pre-wrapper" style="margin: 8px 0px; padding: 0px; box-sizing: border-box; position: relative; color: rgb(45, 48, 55); font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Microsoft Yahei&quot;, &quot;Hiragino Sans GB&quot;, &quot;Heiti SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);"><pre class="brush:php;toolbar:false hljs language-ini" data-copyid="6" data-highlighted="yes" style="margin-top: 8px; margin-bottom: 8px; padding: 15px; box-sizing: border-box; overflow-x: auto; background-color: rgb(240, 242, 245); font-size: 14px; border: 1px solid rgb(219, 225, 232); border-radius: 4px; text-wrap: wrap; overflow-wrap: break-word; word-break: break-all;">extension=memcache.so</pre><button class="ai-code-helper" style="margin: 0px; padding: 0px 8px; position: absolute; top: 2px; right: 80px; height: 24px; line-height: 24px; font-size: 12px; color: rgb(255, 239, 239); background: rgb(255, 102, 102); border-radius: 4px; outline: none; border-width: initial; border-style: none; border-color: initial; cursor: pointer; opacity: 0;">AI代码助手</button><button class="copy-code" title="复制" style="margin: 0px; padding: 0px 8px; position: absolute; top: 2px; right: 8px; background: rgb(240, 242, 245); height: 24px; line-height: 24px; font-size: 12px; color: rgb(158, 167, 179); border-radius: 4px; outline: none; border-width: initial; border-style: none; border-color: initial; cursor: pointer; opacity: 0;">复制代码</button></div><p style="margin-top: 24px; margin-bottom: 24px; padding: 0px; box-sizing: border-box; line-height: 30px; color: rgb(45, 48, 55); word-break: break-all; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Microsoft Yahei&quot;, &quot;Hiragino Sans GB&quot;, &quot;Heiti SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);">After saving and closing the file, restart the web server for the new settings to take effect.</p><p><br/></p>


Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us