3.3 KiB
Server Setup
One-time setup (before first deploy)
Run the setup script on the server. It creates /var/www/posterg, sets the
correct ownership/permissions, and adds the deploy user to the posterg group:
just setup-server
What the script does:
- Creates the
posterggroup if it doesn't exist - Adds both the SSH user (read from
~/.ssh/configviassh -G posterg) andwww-datatoposterg - Creates
/var/www/postergowned bywww-data:posterg - Sets all directories to 2775 (
rwxrws r-x) — the setgid bit ensures new files/dirs inherit theposterggroup, which is required forrsync --chown=www-data:postergto succeed - Sets files to 664
- Sets
storage/to 2775, database files to 660
Important: After running
setup-server, log out and back in on the server (or runnewgrp posterg) so the new group membership is active before deploying.
Why setgid (2775) on directories?
rsync uses --chown=www-data:posterg to set ownership on transferred files.
For this to work, the receiving process (running as padlock) must have write
permission on every target directory. Without the setgid bit:
- Newly created subdirectories inherit
padlock's primary group www-data(nginx/php-fpm) can't write to them → 403 errorspadlockcan't write to dirs owned bywww-data→ rsync Permission denied
With 2775 + group=posterg:
- Both
padlockandwww-dataare inposterg→ both can write - New subdirs automatically get
postergas their group - rsync can create files and directories without errors
Deploying the application
# Push all app files
just deploy
# Push initial database (aborts if remote DB already exists)
just deploy-db
Applying the nginx config
The config is in nginx/posterg.conf. Upload it and run the deploy script on
the server:
rsync -v nginx/posterg.conf posterg:/tmp/posterg.conf
ssh posterg "sudo bash /var/www/posterg/scripts/deploy-server.sh"
ssh posterg "sudo systemctl reload nginx"
scripts/deploy-server.sh fixes ownership/permissions and installs the nginx
config from /tmp/posterg.conf. It must be run as root.
Managing admin users
ssh posterg "sudo bash /var/www/posterg/scripts/manage-admin-users.sh"
Interactive menu for adding, changing, and deleting htpasswd entries at
/etc/nginx/.htpasswd-posterg.
Troubleshooting
rsync: Permission denied on mkdir or mkstemp
The remote directory permissions are wrong. Run:
just setup-server
Then log out/in on the server and retry just deploy.
If you need to fix it manually (replace youruser with your remote username):
ssh posterg
sudo DEPLOY_USER=youruser bash /tmp/setup-server.sh
Or directly:
ssh posterg
sudo chown -R www-data:posterg /var/www/posterg
sudo find /var/www/posterg -type d -exec chmod 2775 {} \;
sudo find /var/www/posterg -type f -exec chmod 664 {} \;
sudo usermod -aG posterg youruser
Nginx 403 Forbidden
ssh posterg
sudo find /var/www/posterg -type d -exec chmod 2775 {} \;
sudo find /var/www/posterg -type f -exec chmod 664 {} \;
sudo chmod 660 /var/www/posterg/storage/*.db
Database permission error
ssh posterg
sudo chown www-data:posterg /var/www/posterg/storage/posterg.db
sudo chmod 660 /var/www/posterg/storage/posterg.db