Przejdź na skróty do treści. | Przejdź do nawigacji
Deploying Plone site to static files
Shows how to dump site build with Plone to static website (HTML, CSS, JS, images, etc.).
Introduction
Deploying Plone site to static files has the following advantages:
- Security: You can run Plone internally, and possibly on a less robust/costly server, since it will only be used by internal content managers. You could then export your published site content in its static form (.html, .css, .jpg, .swf, .pdf files, etc.) and deploy that static site easily to either a very affordable, simple shared HTML site hosting plan, or a massively scalable, load-balanced web server environment for larger organizations.
- Scalability: Since the published site is static HTML, CSS, images, etc., with no database backend to have to connect to or dynamic scripting engine needed to transform the content as a page is requested, the site is served up much faster and the deployment environment is more stable due to fewer moving parts (no database, no scripting engine, etc.) Demands on server CPU and RAM can be greatly reduced.
- Flexible Hosting Options: You can run Plone on your laptop, export your static site as simple HTML, CSS, JavaScript, and image files, and deploy to a $5/month plan shared hosting environment. Or, you can put your entire published site onto a thumb drive to carry around with you. Your entire site could be served from memory (cache the static HTML and other files), since no database is needed for the published site to run. There's no need to buy a Plone-centric hosting plan in this scenario.
- It's Achievable!: There are a few sites out there using the CMFDeployment add-on tool for Zope/Plone. This is the low-hanging fruit, but we shouldn't paint ourselves into a corner if there is a better approach. Entransit may be another option, but to-date, this tool allows for exporting to a relational DB or possibly XML, but not HTML at the moment. [1]
- I know about two packages that can deploy Plone site to static files:
In this article I will show how to install, configure and use stxnext.staticdeployment.
Domains
In my previous blog entry I described how to configure frontend and backend domains. In site with static deployment there are three domains:
- backend - for editors to edit content (default Plone skin)
- preview - for editors to immediately see changes is content (custom skin)
- frontend - for visitors (custom skin)
Frontend domain is served by apache mainly from static files, but some of requests (e.g. submits of forms) are forwarded to Plone.
Installation
Edit buildout.cfg and append stxnext.staticdeployment to eggs and zcml parameters in instance section:
[instance] eggs = ... stxnext.staticdeployment zcml = ... stxnext.staticdeployment
Instance must be rebuild and restarted:
./bin/buildout ./bin/instance stop ./bin/instance start
This product must be also installed inside Plone site. Do do it, go to Site Setup -> Add/Remove Products, select checkbox near stxnext.staticdeployment and click Install button.
Configuration
Every website has own configuration (different set of eggs, skin, products etc.) - this I meas as project. But website can have few instances (development, test and production instances). Because of this, configuration is split for two parts:
- instance parameters:
- parameters connected to instance - e.g.: domain
- configured in Control Panel - can be edited throw the web (Site Setup -> Static deployment -> Settings tab)
- form has description and validation - can be used by less experienced users
- website parameters:
- stored in INI file
- created by developer of website
- can be used by many sites
- default configuration (included in egg)
- default configuration can be overriden by file ${buildout:directory}/etc/staticdeployment.ini
Frontend domain
Frontend domain must be configured in some special way. It will serve static files from disk, but if requested data do not exists in configured directory it will forward request to Plone. Similar all POST request should be also passed to Plone:
<VirtualHost *:80>
ServerName example.org
ServerAlias static.example.org
DocumentRoot /var/www/example.org/html
CustomLog /var/www/example.org/logs/access.log common
ErrorLog /var/www/example.org/logs/error.log
RewriteEngine on
RequestHeader append plone_skin "Notre Dame"
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}index.html !-f
RewriteRule ^/(.*) "http://localhost:8080/VirtualHostBase/http/%{SERVER_NAME}:80/site/++skin++Notre Dame/VirtualHostRoot/$1" [L,P]
## make rewrite on every POST requests
RewriteCond %{REQUEST_METHOD} ^POST$
RewriteRule ^/(.*) "http://localhost:8080/VirtualHostBase/http/%{SERVER_NAME}:80/site/++skin++Notre Dame/VirtualHostRoot/$1" [L,P]
</VirtualHost>
This is only basic configuration. It's very possible that list of circumstances (when content should be served from Plone not from files) will be bigger.
Deployment
When website is ready to deployment go to Site Setup -> Static deployment -> Deployment tab. Select Deploy static version of website checkbox and press Save button. Deployment will work for few seconds or minutes (it depends on size of website and server performance).
Summary
stxnext.staticdeployment v 0.3.1 is not fully functional (it will not dump whole website to static files). Some of pages can work not properly. Static files can't provide all functionalities that are in Plone (e.g. interface translation). But we use this module (with success) in few our projects, so we decided to release it under Open Source license. It can be base for bigger, better and faster solution.
| [1] | Plone Static Publishing project at CoActivate |


