Version 1.0.5
aserve provides an easy way to "point and serve" a folder without having to copy files to /var/www/html, set up Apache vhosts, create symbolic links, or modify permissions.
Technically, aserve is a bash shell script that temporarily bind-mounts a local folder into Apache's document root (/var/www/html), adds minimal ACLs so Apache's www-data user can read/traverse the files, reloads Apache, and cleans everything up when you stop it.
aserve is not intended for long-term file serving. (You should set up vhosts instead!)
aserve.sh— the script to run on your Debian Linux machine- README.md - this file
- LICENSE - the MIT license
- Debian-based system (tested on LMDE 7 but should work on most Debian/Ubuntu derivatives).
- Apache2 installed and configured to serve
/var/www/html. aclpackage recommended (for setfacl):sudo apt install aclmountandsetfaclrequire root.aservemust be run withsudofor normal operation.- Optional utilities:
realpath(recommended). The script has fallbacks to Python for path resolution.
The script creates /var/www/html/<alias> and does a mount --bind /path/to/site /var/www/html/<alias>. Minimal ACLs are added for www-data (rx on the site, x on parent directories up to the user's home). Apache is reloaded so the site is available at http://localhost/<alias>.
- Resolve requested path to absolute path.
- Validate that the directory exists.
- Choose an alias (basename or provided name). If that alias already exists in
/var/www/html, append a timestamp. - Grant minimal ACLs to
www-dataso Apache can read and traverse. - Create the destination mountpoint and perform
mount --bind. - Reload Apache and print the served URL.
- If
-oflag is passed, open URL in default browser. - Wait until the process receives INT/TERM; then unmount, revoke ACLs, reload Apache.
- Download, and make script executable:
chmod +x /path/to/aserve.sh
- Optionally, install to PATH and set permissions so you can run from anywhere:
sudo cp /path/to/aserve.sh /usr/local/bin/aserve sudo chown root:root /usr/local/bin/aserve sudo chmod 755 /usr/local/bin/aserve
- Verify install (should display version):
aserve -v
Serve /home/ken/Dev/kdo (using auto-derived alias kdo):
sudo aserve /home/ken/Dev/kdo
# Now available at http://localhost/kdoServe with an explicit alias:
sudo aserve /home/ken/Dev/kdo foobar
# Now available at http://localhost/foobarServe and auto-open site in default browser:
sudo aserve -o /home/ken/Dev/kdo
# Opens http://localhost/kdo in the default web browserShow help:
aserve -hShow version number:
aserve -vClean up any previous mounts (see below for more info)
sudo aserve --clean-
If
aliasnameis omitted, the script uses the basename of the supplied path (e.g./home/ken/Dev/kdo→kdo). -
If the desired alias already exists in
/var/www/html, the script appends a timestamp to avoid overwriting. -
Press
Ctrl+Cin the terminal runningaserveto unmount, remove the mountpoint, revoke the ACLs, and reload Apache.
Press Ctrl+C in the terminal where you started aserve. The script traps INT/TERM and will:
- unmount the bind mount,
- remove the
/var/www/html/<alias>mountpoint, - revoke the ACL entries it added,
- reload Apache.
-
If
aserveexited unexpectedly or the machine rebooted and a bind mount remains, use--cleanto attempt a safe recovery. -
The script writes a lightweight record file after a successful mount at
/run/aserve/<alias>.recordcontaining the original source path.--cleanprefers using that record to find and clean the site. -
When cleaning an alias,
aservewill also attempt to detect any runningaserveprocess(es) that reference the same source path or/var/www/html/<alias>. If found, the cleaner offers to terminate those process(es) (SIGTERM, then SIGKILL if needed) so the original terminal process doesn't remain running after the mount is removed. -
If the record is missing,
--clean <alias>will fall back to resolving/var/www/html/<alias>withfindmntto determine the bind source. -
sudo aserve --clean <alias>(or--clean /path/to/source) will:- prompt for confirmation,
- revoke the recursive
www-dataACL on the recorded source (setfacl -R -x u:www-data $SRC), - unmount
/var/www/html/<alias>if mounted, - remove the mountpoint directory, remove the
/run/aserve/<alias>.recordfile (if present), and - reload Apache.
-
sudo aserve --cleanwith no argument lists records in/run/aserve/*.recordand lets you pick one interactively.
# Clean a specific alias using its record (preferred)
sudo aserve --clean kdo
# Clean by source path
sudo aserve --clean /home/ken/Dev/kdo
# Interactively choose a record to clean
sudo aserve --cleanYou can also clean old (unused) mounts manually:
sudo umount /var/www/html/<alias> || true
sudo rmdir /var/www/html/<alias> || true
sudo setfacl -R -x u:www-data /path/to/site || true
# And reload apache
sudo systemctl reload apache2- "Operation cannot be completed without root level access. Please use sudo."
- You attempted to run the script without root. Rerun with
sudo.
- You attempted to run the script without root. Rerun with
- "The directory /resolved/path does not exist."
- The supplied path is invalid or non-existent. Verify the path and try again.
- 403 Forbidden when loading the site in the browser:
- Check Apache error log for details:
sudo tail -n 80 /var/log/apache2/error.log
- Ensure
www-datahas traverse permission on every parent directory (the script tries to add these via ACLs). Ifsetfaclis not available, installacl. - Verify the mount exists:
mount | grep /var/www/html/<alias>
- Check Apache error log for details:
- If the script fails to unmount during cleanup, use the clean option (
--clean). See the "Stopping / Cleanup" section above for more information.
- The script grants
rxtowww-dataon your site folder andxon parent directories up to your home. This allows the Apache user to traverse and read the files. The script attempts to revoke the ACLs on exit. - Because it uses bind mounts and modifies ACLs, the script requires
sudo. Use responsibly; only run it on systems you trust. - If you want passwordless operation for convenience, consider a targeted polkit rule limited to this exact command — but be aware this elevates privileges and has security implications.
- The script assumes Apache serves from
/var/www/html. If your configuration differs, pick an appropriate destination or adjust the script. - The script attempts to be careful with ACLs, but ACL support (
setfacl) must be present. Install theaclpackage if needed. - The script uses
systemctl reload apache2to refresh Apache. If your system's service name is different, adjust the script. - The
-oflag usesxdg-openand invokes user's desktop session so browser reuses the existing profile (avoids prompts to choose a profile). This is best-effort and designed to be transparent to the user; if the session can't be detected, the script falls back to simply printing the URL on screen.
This script is intended as a quick developer convenience to preview sites using a real Apache server without creating persistent vhosts and should only be used on development boxes. This script is not intended for production use!