Nastavení práv pro jeden web se provede následujícími příkazy:
chown www-data:www-data -R * # Webový server bude vlastník
find . -type d -exec chmod 755 {} \; # Práva pro adresáře rwxr-xr-x
find . -type f -exec chmod 644 {} \; # Práva pro soubory rw-r--r--
Hromadné nastavení práv pro více instalací WordPressu
Pro více instalací lze použít automatický script.
#!/bin/bash
# Set up a folder to search for WordPress sites (e.g. /var/www)
web_root="/var/www"
# Set the user under which the webserver is running (e.g. www-data)
web_server_user="www-data"
echo "Searchnig WordPress in $web_root"
wordpress_folders=($(find $web_root -type f -name wp-config.php -exec dirname {} \;))
sites_count=${#wordpress_folders[@]}
echo "Found $sites_count sites"
for folder in "${wordpress_folders[@]}"
do
echo "Setting permissions for $folder"
# Set ownership and group to web server
chown -R $web_server_user:$web_server_user $folder
# Set folders permissions to 755
find $folder -type d -exec chmod 755 {} \;
# Set files permissions to 644
find $folder -type f -exec chmod 644 {} \;
# Securing wp-config.php file
chmod 600 $folder/wp-config.php
# Securing the wp-content folder
chmod 755 $folder/wp-content
chmod -R 755 $folder/wp-content/uploads
done
echo "Permissions have been set for all WordPress installations found in $web_root."