# First check what user, apache is running as. Usually, its www-data
ps aux | egrep '(apache|httpd)'
# add your user to www-data group
sudo usermod -a -G www-data <username>
# make folder/file writable by apcahe/php
sudo chown -R www-data <folder/file>