Skip to content

Instantly share code, notes, and snippets.

@anthonycoffey
Forked from durvalrafael/wordpress.sh
Last active September 13, 2025 09:33
Show Gist options
  • Save anthonycoffey/1e57be7d4910e33d436256a4a3dd78a1 to your computer and use it in GitHub Desktop.
Save anthonycoffey/1e57be7d4910e33d436256a4a3dd78a1 to your computer and use it in GitHub Desktop.
fix wordpress permissions from root dir
#!/bin/bash
# Set the WordPress root to the current working directory.
WORDPRESS_ROOT="$PWD"
# Check if the current directory looks like a WordPress installation by checking for wp-config.php
if [ ! -f "$WORDPRESS_ROOT/wp-config.php" ]; then
echo "Error: wp-config.php not found in the current directory."
echo "Please 'cd' into your WordPress root directory before running this script."
exit 1
fi
echo "Resetting permissions for WordPress in $WORDPRESS_ROOT..."
echo "Setting ownership to www-data:www-data..."
# Use sudo for chown as it requires root privileges.
sudo chown -R www-data:www-data "$WORDPRESS_ROOT"
if [ $? -ne 0 ]; then
echo "Error: Failed to set ownership. Make sure you can run sudo."
exit 1
fi
echo "Setting directory permissions to 755..."
find "$WORDPRESS_ROOT" -type d -exec sudo chmod 755 {} \;
if [ $? -ne 0 ]; then
echo "Warning: Some directory permissions might not have been set correctly."
fi
echo "Setting file permissions to 644..."
find "$WORDPRESS_ROOT" -type f -exec sudo chmod 644 {} \;
if [ $? -ne 0 ]; then
echo "Warning: Some file permissions might not have been set correctly."
fi
WP_CONFIG="$WORDPRESS_ROOT/wp-config.php"
echo "Setting permissions for wp-config.php to 640..."
sudo chmod 640 "$WP_CONFIG"
if [ $? -ne 0 ]; then
echo "Warning: Failed to set permissions for wp-config.php."
fi
echo "✅ Permission reset process completed."
echo "Please verify your WordPress site is functioning correctly."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment