Friday, November 25, 2016

Fix for when you can't get Wordpress to self-update



WordPress is awesome - but if sometimes the damn thing just won't update and wants your FTP credentials, which normally don't exist since it's not 1995.  You can untar from the console over the top, normally - but I'm leery of doing stuff like that and causing even more trouble potentially.

First thing to check would be setting (or resetting) the permissions and making sure the upgrade directory is really there (it doesn't exist in the release file).  Here's a cut'n'paste for setting them assuming you are using www-data as the Apache user.


mkdir -p /var/www/html/wp-content/upgrade
sudo chown -R www-data:www-data /var/www/html
sudo find /var/www/html -type d -exec chmod g+s {} \;
sudo chmod g+w /var/www/html/wp-content
sudo chmod -R g+w /var/www/html/wp-content/themes
sudo chmod -R g+w /var/www/html/wp-content/plugins

Try it again - it should work.  If it doesn't - you have an option that should almost all of the time.  You can add this line to the wp-config.php file:

define('FS_METHOD', 'direct');

That line tells WordPress to just shut up and upgrade and stop complaining about whatever it's not liking in the file system.  If you are on a hosting container like Digital Ocean or a VPS - you're fine, but this can cause problems on shared hosting.  Cheap shared hosting is fine for most stuff - but since everyone is sharing the same web server (usually there's hundreds of blogs or whatever on a single physical server) and the web server owns all the hosted files - somebody else on the same host can take over your web site pretty easy with a few lines of PHP.

<?php
$file=fopen("/var/www/html/ilovecats.com/index.php", "w" );
fwrite($file, "<html><body><h1>I smell like butt!</h1></body></html>");
fclose($file);
?>

If you aren't sure and need to use FS_METHOD - add it in, upgrade, and remove it right away.

If you are on shared hosting still and want to try Digital Ocean - this link will get you $10 credit and a few pennies for me.   :-P


No comments:

Post a Comment