Operations 6 min read

Boost PHP Site Performance with tmpfs and Anything‑Sync‑Daemon on Ubuntu

This guide shows how to accelerate a PHP website on Ubuntu by mounting a tmpfs RAM disk, using Anything‑Sync‑Daemon to keep the nginx root synchronized, and configuring systemd timers so that changes are safely written back to persistent storage.

Efficient Ops
Efficient Ops
Efficient Ops
Boost PHP Site Performance with tmpfs and Anything‑Sync‑Daemon on Ubuntu

After migrating the blog to Tencent Cloud and configuring SSL, the author optimizes PHP performance using tmpfs as a RAM disk.

Backup the nginx root directory before starting.

Check Ubuntu version:

<code>$ cat /etc/issue
Ubuntu 18.04.4 LTS \n \l</code>

Create a mount point and mount tmpfs (e.g., 256M):

<code>mount -t tmpfs -o size=256M tmpfs /ramdisk</code>

Verify with df:

<code>$ df -h
Filesystem Size Used Avail Use% Mounted on
...
tmpfs 256M 0 256M 0% /ramdisk</code>

Install Anything‑Sync‑Daemon (asd) to synchronize the website directory to the RAM disk.

<code>wget https://github.com/graysky2/anything-sync-daemon/archive/master.zip
make install-systemd-all</code>
Note: on this system the service files were copied to /lib/systemd/system manually.
<code>mv asd-resync.service asd-resync.timer asd.service /lib/systemd/system
systemctl daemon-reload</code>

Configure

asd.conf

to sync the nginx root:

<code>WHATTOSYNC=('/home/huixinchen/www/htdocs/')   # directory to sync
VOLATILE="/ramdisk"                         # tmpfs target</code>

Optionally add multiple directories separated by commas.

Set up a daily systemd timer:

<code>[Unit]
Description=Timer for Anything-sync-daemon - 1Hour
PartOf=asd-resync.service asd.service

[Timer]
OnUnitActiveSec=24h</code>

Check the daemon status:

<code>$ asd p
Anything-sync-daemon v5.85 on Ubuntu 18.04.4 LTS
Daemon pid file is not present.
Resync cronjob is not present.
Overlayfs technology is currently inactive.
...
tmpfs target: /ramdisk/asd-huixinchen/home/huixinchen/www/htdocs
dir size: 237M</code>

Start the service:

<code>service asd start</code>

The nginx root now points to the RAM disk via a symlink, so no nginx configuration changes are needed; just restart PHP‑FPM and clear opcache.

<code>$ ll
total 0K
lrwxrwxrwx 1 huixinchen huixinchen 50 Feb 15 22:27 htdocs -> /ramdisk/asd-huixinchen/home/huixinchen/www/htdocs/</code>

After restarting FPM, the site works out of the box, and changes are periodically written back to the persistent backup directory.

For more details see the Anything‑Sync‑Daemon wiki.

PerformanceDevOpslinuxPHPnginxtmpfssystemd
Efficient Ops
Written by

Efficient Ops

This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.