Skip to content

wordpress

Quick install Wordpress

curl -O https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
cp -a wordpress/. /var/www/wordpress
chown -R www-data:www-data /var/www/wordpress
find /var/www/wordpress/ -type d -exec chmod 750 {} \;
find /var/www/wordpress/ -type f -exec chmod 640 {} \;

Wordpress install wp utility

sudo -u www-data curl -L https://raw.github.com/wp-cli/builds/gh-pages/phar/wp-cli.phar > wp-cli.phar
sudo -u www-data php wp-cli.phar --info
chmod +x wp-cli.phar
mv wp-cli.phar /usr/bin/wp

Wordpress secure wp-cron.php

The WordPress WP-Cron is used to run scheduled tasks within WordPress core, as well as plugins such as WooCommerce.

The WordPress WP-Cron will run on each page visit by a visitor, this can result in the WP-Cron running multiple times on busy sites and con under up slowing down

  • Disable the WordPress WP-Cron From Running on Page Visits
    This is required, and simple edit of your wp-config.php. Locate the following line below, and change it from false to true. You may not have it in your wp-config.php; simply add it above the line “/ That's all, stop editing! Happy publishing. /“.

    define('DISABLE_WP_CRON', 'true');
    

  • Find wp-cron.php path on your wordpress machine

    find /var/www/ -name 'wp-config.php'
    

  • Run wp-cron automatically: -- Create cron job file on wordpress machine:
    touch /etc/cron.d/wp-cron
    chown root:root /etc/cron.d/wp-cron
    
    -- Populate cron job file (either of the two options):
    --- Direct call
    PATH=/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    MAILTO=wpadmin@email.com
    */5 * * * * www-data /usr/bin/php -q /var/www/path/to/wp-cron.php
    
    -- Using wp utility
    WP-CLI (WP Command Line Interface) is command line for WordPress.
    sudo -u www-data curl -L https://raw.github.com/wp-cli/builds/gh-pages/phar/wp-cli.phar > wp-cli.phar
    sudo -u www-data php wp-cli.phar --info
    chmod +x wp-cli.phar
    mv wp-cli.phar /usr/bin/wp
    
    PATH=/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    MAILTO=wpadmin@email.com
    */5 * * * * www-data wp --path=/var/www/path/to/wordpress cron event run --due-now
    
  • Restrict web server access to wp-cron.php
    F.x. nginx location config
    location = /wp-cron.php {
        allow 127.0.0.1/8;
        deny all;
        include fastcgi_params;
        fastcgi_intercept_errors on;
        fastcgi_pass php;
        fastcgi_buffers 16 16k; 
        fastcgi_buffer_size 32k;
        #The following parameter can be also included in fastcgi_params file
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
    

https://managingwp.io/2021/08/27/replacing-wordpress-wp-cron-with-manual-cron-url-and-php-method/