Fixing broken wordpress uploads folders, Even on shared hosting for many sites.
by Chris Walker on Apr.21, 2010,under Technical, How To, Programming, Bash Scripting, General, Skills, Portfolio, Automation, Linux, Unix, Software, Wordpress, Plesk
Wordpress Cron script
These scripts can be accessed from http://svn.devnetonline.net/BashScripts/wordpress/
User: guest Pass: NO PASSWORD [that means empty password]
[script] wp-cron
This script is the basis from which this is all handled. This script takes upto 6 different arguments, most of these are not needed unless this script is being run on a different system than it normally would be, in which case the script should be adjusted (the top 20 lines are about all that needs to be fixed usually). Unless you pipe this to /dev/null {wp-cron [args] >/dev/null you will see information about each domain being worked on.
arguments:
--domain domain.tld
--content blog/wp-content/uploads/
--user theuser
--perms 775
--group www-data
--wpath /httpdocs/
The domain argument is absolutely required. everything else can be assumed by the defaults within the script itself. Note that the above variables are not the defaults that are in the file.
default variables:
--content wp-content/uploads/
--user nobody
--perms 777
--group nobody
--wpath /httpdocs/
[VHOSTPATH]: This path is the location of all domain folders. by default, we assume your vhosts are in /var/www/vhosts/, there is no option for this variable at runtime.
As this script runs, it assembles the information to check [VHOSTPATH][--domain][--wpath][--content][&YEAR&]/[&MONTH&] (this becomes a path like /var/www/vhosts/mydomain.tld/httpdocs/blog/wp-content/uploads/2010/04/). If the content folder does not exist, nothing happens. If it does, the year and month folders will be created if they do not exist.
The wp-cron script can be executed on its own, or you may use the information below to setup a crontab to do many sites at the same time.
[script] wp-crontab-command
This script is not actually a script, but the information that needs to be used to execute this on multiple domains at once, without installing a new crontab for each domain/user/wordpress. To set this up, copy the contents of this file into crontab. Specify the time for crontab when you do this as well.. For usability, we will set crontab to run this at 12:04am, on the first of the month, every month.
4 0 1 * * [data in wp-crontab-command]
This script/file also requires one other item to run for multiple domains. Note that you may need to modify the information that you place on the crontab, depending on where you leave these scripts and the file required to use the crontab command.
[file] wp-domains.txt
In this file, you will place a list of commands to be executed. Each line is a single execution for a wordpress site/blog. [note that below, some of these lines take multiple lines. please be aware that each site/blog should have 1 line.
example: --domain mydomain.tld --wpath /httpdocs/blog/ --user myname --group www-user --content notstandard/uploads/
--domain myotherdomain.tld --wpath /specialwebsite/ --user joeuser
--domain anewdomain.tld --content blog/wp-content/uploads/ --user theuser
The most common example would be the last of these 3. Each line can take all 6 options, and will apply to that domains wordpress only. Without editing the wp-crontab-command entry, this file should be placed in /root/ as 'wp-domains.txt'. The wp-cron script should be placed in /root/bin [if this bin/ folder does not exist, create it, of course]. The wp-crontab-command is only there for reference of the crontab command, and to additionally force an execution of the months folders if the crontab fails.
If this script does ever fail, run the wp-crontab-command contents without piping to /dev/null.
Thats it.. Please note, if you do decide to mess with these files, that the wp-cron script is pretty ugly for the first million lines (there arent that many, but its long) to parse options. If a better way can be found let me know, or I find a better I will update this script. you may svn up the url above at any time to get the latest version.
Pages: 1 · 2

5 comments
This post has 3 feedbacks awaiting moderation...
Leave a comment