Many people seem to have this issue where you create a WordPress site and then when you go to change the site URL structure under “Permalinks”, the site is unable to change it due to permissions.
First thing to figure out is which directory is the root of your website. Doing a generic install it is /var/www/html for Apache.
Copy the code it gives you on the WordPress page. Create that file in the directory from step 1 and gave it full permissions (temporarily):
1 2 3
cd /var/www/html sudo touch .htaccess sudo pluma .htaccess
- paste in code from above and save.
It said to change permission to apache:apache and run:
1 2 3
sudo chmod 777 .htaccess sudo chown -R apache:apache /var/www/html/* sudo service httpd restart
This should’ve done the trick. But what really happened is once I saved, I got a bunch of AVC Denied errors from Selinux on my Centos VM. So I had to look that up
I started thinking, maybe if it’s not just SELinux, but maybe some configuration for Apache.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
# I ran the following along with the previous steps and it seemed to work. But the links weren't actually changing. sudo setenforce 0 # I then ran the following and it still didn't work. Rebooted. sudo semanage fcontext -a -t httpd_sys_rw_content_t '.htaccess' # I then ran the following in /var/www/html to confirm. Still didn't work. chcon --type httpd_sys_rw_content_t /var/www/html/.htaccess ls -alZ # I started thinking, maybe if it's not just SELinux, but maybe some configuration for Apache. cat /etc/httpd/conf/httpd.conf # Look for <Directory /path/to/site> AllowOverride None </Directory> # Add/change the following setting to allow .htaccess in your web directory to work: AllowOverride FileInfo # Restart the daemon sudo service restart httpd # This resolved it! # NOTE: I've also read that you may have to enable the "mod_rewrite" module: sudo a2enmod rewrite; sudo service apache2 restart