With WordPress being updated more frequently than ever with new security fixes and features it’s important to keep you site up to date with the lates version of WordPress.
Running one update is easy and quick enough but if you have a dozen or more WordPress sites on one server you can update them all at once with a very simple bash script.
This script can be used in one of two ways:
1: Setup the script and run it every time a new version of Wordpres is released
2: Setup a cron task to run the update weekly, this will mean you never have to worry about out of date versions of WP ever again.
It works by using wget to download the latest version and unzip it’s files to each of your WordPress installs.
wget -q http://wordpress.org/latest.tar.gz -O /var/www/latest.tar.gz;
tar -C /var/www/ -zxf /var/www/latest.tar.gz;
cp -r /var/www/wordpress/* /var/www/example.com/htdocs;
cp -r /var/www/wordpress/* /var/www/example.co.uk/htdocs;
cp -r /var/www/wordpress/* /var/www/test.com/htdocs;
Note: If all the sites on your server are running WordPress you could replace the individual cp lines with a loop to go through folders but to keep it simple and stop errors I’ve put a line in for each WP site.
Websites never sleep but you may want to, this script lets you do that without having to worry about Apache or Mysql crashing randomly.
Obviously if you have reoccurring issues its best to check through the log files and fix any issues but this will help reduce down time on vital software crashes to less than a minute by checking for Apache and Mysql services running and if none are found they get restarted.
Save this into a .sh file somewhere on your server and run this every minute usinng the built in Ubuntu Cron. If you are using a different OS and this doesn’t work replace the restart commands.
# APACHE SECTION
if [ $? -ne 0 ]
# MYSQL SECTION
if [ $? -ne 0 ]
To improve this script you could add email notifications and other vital services like sendmail which if they go down may be less apparent.
Working with Ubuntu or any other Linux distribution you really do learn something new every day. Yesterday one of my servers looked like Apache had Crashed.
- Loading a web page wont return a 404 or 500 error just a blank page
- Restarting Apache will help for a minute or two
- It’s a reoccurring issue
- Happens when you have large spikes in traffic
Like most things in Linux it’s an easy fix as long as you know where to look.
To double check this is the issue load up the Apache Log, in Ubuntu it’s /var/log/apache2/error.log
You should see something like :
[Sat Jun 25 14:14:17 2011] [error] server reached MaxClients setting, consider raising the MaxClients setting
To resolve this issue go to /etc/apache2/apache2.conf and change the MaxClients settings from to a higher number. By default it’s 10 and I would recommend changing it to about 30+ if it’s shutting down at 10 requests. You will also need to restart Apache after you change the setting.
More information from Apache on MaxClients