I am running httpd on aws ec2 instance on Amazon Linux 2.
For installing LAMP stack I used this link. The instance is running perfectly.
I need to execute a shell command from php using shell_exec('sh somescript')
. The script then intern creates a folder using sudo mkdir foldername
. This folder never gets created.
So, I directly write shell_exec('sudo mkdir foldername')
. Doesn't work.
I tried shell_exec('whoami')
. This outputs apache
(because of the group I had created from the installation.)
Other things I tried :
- Changing permission and ownership of the folder and subfolder of the directory. (Didn't work).
- Changing the user & group in
httpd.conf
.(Give Error 503, if I use ec2-user and doesn't start if I use root, which btw the comments asks.)
My question :
Why am I not able to create folder from php when httpd is running as apache user/group, when ec2-user is a user of the apache group?
Is it safe to use httpd with ec2-user as the user and group? If so how? If not what is the alternate?