2

I've got some issues with file permissions which I'm trying to resolve...

I have two sites and they both have the same permissions as far as I can tell but for some reason one site can upload files / read the files in WordPress' media explorer however the other site doesn't.

enter image description here

The server in question is a AlmaLinux server running WHM/cPanel with CloudLinux LVE and LiteSpeed Web Server.

The permissions are as follows:

/home/account/ has account:account and 711
/home/account/public_html/ has account:account and 755
/home/account/public_html/.htaccess has account:account and 644
/home/account/public_html/website has account:account and 755
/home/account/public_html/website/.htaccess has account:account and 644
/home/account/public_html/website/wp-config.php has account:account and 600 because the file needs to be able to be edited via FTP with the cPanel account login.
/home/account/public_html/website/*.php have account:account and 644

After this all other files/folders are:

/home/account/public_html/website/[ALL DIRECTORIES] have account:account and 755
/home/account/public_html/website/[ALL FILES] has account:account and 644

The following files have all been setup by WordFence Security automatically:

/home/account/public_html/website/wp-content/wflogs/hasaccount:accountand755 /home/account/public_html/website/wp-content/wflogs/*.php have account:account and 600

By that logic, should Sucuri Security also have the same 600 permissions for their files?/home/account/public_html/website/wp-content/uploads/sucuri/*.php

I created the following script to double check the permissions/ownership and both sites return no issues...

#!/bin/bash

# Define constants
ACCOUNT=account
WORDPRESS=website
ACCOUNT_PATH="/home/${ACCOUNT}"
WORDPRESS_PATH="${ACCOUNT_PATH}/public_html/${WORDPRESS}"
WORDFENCE_LOGS_PATH="${WORDPRESS_PATH}/wp-content/wflogs"

# Function to check file permissions
check_perms() {
    local path="$1"
    local type="$2" # "file" or "dir"
    local perms="$3"
    local owner="$4"
    local group="$5"

    local current_perms=$(stat -c "%a" "$path")
    local current_owner=$(stat -c "%U" "$path")
    local current_group=$(stat -c "%G" "$path")

    if [ "$type" == "file" ] && [ "$current_perms" != "$perms" ]; then
        echo "$path - File permissions should be $perms but are $current_perms."
    elif [ "$type" == "dir" ] && [ "$current_perms" != "$perms" ]; then
        echo "$path - Directory permissions should be $perms but are $current_perms."
    fi

    if [ "$current_owner" != "$owner" ]; then
        echo "$path - Owner should be $owner but is $current_owner."
    fi

    if [ "$current_group" != "$group" ]; then
        echo "$path - Group should be $group but is $current_group."
    fi
}

export -f check_perms
export ACCOUNT ACCOUNT_PATH WORDPRESS WORDPRESS_PATH WORDFENCE_LOGS_PATH

# Check specific directories and files
check_perms "${ACCOUNT_PATH}/" "dir" "711" "$ACCOUNT" "$ACCOUNT"
check_perms "${ACCOUNT_PATH}/public_html/" "dir" "755" "$ACCOUNT" "$ACCOUNT"
check_perms "${ACCOUNT_PATH}/public_html/.htaccess" "file" "644" "$ACCOUNT" "$ACCOUNT"
check_perms "$WORDPRESS_PATH" "dir" "755" "$ACCOUNT" "$ACCOUNT"
check_perms "$WORDPRESS_PATH/.htaccess" "file" "644" "$ACCOUNT" "$ACCOUNT"
check_perms "$WORDPRESS_PATH/wp-config.php" "file" "600" "$ACCOUNT" "$ACCOUNT"

# Correctly check all PHP files in the WordPress root directory
find "$WORDPRESS_PATH" -maxdepth 1 -type f -name "*.php" ! -name "wp-config.php" -exec bash -c 'check_perms "$0" "file" "644" "$ACCOUNT" "$ACCOUNT"' {} \;

# Check all directories and files under the WordPress installation
find "$WORDPRESS_PATH" -type d ! -path "$WORDFENCE_LOGS_PATH" -exec bash -c 'check_perms "$0" "dir" "755" "$ACCOUNT" "$ACCOUNT"' {} \;
find "$WORDPRESS_PATH" -type f ! -path "$WORDFENCE_LOGS_PATH/*" ! -name "*.php" -exec bash -c 'check_perms "$0" "file" "644" "$ACCOUNT" "$ACCOUNT"' {} \;

# Special handling for WordFence Security's wflogs directory and files
check_perms "$WORDFENCE_LOGS_PATH" "dir" "755" "$ACCOUNT" "$ACCOUNT"
find "$WORDFENCE_LOGS_PATH" -type f -name "*.php" -exec bash -c 'check_perms "$0" "file" "600" "$ACCOUNT" "$ACCOUNT"' {} \;
3
  • 1
    your screenshot says there was an error uploading but mentions nothing about permissions, how did you confirm that permissions was the problem and not something else? What does the error log say? Note the media library doesn't display images in the uploads folder, it lists posts of type attachment that represent the files (on many sites the files aren't on the server at all but on a 3rd party). Also the correct ownership and permissions for you are unique and super specific to you, you need to phrase your question in a way that it works for all people with that question, not just you
    – Tom J Nowell
    Feb 26 at 8:58
  • 1
    there's a slight possibility of permission issue with your user and servers' user, please check if you're using apache please check apache user & group, if using php-fpm then check fpm pool conf file and verify the user & group too. if you are using 2 different (usually apache & fpm configured to use www-data:www-data), then your web-server might not have permission to write files to the upload directory. Feb 27 at 9:32
  • Tom, I believe it's permission related because the same exact plugins/theme set work on different sites no problem, other sites on the account work no problem. I'm not seeing anything in any error logs...
    – Ryflex
    Mar 4 at 12:01

1 Answer 1

0

As you can see in wp-includes/script-loader.php, the exact message 'An error occurred in the upload. Please try again later.' is the default error message.

After looking further in wp-includes/js/plupload/handlers.js you can realize that something specific happened. You could debug this by setting a breakpoint to look up exact error code. See https://stackoverflow.com/a/13372025/2234089 for more information about browser javascript debugging.

Look in to your server error log for PHP errors.

Ensure you don't have conflicts with other themes or plugins, try disabling them all and see if upload still fails.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.