When used as a web app server, the Raspberry Pi often hosts a small number of static files that rarely change. Although the Raspberry Pi Model B(+) only has 512 MB of RAM, using 10MB for a ramdisk is usually more than enough.
Files will be copied by Apache at startup. If you make changes to these files, you’ll either need to copy them manually, or restart Apache.
Start by making the directory mount point. I used
# mkdir /var/www-ramdisk
Modern linux systems mount ramdisks through ‘tmpfs’, so add an entry to
tmpfs /var/www-ramdisk tmpfs nodev,nosuid,uid=[UID],gid=[GID],size=10M 0 0
[GID] with the respective uid and gid that Apache runs under for your system. On the default Raspbian install, this will be the www-data user and group.
mount -a and the ramdisk should appear (use
df to confirm).
Next comes the Apache config. Somewhere in the config, you’ll need a
/etc/apache2/mod_perl_post_config.pl, an write in:
# Copy files to the RAM disk (system( 'cp -R /var/www/* /var/www-ramdisk' ) == 0) or die "Could not copy files to ramdisk: $!\n"; 1;
This shells out during startup to recursively copy everything from the default Apache docroot to the ramdisk.
Now grep through your Apache config, and change all paths to
/var/www and replace it with
/var/www-ramdisk. Lastly, restart Apache with:
# /etc/init.d/apache2 restart
Check the files with
ls -l /var/www-ramdisk and you should see everything that’s in
Edit: Forgot to credit domoticz.com, where I got much of the fstab setup.