Recently in one of my project we hosted our PHP website on Amazon EC 2 which was running Apache on ubuntu. In our project we have file upload functionality which was not working. First I tired to set permission to 777 for the upload directory but still it was not working, so I went into details and found out this was the user permission issue. In this blog I am going to explain how to solve this.
Your website is running in Apache on Ubuntu. So there is a apache user, which is actually handling file operations. By default apache user does not have write permission and it does not own your website folder. So there are three basic steps to resolve this issue.
1) Find out your apache user.
Fist we have to find out name of apache user. Run following command in terminal.
ps -ef | grep apache
Check the left most column of the output. See the image below. That is name of your apache user.
In my case it was www-data user.
2)Find out your apache user.
Change owner of your upload directory.
sudo chown www-data /var/www/html/uploads
3) Setup permission on your directory.
sudo chmod 755 /var/www/html/uploads
That's it. Now you can upload file from your web application. Hope this helps you and save your time.