KrisWillis.com

Flower

ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13)

When running PHP5 under Ubuntu, every ~100 times you call session_start() the following error is thrown:

ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13) in ...

By default, session data is stored in /var/lib/php5 which has its permissions set to only allow data to be deleted by it’s owner (and root). It’s like this because there is a cron script that periodically clears the session data. To prevent PHP from also trying to do this, switch off the session garbage collection in php.ini (/etc/php5/apache2/php.ini) with the following:

session.gc_probability = 0

It is quite likely to be set to 1 by default. Save changes and restart apache.

sudo /etc/init.d/apache2 restart

7 Responses to “ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13)”

  1. October 11th, 2010 at 7:03 pm

    Marwelln says:

    Thanks.

  2. October 21st, 2010 at 11:36 am

    Minne says:

    Thanks, saved me time figuring what this random message means. session.gc_probability = 0 makes the garbage collector running 0 of 100 times. But is the result not that ‘garbage’ keeps pilling up? And what are the consequences of that?

  3. October 21st, 2010 at 11:41 am

    Kris says:

    No, as far as I understand it, Ubuntu is configured to go in there and clear the ‘garbage’ via a cron script.

  4. November 12th, 2010 at 8:28 am

    Anon says:

    Thanks, it saved me a lot of time.

  5. January 13th, 2011 at 6:35 am

    stefan says:

    Thanks, it worked for me also!

  6. March 12th, 2011 at 7:18 pm

    Carlos says:

    Thanks a lot!

    This is something that happens under Ubuntu, Debian php5 package hasn’t that problem (instead has others, but that are off-topic in this post :p)

    For the record:

    Debian Lenny:
    ————-
    ; This is disabled in the Debian packages, due to the strict permissions
    ; on /var/lib/php5. Instead of setting this here, see the cronjob at
    ; /etc/cron.d/php5, which uses the session.gc_maxlifetime setting below.
    ; php scripts using their own session.save_path should make sure garbage
    ; collection is enabled by setting session.gc_probability
    ;session.gc_probability = 0
    session.gc_divisor = 100

    Debian Squeeze:
    —————
    ; Defines the probability that the ‘garbage collection’ process is started
    ; on every session initialization. The probability is calculated by using
    ; gc_probability/gc_divisor. Where session.gc_probability is the numerator
    ; and gc_divisor is the denominator in the equation. Setting this value to 1
    ; when the session.gc_divisor value is 100 will give you approximately a 1% chance
    ; the gc will run on any give request.
    ; Default Value: 1
    ; Development Value: 1
    ; Production Value: 1
    ; http://php.net/session.gc-probability
    session.gc_probability = 0

    Ubuntu Maverick Meerkat:
    ————————
    ; Defines the probability that the ‘garbage collection’ process is started
    ; on every session initialization. The probability is calculated by using
    ; gc_probability/gc_divisor. Where session.gc_probability is the numerator
    ; and gc_divisor is the denominator in the equation. Setting this value to 1
    ; when the session.gc_divisor value is 100 will give you approximately a 1% chance
    ; the gc will run on any give request.
    ; Default Value: 1
    ; Development Value: 1
    ; Production Value: 1
    ; http://php.net/session.gc-probability
    session.gc_probability = 1

  7. July 5th, 2011 at 5:29 pm

    Craft It Online! » Permissions Problems with Symfony2: Another Tip says:

    [...] http://www.kriswillis.com/index.php/2010/09/09/ps_files_cleanup_dir-opendirvarlibphp5-failed-permiss... Tweet Posted on July 5, 2011 by Luis Cordova. This entry was posted in Development, symfony. Bookmark the permalink. « Set Default/Custom Selection in Symfony2 Forms [...]

Leave a Reply