@cdejongfiero As you found out when files are added to the app's filesystem, the permissions can become different depending on how the files were added.
When uploading a file via the File Manager, the permissions are "guessed" based on the permissions of the files around it. This is correct most of the time , but can be wrong especially for apps that run with multiple user ids.
When running commands via Web Terminal, the files are created as "root". The default permissions of the Web Terminal is root - again because apps can have multiple user ids and root can be any user id.
For this reason: after you run a command, run chown -R www-data:www-data on the necessary files. Alternately, run the command with "gosu www-data php command.php ..." (this runs as user www-data).
Finally, I am not sure about the "Permission denied to delete files" . Is there a verbose mode for that command to figure what it is not able to delete?