PHP Session Support in /tmp

Greg Larkin glarkin at
Mon Nov 24 07:19:28 PST 2008

Hash: SHA1

APseudoUtopia wrote:
> Hey.
> PHP stores session data for the 'file' handler in /tmp, by default.
> For organizational purposes, I'd like to change this to something like
> /tmp/php_sessions/ or so. However, I have the clear_tmp_enable feature
> enabled, so /tmp is cleared on reboot. PHP wont create the
> php_sessions dir on it's own.
> So basically, I'm looking for a way to create the dir
> /tmp/php_sessions/ each time the server is booted BEFORE apache
> starts. I'm sure I could do this somehow with the rc.d scripts, but I
> really have no idea how.
> Thanks very much.

Hi APseudoUtopia,

In addition to the other solutions offered, you can also create a simple
script like this and place it in /usr/local/etc/rc.d/make_php_session_dir:

- ---------- cut ---------- cut ---------- cut ---------- cut ----------
# PROVIDE: make_php_session_dir
# REQUIRE: mountcritlocal

# Create the PHP session file directory
mkdir -p /tmp/php_sessions
- ---------- cut ---------- cut ---------- cut ---------- cut ----------

By using the "REQUIRE: mountcritlocal" tag, the rcorder system invokes
this script before the Apache startup script in /usr/local/etc/rc.d.  I
tested this on 7.0 with a standard Apache 2.2 installation from the
ports tree.

I hope this helps, and please post any follow-up questions you have.

Best regards,
- --
Greg Larkin       - The Power To Serve - Ready. Set. Code.
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla -


More information about the freebsd-questions mailing list