• Home
    • Cool Knowledge base
    • Light Knowledge base
    • Help Desk
    • OnePage Documentation
  • Services
    • Main Services
    • PPC Services
    • SEO Services
    • SMM Services
  • Docs
  • Blog
    • Affiliate
    • Ecommerce
    • Frontend
    • linux
      • nginx
    • PHP
      • Magento
      • wordpress
    • Python
    • SEO
    • Web
  • Forum
    • Forums
    • Forum Topics
    • Topic Details
    • Ask Question
  • Pages
  • Contact

Subscribe to Updates

Get the latest creative news from FooBar about art, design and business.

What's Hot

VideoJS – multiple source demo

2022-03-08

Add custom field to Woocommerce tab

2022-03-07

Surror Product Tabs for WooCommerce

2022-03-07
Facebook Twitter Instagram
  • 中文
  • English
Facebook Twitter Instagram Pinterest VKontakte
SEO & Website build tips SEO & Website build tips
  • Home
    • Cool Knowledge base
    • Light Knowledge base
    • Help Desk
    • OnePage Documentation
  • Services
    • Main Services
    • PPC Services
    • SEO Services
    • SMM Services
  • Docs
  • Blog
    • Affiliate
    • Ecommerce
    • Frontend
    • linux
      • nginx
    • PHP
      • Magento
      • wordpress
    • Python
    • SEO
    • Web
  • Forum
    • Forums
    • Forum Topics
    • Topic Details
    • Ask Question
  • Pages
  • Contact
SEO & Website build tips SEO & Website build tips
Home»wordpress»WordPress generate static website
wordpress

WordPress generate static website

OxfordBy Oxford2020-11-23Updated:2021-02-05No Comments5 Mins Read
Facebook Twitter Pinterest LinkedIn Tumblr Email
Share
Facebook Twitter LinkedIn Pinterest Email

https://wp2static.com/developers/wp-cli/

 

WP-CLI

 

WP-CLI is a developer-friendly way to manage WordPress sites. WP2Static integrates with WP-CLI, adding useful commands to generate and deploy your static site.

WP-CLI commands

Running the command wp wp2static will give you all the avaiable options and is the best way to know which commands are available on your system. WP2Static Add-ons may provide additional commands.

WP-CLI commands will apply to the site relative to the system path you run them from.

System user when running WP-CLI

TL;DR – run wp commands as the same user as your webserver

When WP-CLI runs, it will likely be using the system default PHP, which executes in a different environment than when accessing your WP site via the webserver. This means that the PHP configuration is likely pulled from a php.ini vs a php-fpm.conf type file, so check you have any webserver environment customizations you need also in your CLI PHP environment.

It also means that when you run the wp command from the CLI, you’ll be doing so as the currently logged in user, unless specified otherwise. For WP2Static and other plugins which touch files on the webserver, this can lead to issues with file permissions, ie – mylocaluser runs wp wp2static generate, which sets files with ownership of mylocaluser, but then when you perform an action via the webserver, your webserver user (www, www-data, etc) may not have permissions to use those files, resulting in unexpected errors.

To change the user who runs wp commands:

OpenBSD

Edit your /etc/doas.conf file, adding a line:

permit persist MYUSERNAME as www cmd wp

You may then choose to alias the command for easier usage. In your ~/.profile:

alias wp='doas -u www wp'

Alternatively, configure your web root to be owned by {MY_USER}:www and be group-writable, then you may run wp as your regular user.

Linux/macOS/Windows

Try something similar with sudo -u www wp or runas /noprofile /user:mymachine\www wp. Let us know what works and we’ll update this doc.

Multisite WP2Static WP-CLI commands

When running WordPress in a Network/Multisite setup, add the --url=<url> argument to force the command to be applied to the WordPress site with that Site URL.

Undefined environment variables when running WP-CLI commands

  • $_SERVER['SERVER_NAME']
  • $_SERVER['HTTP_HOST']
  • $_SERVER['DOCUMENT_ROOT']

You may need to override these in your /wp-config.php file to get identical behaviour when executing WP2Static commands via WP-CLI vs from within the WordPress web application.

WP-CLI examples


Quickstart: Install and activate WP2Static, set deployment URL and generate static site

  • wp plugin install --activate static-html-output-plugin
  • wp wp2static options set deploymentURL https://example.com
  • wp wp2static detect
  • wp wp2static crawl
  • wp wp2static post_process

Your static site will now be available at wp-content/uploads/wp2static-processed-site.

Note: the plugin’s slug, as used within the official wp.org repo is static-html-output-plugin, not wp2static. Because, reasons.


Quickstart: Generate static site and deploy using Netlify CLI tool

This is a good option for very large sites deploying to Netlify, as only changes will be deployed each time.

  • wp wp2static options set deploymentURL https://example.com
  • wp wp2static detect
  • wp wp2static crawl
  • wp wp2static post_process
  • cd wp-content/uploads/wp2static-processed-site
  • netlify deploy

The Netlify CLI will give you an interactive prompt to follow.


Quickstart: Generate static site and deploy via sFTP

Until there is a dedicated Add-on supporting sFTP, the following commands will work.

  • wp wp2static options set deploymentURL https://example.com
  • wp wp2static detect
  • wp wp2static crawl
  • wp wp2static post_process
  • scp -rp wp-content/uploads/wp2static-processed-site user@server:dest

Quickstart: Generate static site and deploy to CloudFlare Workers via Wrangler

Until there is a dedicated Add-on supporting CloudFlare workers, the following commands will work.

  • wp wp2static options set deploymentURL https://wp2staticv6test.wp2static.workers.dev/
  • wp wp2static detect
  • wp wp2static crawl
  • wp wp2static post_process
  • cp -r wp-content/uploads/wp2static-processed-site/* "$MY_WORKER_DIR"/public/
  • cd "$MY_WORKER_DIR"
  • wrangler publish

Above example expects you’ve installed CloudFlare’s Wrangler tool and run wrangler config and wrangler generate --site SITE_NAME. MY_WORKER_DIR above is to be replaced with the actual directory you created with wrangler generate.

Your wrangler.toml will look similar to this:

name = "wp2staticv6test"
type = "webpack"
account_id = "0a5e6f4c0d8a4e4cb4dd08d29e99ddcc"
workers_dev = true

[site]
bucket = "./public"

This example shows how to deploy to your workers.dev domain. Additional configuration is required to deploy to your own domain name. To be updated.

WP2Static Core CLI commands explained

detect

Detects URLs within WordPress site to be used in crawling. Detection levels controlled by core options and any optional detection add-ons.

  • wp wp2static detect

Detected URLs go into WP2Static’s Crawl Queue.

  • wp wp2static crawl_queue count # get total number of detected URLs
  • wp wp2static crawl_queue list # list all detected URLs
  • wp wp2static crawl_queue delete # clear Crawl Queue

crawl

Crawls all URLs in the Crawl Queue, generating a static site, identical to your WordPress site, but with URLs like /some-post/ generating static site compatible folder called /some-post/, containing an index.html file within.

  • wp wp2static crawl

Generates static site to wp-content/uploads/wp2static-crawled-site.

Crawl Cache is used to prevent having to re-crawl URLs which haven’t changed.

  • wp wp2static crawl_cache count # get total number of cached crawl URLs
  • wp wp2static crawl_cache list # list cached crawl URLs
  • wp wp2static crawl_cache delete # rm wp-content/uploads/wp2static-crawled-site

post_process

Processes the crawled site, rewriting URLs and optionally performing other actions to prepare static site for deployment.

  • wp wp2static post_process

Generates deployable static site files to wp-content/uploads/wp2static-processed-site.

deploy

Triggers a deployment, which signals to any deployment add-ons to perform their specific deployment actions.

  • wp wp2static deploy

Triggers post-deployment actions on completion, such as email or webhook notifications.

process_queue

This will check for any queued jobs with the ‘waiting’ status and process them.

  • wp wp2static process_queue

This is useful when you want to rely on regular CRON job than WP-Cron.

 

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
Avatar photo
Oxford

Related Posts

Add custom field to Woocommerce tab

2022-03-07

Surror Product Tabs for WooCommerce

2022-03-07

make wordpress static with gatsby

2021-09-29

WP Remote Users Sync – manage multi wordpress website easy

2021-08-01
Recent Posts
  • VideoJS – multiple source demo
  • Add custom field to Woocommerce tab
  • Surror Product Tabs for WooCommerce
  • How To Scrape Amazon at Scale With Python Scrapy, And Never Get Banned
  • Compile a Jekyll project without installing Jekyll or Ruby by using Docker
November 2020
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct   Jan »
Tags
app branding culture design digital Docly docs etc faq fashion featured fitness fix github Helpdesk Image issue leisure lifestyle magento Manual marketing memecached Photography picks planing seo sequrity tips Travel trending ui/ux web WordPress 爬虫
Editors Picks

Fujifilm’s 102-Megapixel Camera is the Size of a Typical DSLR

2021-01-05
Top Reviews
8.9

Which LED Lights for Nail Salon Safe? Comparison of Major Brands

By Oxford
8.9

Review: Xiaomi’s New Loudspeakers for Hi-fi and Home Cinema Systems

By Oxford
70

CES 2021 Highlights: 79 Top Photos, Products, and Much More

By Oxford
Advertisement
Demo
  • Facebook
  • Twitter
  • Instagram
  • Pinterest
About Us
About Us

Your source for the lifestyle news. This demo is crafted specifically to exhibit the use of the theme as a lifestyle site. Visit our main page for more demos.

We're accepting new partnerships right now.

Email Us: [email protected]
Contact: +1-320-0123-451

Facebook Twitter Instagram Pinterest YouTube LinkedIn
Recent Posts
  • VideoJS – multiple source demo
  • Add custom field to Woocommerce tab
  • Surror Product Tabs for WooCommerce
  • How To Scrape Amazon at Scale With Python Scrapy, And Never Get Banned
  • Compile a Jekyll project without installing Jekyll or Ruby by using Docker
From Flickr
Ascend
terns
casual
riders on the storm
chairman
mood
monument
liquid cancer
blue
basement
ditch
stars
© 2025 Designed by 九号资源网.

Type above and press Enter to search. Press Esc to cancel.