I just set up my first instance of AWS EC2 server and I'm running into an issue with permissions on a script uploading pictures. 'var/www' (and all subdirectories) owner is 'ec2-user' however the apache server is running as 'apache'. Therefore all directories created dynamically by the php script (using mkdir) have 'apache' as the owner (which it seems doesn't have write permissions) I could certainly change the apache user to 'ec2user' but I'm worried that might be a security risk. What's the correct way of doing this? Thanks for your help.
相关问题
- Django check user group permissions
- How to generate 12 digit unique number in redshift
- Use awslogs with kubernetes 'natively'
- JQ: Select when attribute value exists in a bash a
- Assume/switch role in aws toolkit for eclipse 2.0
相关文章
- Right way to deploy Rails + Puma + Postgres app to
- how many objects are returned by aws s3api list-ob
- AWS S3 in rails - how to set the s3_signature_vers
- Passthrough input to output in AWS Step Functions
- I cannot locate production log files on Elastic Be
- ImportError: cannot import name 'joblib' f
- Static IP for Auto Scale in AWS
- Flutter - http.get fails on macos build target: Co
This is a pure Linux permission problem, not an AWS problem. I just created an Amazon Linux instance and verified permissions in /var
As you see, ownership is
root
and notec2-user
. You should understand first what / why you see permission on/var/www/
toec2-user
Should need to change the owner of that directory again, you can type :
It is not a best practice to let your web server (
httpd
) write to/var/www
nor to run that process with elevated privileges (such as root). Should your app really write to the local storage, use a different volume, mounted in a separate directory, where no executable are available.To set file permissions for the Apache web server
1- Add the www group to your EC2 instance with the following command:
2- Add the ec2-user user to the www group:
3- To refresh your permissions and include the new www group, log out:
4- Log back in again and verify that the www group exists with the groups:
5- Change the group ownership of the
/var/www
directory and its contents to the www group:6- Change the directory permissions of
/var/www
and its subdirectories to add group write permissions and set the group ID on subdirectories created in the future:7- Recursively change the permissions for files in the
/var/www
directory and its subdirectories to add group write permissions: