Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS /

Static publisher, getting it to work (2.4) need help


Reply


5 Posts   2476 Views

Avatar
TF-35Lightning

Community Member, 137 Posts

13 May 2010 at 5:21pm

Edited: 13/05/2010 5:23pm

Hi all,

I am trying to get the static publisher to work, this is my first time trying to run it.

I have followed http://doc.silverstripe.org/staticpublisher
and are using the Single server Caching technique.

These are the things I have done.

1/ mysite/_config.php - added
Object::add_extension("SiteTree", "FilesystemPublisher('cache/', 'html')");

2/ .htaccess replaced
RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]
with
RewriteRule .* sapphire/static-main.php?url=%1&%{QUERY_STRING} [L]

3/ Have added the below to the Page.php class file

// class Page extends SiteTree { stays here is the start of a default class
class Page extends SiteTree {

   public static $db = array(
   );

   public static $has_one = array(
   );
   
   
// page classes for static publisher added by t

/**
* Return a list of all the pages to cache
*/
function allPagesToCache() {
// Get each page type to define its sub-urls
$urls = array();

// memory intensive depending on number of pages
$pages = DataObject::get("SiteTree");

foreach($pages as $page) {
$urls = array_merge($urls, (array)$page->subPagesToCache());
}

// add any custom URLs which are not SiteTree instances
$urls[] = "sitemap.xml";

return $urls;
}

/**
* Get a list of URLs to cache related to this page
*/
function subPagesToCache() {
$urls = array();

// add current page
$urls[] = $this->Link();

// cache the RSS feed if comments are enabled
if ($this->ProvideComments) {
$urls[] = Director::absoluteBaseURL() . "pagecomment/rss/" . $this->ID;
}

return $urls;
}

function pagesAffectedByChanges() {
$urls = $this->subPagesToCache();
if($p = $this->Parent) $urls = array_merge((array)$urls, (array)$p->subPagesToCache());
return $urls;
}

4/ Run /dev/buildcache?flush=1

which then gives me:

ebuilding cache.
NOTE: Please ensure that this page ends with 'Done!' - if not, then something may have gone wrong.

Removing stale cache files...
done.

Rebuilding cache from 5 urls...

FilesystemPublisher: Publishing to
* Publishing page 1/5: /silverstripe/silverstripe-v2.4.0
* Publishing page 2/5: /silverstripe/silverstripe-v2.4.0/about-us
* Publishing page 3/5: /silverstripe/silverstripe-v2.4.0/contact-us
* Publishing page 4/5: /silverstripe/silverstripe-v2.4.0/page-not-found
* Publishing page 5/5: sitemap.xml
Rebuilding cache.
NOTE: Please ensure that this page ends with 'Done!' - if not, then something may have gone wrong.

There already appears to be a publishing queue running. You can skip warning this by adding ?/&force to the URL.

5/ I then try access the main silverstripe site and I get these error messages at the top of the page

Notice: Use of undefined constant BASE_URL - assumed 'BASE_URL' in F:\wamp\www\silverstripe\silverstripe-v2.4.0\sapphire\static-main.php on line 52

6/ I've checked the cache folders and there is definatley no html file there.

Any help would be great

Avatar
Pigeon

Community Member, 243 Posts

14 May 2010 at 8:13pm

Hi,

I think you are getting a little bit confused between static publisher and 2.4s new caching (which dynamically caches parts of pages).

For static publisher see: http://doc.silverstripe.org/staticpublisher

You will need an .htaccess file like this: http://open.silverstripe.org/browser/modules/cms/trunk/code/staticpublisher/htaccess_example_rsyncsingleserver

This forum post might help you too: http://www.silverstripe.org/customising-the-cms/show/263772?start=0#post263776

Avatar
TF-35Lightning

Community Member, 137 Posts

14 May 2010 at 10:35pm

Hi Pigeon thanks for the reply so staticpublisher and Single server Caching are completly seperate things???

Avatar
TF-35Lightning

Community Member, 137 Posts

17 May 2010 at 5:02pm

Pigeon can I please have a look at your htaccess file if you have done what I am trying to do?

I tried using a .htaccess file such as:

### SILVERSTRIPE START ###
RewriteEngine On
RewriteBase /silverstripe/silverstripe-v2.4.0
   
## CONFIG FOR DEV ENVIRONMENTS
   
# Cached content - **sitedir** subdirectory
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{REQUEST_URI} ^/silverstripe-v2.4.0/(.*)$
RewriteCond %{REQUEST_URI} /silverstripe-v2.4.0/(.*[^/])/?$
RewriteCond %{DOCUMENT_ROOT}/silverstripe-v2.4.0/cache/%1.html -f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /silverstripe-v2.4.0/cache/%1.html [L]
   
# Cached content - homepage
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{REQUEST_URI} ^/silverstripe-v2.4.0/?$
RewriteCond /silverstripe-v2.4.0/cache/index.html -f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /silverstripe-v2.4.0/cache/index.html [L]
         
###Original line here, I commented it out for static publisher ###
#RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]

RewriteRule .* sapphire/static-main.php?url=%1&%{QUERY_STRING} [L] ###
   

### SILVERSTRIPE END ###

When I do a buildcache?flush=1 it says it has built the cache but no files are showing in the cache etc and I can't click anywhere.

My silverstripe directory is silverstripe-v2.4.0
physical.
E:\wamp\www\silverstripe\silverstripe-v2.4.0

I access it in browser from http://localhost/silverstripe/silverstripe-v2.4.0/

Thought it might have been been something to do with pathing but tested it and appears not to be, must be something to do with how I have my file setup.

Any help would be great

Avatar
Pigeon

Community Member, 243 Posts

18 May 2010 at 8:46pm

Edited: 18/05/2010 8:47pm

My .htaccess looks like this:

### SILVERSTRIPE START ###
<Files *.ss>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Files>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

## CONFIG FOR TEST/LIVE ENVIRONMENTS

# Cached content - live webserver
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{REQUEST_URI} /(.*[^/])/?$
RewriteCond %{DOCUMENT_ROOT}/cache/%1.html -f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /cache/%1.html [L]

# Cached content - homepage
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{REQUEST_URI} ^/?$
RewriteCond %{DOCUMENT_ROOT}/cache/index.html -f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /cache/index.html [L]

### Dynamic ###
RewriteCond %{REQUEST_URI} !(\.gif$)|(\.jpg$)|(\.png$)|(\.css$)|(\.js$)|(\.php$)

RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]
</IfModule>
### SILVERSTRIPE END ###

Make sure that chache is writable. You can test the .htaccess is working by adding a .html file there (eg: test.html) and then navigating to domain.com/test/ and see if it loads the html file. if it does, then your issue is with the cache being written, not the htaccess rule