How to Install Memcached in Fedora 15

by Prabakaran 2012-07-30 14:29:47

Step 1: It is assumed that you already have a Fedora setup with PHP installed. Now first we will install memcached in the system. Then we will change the configurations. So open the terminal and gain the root privilege.

[aneek@localhost ~]$ sudo su
[sudo] password for aneek:
[root@localhost aneek]# yum install memcached

This will create this type of output

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
memcached i686 1.4.5-7.fc15 fedora 68 k

Transaction Summary
================================================================================
Install 1 Package(s)

Total download size: 68 k
Installed size: 146 k
Is this ok [y/N]: y
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 68 k
memcached-1.4.5-7.fc15.i686.rpm | 68 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : memcached-1.4.5-7.fc15.i686 1/1

Installed:
memcached.i686 0:1.4.5-7.fc15

Complete!

Step 2: Next, we will configure the memcached settings. So to do that again type in

[root@localhost aneek]# vim /etc/sysconfig/memcached

So, this will open the file called memcached as,

PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="512"
OPTIONS=""

Step 3: Then we will make the memcached as the system service. So to do that we will issue the following commands.

[root@localhost aneek]# chkconfig memcached on
[root@localhost aneek]# /etc/init.d/memcached start

The first one is the command that will allow memcached to start when the system starts. The second one is the command that will start the demon.
Hopefully this will output as,

Starting memcached (via systemctl): [ OK ]

Step 4: In the next step, issue this command to test the service/demon.

echo stats | nc localhost 11211

This will outoput as,

STAT pid 3353
STAT uptime 11
STAT time 1314808323
STAT version 1.4.5
STAT pointer_size 32
STAT rusage_user 0.000000
STAT rusage_system 0.002999
STAT curr_connections 10
STAT total_connections 11
STAT connection_structures 11
STAT cmd_get 0
STAT cmd_set 0
STAT cmd_flush 0
STAT get_hits 0
STAT get_misses 0
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 6
STAT bytes_written 0
STAT limit_maxbytes 67108864
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT bytes 0
STAT curr_items 0
STAT total_items 0
STAT evictions 0
STAT reclaimed 0
END

Step 5: The next step is to allow memcache port in the Firewall. I have the firewall disabled in my PC. But if you have it enabled then issue this command and paste the following line,

[root@localhost aneek]# vim /etc/sysconfig/iptables
#Paste this in iptables file Before COMMIT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 11211 -j ACCEPT
[root@localhost aneek]# service iptables restart

Please note,
Paste this in iptables file Before COMMIT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 11211 -j ACCEPT
Step 6: Now we are in the last stages, install the PHP extension for memcache and memcached. So again open the terminal, and type,

[root@localhost aneek]# yum install php-pecl-memcache

This will output as,

Dependencies Resolved

=====================================================================================================================================================
Package Arch Version Repository Size
=====================================================================================================================================================
Installing:
php-pecl-memcache i686 3.0.5-3.fc15 fedora 58 k

Transaction Summary
=====================================================================================================================================================
Install 1 Package(s)

Total download size: 58 k
Installed size: 156 k
Is this ok [y/N]: y
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 58 k
php-pecl-memcache-3.0.5-3.fc15.i686.rpm | 58 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : php-pecl-memcache-3.0.5-3.fc15.i686 1/1

Installed:
php-pecl-memcache.i686 0:3.0.5-3.fc15

Complete!

Step 7: Last, we will install the Memcached extension. Type in terminal as,

[root@localhost aneek]# yum install php-pecl-memcached

This will output as,

Dependencies Resolved

=====================================================================================================================================================
Package Arch Version Repository Size
=====================================================================================================================================================
Installing:
php-pecl-memcached i686 1.0.2-5.fc15 fedora 28 k
Installing for dependencies:
libmemcached i686 0.47-1.fc15 fedora 156 k
php-pecl-igbinary i686 1.1.1-1.fc15 fedora 30 k

Transaction Summary
=====================================================================================================================================================
Install 3 Package(s)

Total download size: 214 k
Installed size: 503 k
Is this ok [y/N]: y
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 214 k
(1/3): libmemcached-0.47-1.fc15.i686.rpm | 156 kB 00:01
(2/3): php-pecl-igbinary-1.1.1-1.fc15.i686.rpm | 30 kB 00:00
(3/3): php-pecl-memcached-1.0.2-5.fc15.i686.rpm | 28 kB 00:00
-----------------------------------------------------------------------------------------------------------------------------------------------------
Total 87 kB/s | 214 kB 00:02
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : php-pecl-igbinary-1.1.1-1.fc15.i686 1/3
Installing : libmemcached-0.47-1.fc15.i686 2/3
Installing : php-pecl-memcached-1.0.2-5.fc15.i686 3/3

Installed:
php-pecl-memcached.i686 0:1.0.2-5.fc15

Dependency Installed:
libmemcached.i686 0:0.47-1.fc15 php-pecl-igbinary.i686 0:1.1.1-1.fc15

Complete!

Step 8: Next we will restart out Apache server to see the effects.

[root@localhost aneek]# /etc/init.d/httpd restart

Then Create a php file and write the codes in it,

<?php
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");
//Can Use 127.0.0.1 instead "localhost"
$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>n";
$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;
$memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)<br/>n";
$get_result = $memcache->get('key');
echo "Data from the cache:<br/>n";
var_dump($get_result);
?>

If you see it running then it is fine. Now, you can use Memcached in Fedora 15.
674
like
0
dislike
0
mail
flag

You must LOGIN to add comments