Skip to content

Instantly share code, notes, and snippets.

@skaag
Created April 4, 2013 19:11
Show Gist options
  • Save skaag/5313251 to your computer and use it in GitHub Desktop.
Save skaag/5313251 to your computer and use it in GitHub Desktop.
If you don't have an extra partition that you can use for temporary uploaded files via php, you can create a virtual drive. This script shows you how to do that.
# Create the file and format it
cd /opt
dd if=/dev/zero of=/opt/tmp-disk.img count=2048000
mkfs.ext3 -q /opt/tmp-disk.img
# Let's create the actual directory for it
mkdir /phptmp
chmod 1777 /phptmp
# Add this to /etc/fstab so we can mount it
echo "# Locked down temporary mount for php sessions and uploads" >> /etc/fstab
echo "/opt/tmp-disk.img /phptmp ext3 rw,noexec,nosuid,nodev,noatime,loop=/dev/loop1 0 0" >> /etc/fstab
# Finally let's mount it:
mount /phptmp
# Now edit /usr/local/lib/php.ini (or wherever it is), and modify:
upload_tmp_dir = /phptmp
session.save_path = /phptmp
# 1. Restart Apache / Nginx
# 2. Verify that temporary files and sessions can be written to /phptmp
# 3.You're done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment