• Home
  • About Us
  • Contact
  • Privacy Policy

LinuxAdmin.io

  • Home
  • Tutorials
    • System Administration
    • Linux Tutorials
    • Web Hosting
    • WordPress
    • Virtualization
    • Troubleshooting
    • OpenStack

How to Save PHP Sessions in Memcached

Storigng PHP Sessions in memcached

Memcached is a high performance storage engine designed for storing chunks for data, so it is great for storing sessions in it.  The upside of doing this you notice a performance benefit from not writing these disk or a database is that you gain a performance increase. The downside is that memcached isn’t saving anything, so if memcached restarts all of the users will need to login again.

This guide assumes you have a  working installation. If you do not please see How to install Memcached.

Configure PHP for Memcache

Make sure the memcache PHP extension is installed

php -i|grep memcache

If nothing returns go ahead and install it:

pecl install memcache

Find the location of your php.ini

# php -i|grep "Loaded Configuration File"
 Loaded Configuration File => /usr/local/php7/etc/php.ini

Open the php.ini file and add the following line at the top:

extension="memcache.so"

Configure PHP To Store Session Data In Memcached

You will want to edit your php.ini again and find the following lines:

session.save_handler =
session.save_path =

You will then want to update them to the following and uncomment them:

session.save_handler = memcache
session.save_path = 'tcp://127.0.0.1:11211'

The reason we selected the PHP extension memcache vs memcached, is that the memcached extension is not available in  PHP 7. Go ahead and save the file.

Restart your webserver

service nginx restart

or

service httpd restart

And your session data should now be stored in memcached

Aug 6, 2017LinuxAdmin.io
0 0 vote
Article Rating
How To Install NTPD On CentOS 7How To Install And Test Go On CentOS
You Might Also Like
 
How To Install Memcached on CentOS
Subscribe
Notify of
guest
guest
0 Comments
Inline Feedbacks
View all comments
5 years ago PHP, Web Hosting memcached1,128
Recent Posts
  • Laravel Installation Guide For CentOS
  • Openstack Services Explanation And Overview
  • OSSEC Intrusion Detection Installation On Centos 7
  • Configure ProFTPd for SFTP on CentOS
  • How To Check And Repair MyISAM Tables In MySQL
Most Commented
Hot Clone Linux Server with Rsync
Hot Clone A CentOS Server With Rsync
14 Comments
ngx_cache_purge module
Install The ngx_cache_purge Module In Nginx
8 Comments
piwik-nginx
Piwik Analytics on Nginx
8 Comments
Tags
linuxcentosLinux Performance Tuningsysadminkvmnetworkingmemcachedanalyticssystemd
About

We love Linux and are dedicated to creating Linux administration tutorials for System Administrators since 2016.

Most Viewed
Default Gateway
How To Configure A Default Gateway on CentOS
63,000 views
Zend Opcache
Setup and Optimize Zend OpCache
46,714 views
Install ffmpeg
FFMpeg Install On CentOS 7
20,912 views
Archives
Email subscription

Sign up for our newsletter to receive the latest news and event postings.

2018 © LinuxAdmin.io
wpDiscuz