Using WordPress With Static Webspace

This website jsteeb.de is hosted on a static webspace – it does not run PHP scripts, just HTML files. But the website is built using WordPress, and WordPress needs PHP. How can this work?

The idea:

  1. run WordPress on a local machine (Kubuntu Linux PC running the Apache web server with PHP).
  2. on the local machine, create static pages using wget (command line tool)
  3. upload the static pages to the web server using ftp

WordPress On A Local Machine

To start with, this is a normal WordPress installation. But I moved wp-content out of the rest of WordPress.

Folder Structure

So the folder structure is:

makefile           Makefile that supports the workflow
impl/wordpress     The original WordPress installation.
impl/wp-content    Some WordPress adaptations
impl/wp-content/plugins/jsteeb/cleanup.php
                   Get rid of some dynamic WordPress functionality
pub/               The local static pages.

Cleanup

Since the uploaded version is HTML only, no PHP, any dynamic WordPress functionality can be dropped. As an example, a search box or a post comment box do not make sense, since there is no PHP script that could process the user input.

On the local machine, a PHP file cleanup.php (zipped) drops the dynamic functionality. It also includes a specific CSS file which hides some WordPress parts (search box)

  #comments
, .site-info a
, form.search-form
{
  display: none !important;
}

and it removes the WordPress version number from links.

Create Static Pages

On the command line, I run “make pub” to create the static pages. The makefile reads:

PUB=pub

# 2014-01-06 HS:
# cannot use
#   --restrict-file-names=windows
# because if links in HTML contain "@", the links will not match.
#
# 2014-01-13 HS:
# to show images created by WordPress but not actually referenced in static pages:
#   diff -r impl/wp-content/uploads/ pub/wp-content/uploads/

pub:
	PUB=pub  
	rm -rf $(PUB)/*
	cp impl/.htaccess-server $(PUB)/.htaccess
	(wget --recursive --convert-links --page-requisites --no-host-directories --directory-prefix $(PUB) http://jsteeb.local) || true
	cp pub_robots.txt pub/robots.txt
	@find pub -name '*\?*' || echo "ERROR: file name contains ? symbol - adapt makefile!"

The task copies a special .htaccess file, which contains redirects for some old URLs that I still want to support, like

RewriteRule ^losung/DEgreeting.803.htm         freeware-losungsprogramme/ubersicht-losung-de/

It then uses the wget command with specific parameters to create the static pages in the pub/ subfolder. The task also copies a specific robots.txt for the server. Finally, it checks that no file remains having a question mark in the file name. Such a file name might be created by wget from a link like http://jsteeb.local?ver=123, and some operating systems do not like “?” in file names. The cleanup.php should suppress such version numbers in links, but… be defensive.

Upload Static Pages To The Server

Another makefile target make server copies the static pages from pub/ to the webspace, using ftp:

.PHONY: server
server:
	lftp -c "set ftp:list-options -a;\
	open ftp://user:pass@jsteeb.de;\
	lcd ./pub;\
	mirror --reverse --delete --use-cache --verbose --only-newer --dereference --allow-chown --allow-suid --no-umask --parallel=2 --exclude-glob logs/ --exclude-glob private/"

I first tried using rsync on a folder mounted via ftp (see some info about this), but gave up on error messages like

rsync: chgrp "/mnt/jsteeb/wp-content/themes/twentythirteen/js" failed: Operation not permitted (1)
rsync: mkstemp "/mnt/jsteeb/wp-content/themes/twentythirteen/images/.dotted-line-2x.png.RL2oWf" failed: Operation not supported

If you want to run WordPress on a server with static webspace only, I hope these tips are useful for you.

A drawback of the solution is: it re-creates and uploads all files with every modification of your site.

For questions or suggestions, just contact me.