WordPress Auto Upgrade

         · ·

Recent versions of WordPress have the ability to upgrade themselves at the click of a button. This has never seemed to work for me, instead it just asks for FTP credentials. I was told this was a permissions thing, that this is what happens if it permissions arent correct. So today I decided to look into it. Its really quite simple.

On a web server, the service runs under an account context – in my case the account is apache. Now all the files in the root of my WordPress folder are owned by root, and only root can write to them. So this is why auto-upgrade doesnt work. Changing the ownership of these files to be Apache would fix it. However, this means that if ever Apache is attacked and breaks giving the user access as the apache user, he would have read-right access. Its a pretty unlikely scenario I know but hey, call me paranoid

If you want your WordPress to be autoupgradable, you simple need to change the ownership of the wordpress files to apache so that the webserver has read/write access.

Ive decided to come up with two scripts, one that is run before the upgrade, that changes the ownership to apache and one that runs after the upgrade to change the ownership back. Its really very simple, so here they are

Before upgrade

chown apache:apache /var/www/html

chown apache:apache /var/www/html/readme.html

chown apache:apache /var/www/html/index.php

chown apache:apache /var/www/html/license.txt

chown apache:apache /var/www/html/xmlrpc.php

chown -R  apache:apache /var/www/html/wp-content/

chown -R  apache:apache /var/www/html/wp-includes/

chown -R  apache:apache /var/www/html/wp-admin/

chown apache:apache /var/www/html/wp-*

chown root:root /var/www/html
chown root:root /var/www/html/readme.html
chown root:root /var/www/html/index.php
chown root:root /var/www/html/license.txt
chown root:root /var/www/html/xmlrpc.php
chown -R  root:root /var/www/html/wp-content/
chown -R  root:root /var/www/html/wp-includes/
chown -R  root:root /var/www/html/wp-admin/
chown root:root /var/www/html/wp-*
Post upgrade

chown root:root /var/www/html

chown root:root /var/www/html/readme.html

chown root:root /var/www/html/index.php

chown root:root /var/www/html/license.txt

chown root:root /var/www/html/xmlrpc.php

chown -R  root:root /var/www/html/wp-content/

chown -R  root:root /var/www/html/wp-includes/

chown -R  root:root /var/www/html/wp-admin/

chown root:root /var/www/html/wp-*

Its probably not really necessary but it feels better this way :-)

Please note, my WordPress files are in the root folder, not in “wordpress” or “blog”, so you will need to adapt the above for your own case

OSG

comments powered by Disqus