FileZilla cannot upload to /var/www on your EC2 instance
FileZilla reports permission denied when uploading into /var/www/htmlShort answer
You log in over SFTP as ec2-user, but Apache's document root is owned by root, so you may not write there. Add ec2-user to the apache group, hand /var/www to that group, and give it write access. Log out and in again so the new group takes effect, and reconnect FileZilla.
Fix it fast
1Find out which cause you have
On the instance, see who owns the web root and which groups your login user belongs to.
ls -ld /var/www /var/www/html groups2Match what you see, then jump to its fix
- 1
ls -ld shows root root and drwxr-xr-x/var/www is owned by root and your user has no write accessFix - 2
usermod ran, but writes still failThe group change is not active in the session FileZilla usesFix - 3
Authentication fails or you land in a home folder that is not ec2-user'sFileZilla logs in as the wrong user for the AMIFix
- 1
What does the error look like?
FileZilla reports permission denied when uploading into /var/www/htmltouch: cannot touch '/var/www/html/index.html': Permission denied
Cause 1 of 3
/var/www is owned by root and your user has no write access
1Check
The Amazon Linux document root is /var/www/html, owned by root by default, so ec2-user cannot write there.
ls -ld /var/www/html2Fix
Give ec2-user group access through the apache group: add the user to the group, change group ownership, then set group write and the setgid bit on directories and 0664 on files.
sudo usermod -a -G apache ec2-user
sudo chown -R ec2-user:apache /var/www
sudo chmod 2775 /var/www && find /var/www -type d -exec sudo chmod 2775 {} \;
find /var/www -type f -exec sudo chmod 0664 {} \;3Verify
Log out and back in, then check the group list and try a file write.
groups
touch /var/www/html/test.txt && rm /var/www/html/test.txtConfirmed by docs.aws.amazon.com
Cause 2 of 3
The group change is not active in the session FileZilla uses
1Check
A new group membership shows only after you log out and in. The AWS guide says to do this to pick up the group.
groups2Fix
Disconnect FileZilla and your ssh sessions, then reconnect. groups should list apache.
exit3Verify
After reconnecting, groups lists apache and the upload works.
groupsConfirmed by docs.aws.amazon.com
Cause 3 of 3
FileZilla logs in as the wrong user for the AMI
1Check
Each AMI has its own default user: ec2-user for Amazon Linux, ubuntu for Ubuntu, admin for Debian and so on.
cat /etc/os-release | head -n 22Fix
Use the AMI's default user and your .pem key in FileZilla's SFTP site settings, the same pair that works for ssh.
ssh -i /path/key-pair-name.pem ec2-user@instance-public-dns-name3Verify
The remote site opens in the user's home directory.
ls ~Confirmed by docs.aws.amazon.com
How do I stop it coming back?
- Never upload as root or chmod 777 the web root; use the group method instead.
- Apply the group setup once when you build the server and put it in your setup notes.
- Use a deploy user or CI over ssh for production, so no person edits files by hand.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Servers
dnf cannot install MySQL on Amazon Linux 2023
dnf cannot find a mysql-server package on Amazon Linux 2023
Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.
3 causes, each with a fixServers
Ansible hangs, then times out waiting for the sudo prompt
a playbook using become seems to hang
Ansible ran sudo on the target and never saw the answer it expected.
3 causes, each with a fixServers
Apache on Ubuntu returns 404 Not Found for my site
The requested URL was not found on this server.
On Ubuntu a 404 from Apache usually means the request maps to a path that has no file.
3 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
Apache warns that a ${VAR} config variable is not defined
${VAR} left unchanged in the configuration, with a warning in the error log
Apache expands ${VAR} from Define or from the shell environment that exists when the server starts.
3 causes, each with a fix