The folder that your PHP script is trying to write will probably be owned by the root user. Your PHP script is more than likely running under the www-data user if you use the default Ubuntu / Apache / PHP setting.
As such you need:
chown -R www-data:www-data folder chmod -R g+w folder
If you find that PHP runs as a user other than www-data, just change the user to a group in the first line of code.
PS. change the "folder" for your actual folder name.
source share