How To make sure any file or folder created in /var/www/html gets automatically owned by www-data
Automatically Set Ownership to www-data Using incron If you want to ensure that any file or folder created inside /var/www/html is automatically owned by www-data , you can use incron . Incron works similarly to cron, but instead of running based on time schedules, it monitors filesystem events such as: File or directory creation File modifications Attribute changes File deletions Step 1 — Install incron Install incron using: sudo apt-get install incron Step 2 — Allow Root to Use incron By default, not all users are allowed to use incron. You must explicitly grant permission. Open the file: sudo vim /etc/incron.allow Add the following line: root Save and exit. Step 3 — Configure incrontab Edit the incrontab for root: sudo incrontab -u root -e Add this line: /var/www/html IN_CREATE /bin/chown -R www-data:www-data /var/www/html/ Save and exit. How It Works With this configuration, whenever a new file is created inside /var/www/html , its ownership will auto...