搭建LNAMP環境(七)- PHP7源碼安裝Memcached和Memcache拓展

來源:互聯網
上載者:User

標籤:memcached   support   apache   could not   profile   with   https   pre   port   

上一篇:搭建LNAMP環境(六)- PHP7源碼安裝MongoDB和MongoDB拓展一、安裝Memcached

1.yum安裝libevent事件觸發管理器

yum -y install libevent-devel

2.建立memcached使用者組和使用者

groupadd memcacheduseradd -r -g memcached -s /sbin/nologin -M memcached

3.下載memcached源碼包,並將源碼包放到/usr/local/src/目錄下
下載頁面:http://memcached.org/downloads
這裡用的是 memcached-1.4.33.tar.gz
:http://memcached.org/files/memcached-1.4.33.tar.gz
4.進入src/目錄

cd /usr/local/src/

5.解壓源碼包

tar -zxf memcached-1.4.33.tar.gz

6.進入memcached源碼目錄,編譯安裝

cd memcached-1.4.33/./configure --prefix=/usr/local/memcached  --with-libeventmake && make install

7.修改memcached目錄許可權

chown -R memcached:memcached /usr/local/memcached

8.將memcached命令加入環境變數,修改profile檔案

vim /etc/profile

9.修改為下面內容,儲存退出

PATH=/usr/local/mysql/bin:/usr/local/php/bin:/usr/local/redis/bin:/usr/local/mongodb/bin:/usr/local/memcached/bin:$PATH

10.使/etc/profile裡的配置立即生效

source /etc/profile

11.將memcached服務指令碼加入到init.d/目錄,建立memcached檔案

vim /etc/init.d/memcached

12.加入下面內容,儲存退出

 View Code

參數解釋:
/usr/local/bin/memcached -d -u memcached -m 1024 -l 127.0.0.1 -p 11211 -c 1024 -P /var/run/memcached/memcached.pid
-d 啟動一個守護進程。可以啟動多個守護進程,但是連接埠不能重複
-u 運行Memcache的使用者
-m 分配的記憶體數量,單位是MB
-l 監聽的伺服器IP地址,預設是本機
-p 監聽的連接埠
-c 最大啟動並執行並發串連數,預設是1024
-P pid檔案位置

13.為memcached添加可執行許可權

chmod +x /etc/init.d/memcached

14.將memcached加入系統服務

chkconfig --add memcached

15.修改服務的預設啟動等級

chkconfig memcached on

16.啟動memcached

service memcached start

 

二、PHP7安裝Memcache拓展

1.yum安裝zip

yum install -y zip unzip

2.下載php7 memcache拓展包,並將源碼包放到/usr/local/src/目錄下
:https://codeload.github.com/websupport-sk/pecl-memcache/zip/php7/pecl-memcache-php7.zip
3.進入src/目錄

cd /usr/local/src/

4.解壓拓展包

unzip pecl-memcache-php7.zip

5.進入memcache拓展目錄,編譯安裝拓展

cd pecl-memcache-php7phpize./configure --with-php-config=/usr/local/php/bin/php-configmake && make install

6.修改php.ini檔案

vim /usr/local/php/etc/php.ini

7.添加memcache.so擴充配置,儲存退出

extension=memcache.so

8.重啟Apache或php-fpm

service httpd restartservice php-fpm restart

9.在web目錄下添加php檔案,如/usr/local/apache/htdocs/memcache.php 或 /usr/local/nginx/html/memcache.php

<?php$memcache = new Memcache;$memcache->connect(‘127.0.0.1‘, 11211) or die ("Could not connect");$memcache->set(‘class‘,‘toefl‘);print_r($memcache->get(‘class‘));

訪問URL,如:http://192.168.8.9/memcache.php
頁面顯示正常,則配置成功
Memcached安裝完畢

搭建LNAMP環境(七)- PHP7源碼安裝Memcached和Memcache拓展

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.