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


Thursday, January 7, 2016

MySQL group_concat is causing trouble in getting output

Hello,

I was trying to get a long list of IDs against some value together by using group_concet comnad but there was some issue as the list I was getting was incomplete and every time I executed the command some values were missing.

I Googled for this issue and found that there is a MySQL session variable named group_concat_max_len which has a limit enforced by default to 1024, and it will not let anything beyond the enforced limit.

So, simple solution was to increase this limit to suit my need,

the command is I used is following:

SET SESSION group_concat_max_len = 1000000;

This needs to be executed for every MySQL session or needed to be declared in my.ini file for permanent usage.

Tested it works like a charm.

Thanx
Anshumaan Bakshi