Friday, June 17, 2016

AWS EC2 Apache File upload and move issue [RESOLVED]

Hello Everyone,

If you have purchased a fresh new instance on AWS which runs RHEL 7+.

And you are running PHP based application and trying to upload a file and also to move the uploaded file from tmp folder to a desired folder using. PHP functions like

copy() or move_uploaded_file() 

Now while trying to achieve above you are getting permissions errors and warnings.

You have tried everything like giving all folder permission  as 777 and made Apache the user and group owner for every file and directory under /var/www/html. And if still no joy then my friend you are a victim of SELinux.

I banged my head for hours figuring  why this simple and straight forward is not working. Finally found RHEL 7+ got SELinux installed and enabled by default. And SELinux blocks Apache to move files irrespective it is part of the same group as the folder permissions are set.

So you have same issue then start by checking if it is enabled by command:

/usr/sbin/sestatus 

The first row will say the status of SELinux, if enabled it will say enabled. And if it is enabled then most probably the reason for Apache not able to move files.

For fixing the issue just need to disable it, open the config file for SELinux:

vi /etc/selinux/config

And find a variable named SELINUX and set it as 

SELINUX=disabled

I tried SELINUX=permissive but no joy with it.


Then need to restart the system to take effect. Following works well on AWS.

shutdown -r now 


After restarting it did resolved the problem.

I did server hardening like, Permissions and ownership's I changed,  I changed them back and checked once again and everything worked well.

Do check and let me know in comments if any other issue you faced,

Thanx
Anshumaan Bakshi


1 comment:

  1. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…

    Digital Marketing Training in Chennai

    Digital Marketing Course in Chennai


    ReplyDelete