Storing your PHP sessions using memcached

sudo apt-get install memcached
sudo apt-get install php5-memcache

and change some of your PHP settings :

sudo nano /etc/php5/apache2/php.ini

session.save_handler = files
; session.save_path = "N;/path"

to :

session.save_handler = memcache
; change server:port to fit your needs...

sudo service apache2 restart

To see if its working:

echo "stats settings" | nc localhost 11211

This shows that the Memcached is now listening on port 11211 with localhost connections only. We will change this to the, catch-all, IP by changing the line: “-l” to “-l” in the file “/etc/memcached.conf”. After changing the config you can see if we can now make a connection from external machines use the following command:

netstat -ln4t | grep :11211

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s