Thanks so much for taking the time to help me with this issue:

I had a Wordpress blog hosted on a shared Bluehost hosting account. I'm currently in the process of migrating it manually over to an AWS Elastic Beanstalk created EC2 instance using an Amazon Linux AMI. Using SSH, I:

  1. exported and imported the database into the new server's MySQL database
  2. copied over all the Wordpress files with ownership as ec2-user:ec2-user
  3. set all of the directory permissions to 755, and all of the file permissions to 644.

At this point, the index of the blog loaded perfectly normal. However, when I attempted to click on one of the posts that previously used pretty permalinks, Wordpress couldn't load it because I didn't have the .htaccess file using mod_rewrite (please note that transferring the original .htaccess is not an option). So I logged into the admin section and under Settings > Permalinks, I attempted to recreate the .htaccess file. However, I received this message from Wordpress: "If your .htaccess file were writable, we could do this automatically, but it isn’t so these are the mod_rewrite rules you should have in your .htaccess file." I created a blank .htaccess file at this point with proper permissions and retried, but with the same result.

I also noticed at this point that within the admin section, I was unable to upload pictures to the media section. From there, I figured it was an ownership issue.

Based on the above two issues, I used whoami via php's shell_exec() to determine which user Wordpress was using, and learned that the user webapp was being used. Elastic Beanstalk creates the webapp user to use for uploading and deploying new code versions via the console (however, I'm manually uploading code via SFTP using the ec2-user account). From here I:

  1. changed all of the Wordpress file/directory ownership to webapp:ec2-user
  2. set all of the directory permissions to 775, and all of the file permissions to 664 (so that I as ec2-user may write to them as well)

At this point, media uploads worked perfectly. However, Wordpress could still not create/write to the .htaccess file. Frustrated at this point, I set permissions to 777 just to see if that would work, but that didn't work either.

Any help is greatly appreciated. And thanks again for your time!

  • why not just update the htaccess manually? – Drew Khoury Sep 5 '13 at 3:31
  • It's for a Wordpress install. And I would prefer if Wordpress could do it automatically. – MSchwartz Sep 5 '13 at 18:06

Versions of Redhat/Centos? Nowadays SELinux is enabled by default and tightly limits the web server process. Output of ls -alZ .htaccess? Only files that are labeled with the selinux type httpd_sys_rw_content_t can be changed by the web server process, regardless of the old rwx unix permissions. Use chcon -t httpd_sys_rw_content_t .htaccess to change.

  • He said it was Amazon Linux. – Michael Hampton Sep 4 '13 at 16:38
  • Well he edited the question to remove the RHEL reference. – vbraun Sep 5 '13 at 11:32
  • Hi guys. When I tried chcon -t httpd_sys_rw_content_t .htaccess, I received the message "chcon: can't apply partial context to unlabeled file `.htaccess'" – MSchwartz Sep 5 '13 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.