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
1

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.

 

This article was written quite a while ago (9 years), please keep this in mind when using the information written here. Links, code and commands might be outdated or broken.

Random articles

  • Laracon 2013 – Jordi Boggiano: In Depth Composer (47min video)Laracon 2013 – Jordi Boggiano: In Depth Composer (47min video)
  • First view on Zend Framework 3 by Matthew O’PhinneyFirst view on Zend Framework 3 by Matthew O’Phinney
  • PHP Caching Best Practices by Eli White (video from PHP UK Conference 2014)PHP Caching Best Practices by Eli White (video from PHP UK Conference 2014)
  • How to setup a (or multiple) server/LAMP-stack inside a virtual machine for local development with Vagrant and PuPHPetHow to setup a (or multiple) server/LAMP-stack inside a virtual machine for local development with Vagrant and PuPHPet
  • Get Github’s code colors in PHPStorm (2014 style)Get Github’s code colors in PHPStorm (2014 style)
  • The difference between “composer install” and “composer update” – nailed on the headThe difference between “composer install” and “composer update” – nailed on the head
  • When PHPStorm’s cache eats up your harddisk spaceWhen PHPStorm’s cache eats up your harddisk space
  • Perfect HTML email templates for perfect HTML emails (outlook!) with INKPerfect HTML email templates for perfect HTML emails (outlook!) with INK
  • SASSmeister is a real-time JSfiddle for SASS / CSS. Awesome!SASSmeister is a real-time JSfiddle for SASS / CSS. Awesome!
Share this

1 Comment

  • Marcello Kad Cadoni
    May 27, 2015 1:24 pm

    Why you don’t put this parameter into the Virtualhost tag instead of directory tag?

    Reply

Leave A Comment Cancel reply

phpstorm-8

A PHPStorm shortcuts cheat sheet (for Windows, Mac OS and Linux)

Shortcuts that will make you life so much easier! Please note: Frontend Devs might be irritated by the weird CTRL-Y-shortcut,

Frontend Ops Conf 2014 – Paul Irish: Delivering The Goods In Under 1000ms (40min video)

This article was written quite a while ago (8 years), please keep this in mind when using the information written

photoshop-cc-deal

Adobe offers Photoshop for $9.99 per month (limited deal)

Currently Adobe offers the very latest version of Photoshop (which is Photoshop CC) for just $9.99 or 12,99€ (EU zone:

Install MINI in 30 seconds inside Ubuntu 14.04 LTS

This is a guideline on how to install MINI – an extremely simple naked PHP application – more or less

symfony-framework-logo

SensioLabs, creator of Symfony and Silex PHP frameworks, gets $7 million capital

The company behind the two popular PHP frameworks Symfony and Silex just raised 7 million dollars to “expand their open-source

php

Awesome list of Design Patterns with PHP code examples

Probably one of the most useful GitHub repositories ever: Dominik Liebler has published a well-reseached and well-written (PSR coding guidelines

(Links) How to fix an extremely slow Symfony inside a Vagrant box

When you work with Vagrant (if not – try it!) on a Windows or Mac machine (which is an excellent

Rare Steve Jobs AND Bill Gates video interview from 2007’s D5 conference (90min)

This is something great! Two of the most important people in the last 20 years’s mainstream consumer IT history in

[Link] Improving Smashing Magazine’s Performance: A Case Study

The title says it all: A very interesting guide through the optimization process on one of the largest blogs in

steam sale coupon voucher

-30% to -90% on Steam and Origin

Soft off-topic, but as most developers like to play from time to time, this might be your change to grab

1/4

Categories

Search

hearthbleed-ssl-bug
The SSL Heartbleed bug explained in 30 seconds
Test GZIP compression of your server easily
hack-php
Facebook releases HipHop (HHVM) 3.0, adds mysqli and support for Hack language
Migrating Wikipedia to HHVM (@Scale Conference 2014)
php uk conference
PHP Opcache Explained by Julien Pauli (video from PHP UK Conference 2014)
phpstorm 7.0 php
PHPStorm 7 has been released!
php
How to setup / install PHP 5.6 on Ubuntu 14.04 LTS
php
How to prevent PHP sessions being shared between different apache vhosts / different applications
css4
Angelina Fabbro talks about “CSS4” in this excellent conference video
[Link] Making a website vertically responsive
Install MINI in 30 seconds inside Ubuntu 14.04 LTS
MINI, an extremely simple barebone PHP application
photoshop-cc-deal
Adobe offers Photoshop for $9.99 per month (limited deal)
cheap cloud server php
DigitalOcean rolls out interesting feature: Transfering server snapshots directly to the client’s account
php
Postmodern PHP: appserver.io, a multithreaded application server for PHP, written in PHP

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
 
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT