WARNING! BACKUP YOUR MACHINE! UNTESTED!

before running this script change to your new web root: /home/UserName/web/domain.com/public_html

then run it like /scripts/install_wordpress.sh

it tries to:

  • download and unpack the latest wordpress into the current directory
  • disable xmlrpc.php
  • disable wp-cron.php

requirements:

  • a script called /scripts/wp-cron.sh exists and is set to executable (chmod +x /scripts/*.sh) that is run every hour by cron under the account of UserName
    • 0 * * * * /scripts/wp-cron.sh # run every hour

You might to want to copy and paste line by line into terminal, and test if it does what you want.

also make sure to change UserName: /home/UserName/web/domain.com/public_html

cat /scripts/install_wordpress.sh
#!/bin/bash
echo "================ installing latest wordpress into current directory";
echo "... i expect you are in domain.com/public_html";

echo "try to find domain name";
parentdir="$(dirname "$PWD")";
DOMAIN=$(basename $parentdir);
echo "domain name should be:"$DOMAIN;

echo "cleaning current directory and downloading latest wordpress.org/latest/.tar.gz";
rm -rf index.html;
rm -rf latest*;
wget https://wordpress.org/latest.tar.gz;

echo "unpacking"
tar fxvz latest.tar.gz;
mv ./wordpress/* ./;
rm -rf latest.tar.gz wordpress;

echo "setting user-rights"
chown -R UserName:UserName /home/UserName/web/ &

echo "disable xmlrpc.php by renaming to xmlrpc.php.disabled"
mv -v xmlrpc.php xmlrpc.php.disabled

echo "disable wp-cron.php in wp-cron.php";
# especially this part you probably want to test-run
# find . -type f -name wp-config.php -exec sed -i.bak 's/define(\x27DB_COLLATE\x27, \x27\x27);/define(\x27DB_COLLATE\x27, \x27\x27); define(\x27DISABLE_WP_CRON\x27, true);/g' {} \;
# find . -type f -name wp-config.php.bak -delete

echo "adding entry for $DOMAIN to /scripts/wp-cron.sh";
echo "/usr/bin/php /home/UserName/web/$DOMAIN/public_html/wp-cron.php >/dev/null 2>&1" >> /scripts/wp-cron.sh;
admin