Logo
  • PHP
    • HipHop / HHVM
    • Modern PHP
    • PHPStorm
    • LAMP
    • Laravel
    • Composer
    • PDO
  • JavaScript
    • node.js
    • AngularJS
  • CSS
    • SASS
    • “CSS4” (CSS level 4)
  • HTML
  • Git
  • LAMP
  • Vagrant
  • UI / UX
  • Architecture of …
  • Off-Topic
With ♥ from Berlin
August 30, 2013
Chris
Linux, PHP
Comments Off on How to prevent PHP sessions being shared between different apache vhosts / different applications

How to prevent PHP sessions being shared between different apache vhosts / different applications

PreviousNext
php

When you run multiple applications on one server, you might run into the session-sharing problem: All your applications share the same pool of PHP sessions. This is especially bad when running multiple instances of the same software, like multiple WordPress blogs etc.

Usually, when running multiple applications, you’ll do this with multiple VirtualHosts on your server (i cannot go into detail what a VirtualHost is or how to setup, as you probably already know when reading such an article). The way to go is simple: Set a different PHP session folder for every VirtualHost, like this:

php_value session.save_path "/var/mysessionsforapplication_1"

 

In this example I’m running two instances of the same application on one server, each one on a different port (you might want to use a domain name here).

<VirtualHost *:81>
    ...
    DocumentRoot /var/www/app1
    <Directory "/var/www/app1">
        AllowOverride All
        php_value session.save_path "/var/mysessionsforapplication_1"
   </Directory>
</VirtualHost>

<VirtualHost *:82>
    ...
    DocumentRoot /var/www/app2
    <Directory "/var/www/app2">
        AllowOverride All
        php_value session.save_path "/var/mysessionsforapplication_2"
   </Directory>
</VirtualHost>

Please note that you need to restart the apache after you’ve changed things like that. Setting up VirtualHosts is a topic on it’s own, so it’s not covered here. In most cases editing

/etc/apache2/sites-available/default

will do the job.

 

Share this
js javascript

How JavaScript really works – An introduction into the JavaScript call stack by Philip Roberts (20min video)

hiphop php

HipHop VM reaches 100% green Unit Tests in Laravel, Drupal, Slim, CodeIgniter etc.

In September 2013 the PHP HipHop VM dev team wrote a very interesting article [1] about failing Unit Tests of

phpstorm-github-code-color-syntax-theme

Get Github’s syntax highlighting colors in PHPStorm

I really really like the colors on GitHub’s code previews but couldn’t find any themes that copy that in a

Microsoft announces “holographic” 3D interfaces (promo video)

Microsoft has just announces the damn future in business und consumer electronics! Interactive, “holographic” 3D environments, usable without a keyboard,

Compare 250+ cloud server plans with Cloud Cost Calculator

How cool is that ? The Cloud Cost Calculator compares more than 250 cloud server plans of Amazon, Rackspace, DigitalOcean,

php

How the PHP session garbage collector really works

Sessions in PHP are easy to handle, but have a tricky configuration underneath. The common opinion is, that when you

hack-php

Wow! Facebook devs have rewritten and fixed PHP, releasing it as new language called “Hack” today

Exciting stuff is happening: Some years ago Facebook has released an early preview of HipHop, a virtual machine that precompiles

Google I/O 2014 – HTTPS Everywhere (video)

Excellent, essential and game-changing talk by Ilya Grigorik and Pierre Far (both of Google), explaining why you should always use

Create a fast, perfect and bootable 1:1 Windows backup (full clone of HDD) for SSD migration

In this article I want to share a super-simple, extremely fast and totally free workflow with you that will create

organizing css

Jonathan Snook – CSS is a Mess – How to organize CSS in big projects (54min video talk)

1/4

Categories

Search

php
appserver.io – A New Way of Magento Enterprise Infrastructure (26min video talk)
phpstorm 7.0 php
A perfect video tutorial to get started with xdebug in PHPStorm
github-logo-octocat
GitHub buys Easel.io, a code-free full website creator worth a look
How Snapchat wants to earn money (by establishing vertical videos)
php
Test out PHP 5.6alpha1 on Windows 7 / 8 with two clicks
php
Slides from International PHP Conference 2014
modern-php
Creator of Slim framework and “PHP – The right way” writes book: “Modern PHP”, available 2015
Disappointed by Watch Dogs’s graphics ? See how it looks with unlocked, hidden settings. Awesome!
php
How to install/setup latest version of PHP 5.5 on Debian Wheezy 7.0/7.1/7.2 (and how to fix the GPG key error)
phpstorm 7.0 php
How to setup and use XDEBUG with PHPStorm 6/7 (locally in Windows 7/8 and Mac OS X)
vagrant
How to setup a local server (in a virtual machine) with Vagrant in PHPStorm
mod-rewrite-ubuntu-14-04-lts
How to enable mod_rewrite in Ubuntu 14.04 LTS
php
PHP 5.7 gets refactored core, is 10%-30% faster than PHP 5.5! Wow!
Dangerous Performance Myths in the Web (video talk by Thomas Lohner, PHPUG Latvia)
github-logo-octocat
GitHub rolls out .PSD diff and viewing

Tags

apache bash centos composer conference coupon CSS debian fonts framework git GitHub hack HHVM HipHop HTML HTML5 IDE JavaScript JS LAMP laravel linux mod_rewrite MVC MySQL Nginx optimization PHP PHP 5.5 PHP 5.6 phpmyadmin PHPStorm security server SSD Ubuntu UI UX vagrant video virtual machine voucher VPS wordpress
Side-Project: Wordle-Solver:
www.wordle-helper.info

Pages

  • Privacy Policy