How To Store PHP Sessions in Memcached on a CentOS

Store PHP Sessions in memcached will improved the performance for busy server. Why? Because memcached will store session in memory instead of files. The following how to install Memcached and buold PHP memcached extension:
1. Install Memcached:
# yum install memcached
2. Since memchached isn’t protected with a username and password, so anyone can access it via port 11211. The solution is only listening localhost.
Let’s edit /etc/sysconfig/memcached and change:
OPTIONS=""
to
OPTIONS="-l 127.0.0.1"

3. Start memcached:
# /etc/init.d/memcached start
4. To start automatically on boot, run this command:
# chkconfig --levels 235 memcached on
5. The next step is build the memcached extension:
# yum install zlib-devel libmemcached-devel
# pecl install memcached

6. Edit php.ini and change the configuration to:
session.save_handler = memcached
session.save_path = "127.0.0.1:11211"

7. Restart apache
# /etc/init.d/httpd restart

And check using phpinfo. You should get the configuration changes like the following screenshot:
2014-12-28_13-49-07

Posted in CentOS, Linux

Leave a Reply

Your email address will not be published. Required fields are marked *

*