Forum

URLToolkit Silverstripe CMS

Phil Daintree
5 November 2008, 11:44
I am trying to get the silverstripe CMS working under Hiawatha and it requires some rewriting of URLs and I guess it can be done with the URL toolkit but I don't understand enough about the rules under apache to translate apache rules to Hiawatha URL toolkit rules - appreciate any help? The apache .htaccess file shows:

### SILVERSTRIPE START ###
RewriteEngine On
RewriteBase /silverstripe

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]
### SILVERSTRIPE END ###

What should the URLToolkit rules look like?
Really lost here ... appreciate any pointers.

Thanks
Hugo Leisink
5 November 2008, 12:12
Since I don't have Silverstripe installed, I can't test it. But I think your rule would look like this:
VirtualHost {
...
UseToolkit = silverstripe
}

UrlToolkit {
ToolkitID = silverstripe
Match (\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php) Return
RequestURI exists Return
Match ^(/silverstripe/.*)\?(.*) Rewrite $1&$2 Continue
Match ^/silverstripe/(.*) /silverstripe/sapphire/main.php?url=$1
}


I don't know exactly what RewriteBase does, so its usage is a wild guess. Ask an Apache expert about that one. If the rule doesn't work, please let me know. Then I'll look into it a little further.
Phil Daintree
6 November 2008, 11:17
Thanks Hugo... unfortunately I am using 6.7 so I doctored for the URLRewrite changes - pre-URLToolkit, I have got past a number of "Syntax error in httpd.conf" but the re-writing is not doing the necessary for silverstripe.

I have:
UrlRewrite {
RewriteID = silverstripe
Match (\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php) Return
RequestURI exists Return
Match ^(/silverstripe/.*)\?(.*) Rewrite $1&$2
Match ^/silverstripe/(.*) Rewrite /silverstripe/sapphire/main.php?url=$1
}


and the

VirtualHost {
Hostname = localhost
WebsiteRoot = /root/httpd/hiawatha/silverstripe
StartFile = index.php
FastCGI = PHP5
RewriteUrl = silverstripe
}


I checked also the silverstripe forums where someone has got lighthttpd going with some tricky rewriting -

http://www.silverstripe.com/site-builders-forum/flat/3048?showPost=32814

using the line:

url.rewrite-once = (
"(?i)(/.*\.(jpe?g|JPE?G|png|PNG|css|CSS|js|JS|gif|GIF|php|PHP|x?html?|X?HTML?))(.*?)$" => "$0",
"^/(.*?)(\?|$)(.*)" => "/sapphire/main.php?url=$1&$3"
)


Sorry to be a dummy - thanks so much for your help!
Phil Daintree
6 November 2008, 11:26
So I also tried :

UrlRewrite {
RewriteID = phil
# Match ^/(.*?)(\?|$)(.*) Rewrite /sapphire/main.php?url=$1&$3
Match (?i)(/.*\.(jpe?g|JPE?G|png|PNG|css|CSS|js|JS|gif|GIF|php|PHP|x?html?|X?HTML?))(.*?)$ ^/(.*?)(\?|$)(.*) Rewrite /sapphire/main.php?url=$1&$3
}

VirtualHost {
Hostname = localhost
WebsiteRoot = /root/httpd/hiawatha/silverstripe
StartFile = index.php
FastCGI = PHP5
RewriteUrl = phil
}


still no joy??
Hugo Leisink
6 November 2008, 11:39
I've downloaded SilverStripe and based on what I see in the code (had no time to install it yet), I think your rewrite rules must be:
UrlRewrite {
RewriteID = silverstripe
Match (\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php) Return
RequestURI exists Return
Match (.*)\?(.*) Rewrite $1&$2
Match ^/(.*) Rewrite /sapphire/main.php?url=$1
}
Phil Daintree
8 November 2008, 07:01
I've tried this and it still doesn't work - Looks like Hiawatha and Silverstripe was not meant to be

Certainly appreciate your efforts to help though :-)

Thanks
Phil
Hugo Leisink
8 November 2008, 09:39
I've had time to install and try Silverstripe myself. It worked fine with the following configuration:

UrlToolkit {
ToolkitID = silverstripe
RequestURI isfile Return
Match (.*)\?(.*) Rewrite $1&$2 Continue
Match ^/(.*) Rewrite /sapphire/main.php?url=$1
}

VirtualHost {
Hostname = silverstripe-hostname
WebsiteRoot = /path/to/silverstripe
ExecuteCGI = yes
UseToolkit = silverstripe
TriggerOnCGIstatus = no
}


Install via http://your-url/install.php. After installation, manually delete the following files:
check-php.php, config-form.css, config-form.html, index.php, index.html, install.php and rewritetest.php

The weird thing about Silverstripe is that the startfile (sapphire/main.php) is not located in the webroot directory.
Phil Daintree
9 November 2008, 00:56
Can't post now message seen as spam?
Phil Daintree
9 November 2008, 00:56
This doesn't work for 6.7 syntax error on UrlToolkit so I modified it as follows:

UrlRewrite {
RewriteID = silverstripe
RequestURI isfile Return
Match (.*)\?(.*) Rewrite $1&$2
Match ^/(.*) Rewrite /sapphire/main.php?url=$1
}

VirtualHost {
Hostname = localhost
WebsiteRoot = /root/httpd/hiawatha/silverstripe
ExecuteCGI = yes
FastCGI = PHP5
RewriteUrl = silverstripe
}


I deleted the files you suggested and pointing the first link to :

http://localhost/silverstripe/home

I thought should rewrite to:


http://localhost/silverstripe/sapphire/main.php?url=home


but no?
Phil Daintree
9 November 2008, 00:58
Part II:

The output of hiawatha -v is :
Hiawatha v6.7, cache, IPv6, SSL, URL rewrite


I have restarted hiawatha between edits of the /etc/hiawatha/httpd.conf
Phil Daintree
9 November 2008, 00:59
Part III:
I tried to use wigwam to test the URL re-writing:
# wigwam -c /etc/hiawatha/ -r [silverstripe] http://localhost/silverstripe/home
Reading httpd.conf
RewriteID '[silverstripe]' not found.

Phil Daintree
9 November 2008, 01:00
Part IV:

next I tried:

# wigwam -c /etc/hiawatha/ -r silverstripe http://localhost/silverstripe/home
Reading httpd.conf
RewriteID 'http://localhost/silverstripe/home' not found.

Phil Daintree
9 November 2008, 01:00

and finally:
# wigwam -c /etc/hiawatha/ -r silverstripe                                   
Reading httpd.conf

===[ URL rewrite tester
Use empty input to leave the program.

url: http://localhost/silverstripe/home
Bad URL: missing leading slash.
old: http://localhost/silverstripe/home

Phil Daintree
9 November 2008, 01:02
You've been so patient Hugo - I won't give up until you do!!
Phil
Hugo Leisink
9 November 2008, 09:24
message seen as spam: sorry about that. I had to apply some anti-spam rules because of the many spam attempts on this forum. Your message contained multiple links (more than 3) which is common for spam. I've increased the maximum number of links to 5.

Is it possible for you to update your Hiawatha installation to the latest version (6.10)? Just to be sure we're not dealing with a rewrite bug in 6.7.

Part III and IV: you are using wigwam incorrectly. It's usage is: wigwam -r [<rewrite_id>][ <rewrite_id>] ...

finally: Only use the part of the URL after the hostname:
# wigwam -r silverstripe
Reading httpd.conf

===[ URL rewrite tester
Use empty input to leave the program.

url: /home
new: /sapphire/main.php?url=home


Thanks for not giving up. I really need this to make Hiawatha better. Because I know that Hiawatha is capable of running every website available. It's just that it's possible things are not explained clear enough in the manpage/HOWTO/F.A.Q. I really need your feedback to make it all better understandable.
Phil Daintree
9 November 2008, 11:06
OK, I recompiled with the latest source tarball 6.10 and installed.

I think you are absolutely right about Hiawatha I am amazed that the binary is just 105k compared to 2.5Meg for apache and the memory usage is a fraction of apache's it would be interesting to see some benchmarks with PHP as a fast CGI daemon vs apache PHP module. It's my bet that there is not much in it - maybe Hiawatha is faster?

However, configuration of Hiawatha is an issue because the manual/documentation is not so clear at least for me - to be fair I think this rewriting stuff is complicated in any webserver.

I ran hiawatha with your Tookit definition:
UrlToolkit {
ToolkitID = silverstripe
RequestURI isfile Return
Match (.*)\?(.*) Rewrite $1&$2 Continue
Match ^/(.*) Rewrite /sapphire/main.php?url=$1
}



No go :-(

http://localhost/silverstripe/InstallerTest/testrewrite

Warning: file_get_contents(http://localhost/silverstripe/InstallerTest/testrewrite) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in /root/httpd/hiawatha/silverstripe/rewritetest.php on line 50

http://localhost/silverstripe/InstallerTest/testrewrite

Warning: file_get_contents(http://localhost/silverstripe/InstallerTest/testrewrite) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in /root/httpd/hiawatha/silverstripe/rewritetest.php on line 50
mod_rewrite doesn't appear to be working. Make sure:

* mod_rewrite is enabled in your httpd.conf
* AllowOverride is enabled for the current path.

Please check these options, then refresh this page.If you believe that your configuration is correct, click here to proceed anyway.


Using wigwam to test the re-writing I get:
# wigwam -c /etc/hiawatha -t silverstripe
Reading httpd.conf

===[ URL toolkit tester
Use empty input to leave the program.

url: home
Bad URL: missing leading slash.
old: home

url: /home
new: /sapphire/main.php?url=home

url: /localhost/silverstripe/home
new: /sapphire/main.php?url=localhost/silverstripe/home



I noticed that the full url does not rewrite correctly in wigwam?
However, if I start the URL from the point of the

WebsiteRoot = /root/httpd/hiawatha/silverstripe

i.e just the /home bit then all is well - wigwam rewrites this ok. Wondering if this was where we were going so I modified the re-write rule to:

Match (.*)silverstripe/(.*) Rewrite $1silverstripe/sapphire/main.php?url=$2


now:
# wigwam -c /etc/hiawatha -t silverstripe
Reading httpd.conf

===[ URL toolkit tester
Use empty input to leave the program.

url: /localhost/silverstripe/home
new: /localhost/silverstripe/sapphire/main.php?url=home


So looks good - but still no joy!!

My webdoc root its
/root/httpd/hiawatha
and I have
VirtualHost {
Hostname = localhost
WebsiteRoot = /root/httpd/hiawatha
StartFile = index.php
FastCGI = PHP5
}

VirtualHost {
Hostname = localhost
WebsiteRoot = /root/httpd/hiawatha/silverstripe
FastCGI = PHP5
UseToolkit = silverstripe
}


I am using the FastCGI config ... do I also need
    ExecuteCGI = yes
TriggerOnCGIstatus = no


Is the sequence of statements in the httpd.conf file important?
Hugo Leisink
9 November 2008, 11:16
I also got the file_get_contents() warning, but after several F5 key presses, it worked fine. I think that not all problems are Hiawatha related. My guess is that Silverstripe is not really designed to be webserver independent. It could be some internal caching problems. I'll see if I can reproduce the file_get_contents() problems and try to find out what to do to fix the problem.



(I have to leave within an hour. So if I don't respond to your messages, please be patient. Will get back to you this evening or otherwise tomorrow morning)
Hugo Leisink
9 November 2008, 11:49
I've done a complete reinstall of Silverstripe, but it all worked perfecly with the configuration I posted earlier. Install is done via an explicite /install.php requests. After installation, deletion of the install files isn't even required.
Phil Daintree
9 November 2008, 22:04
Please could you describe your directory structure and httpd.conf file
Are the extra configuration parameters required?
 ExecuteCGI = yes
TriggerOnCGIstatus = no

I have run the install.php many times and each time I am presented with the rewrite error page as above.
The code looks at index.php then forwards to install.php - as part of the install it tests the rewriting which is where things fail for me. There is an option to proceed anyway which fails for me too. I need more info to proceed. Is there a way to turn up the debug info so I can get output in the logs which may help debug the issue?

I will delete silverstripe completely and re-install with your config.
Hugo Leisink
10 November 2008, 01:13
My config is this:
CGIhandler = /usr/bin/php5-cgi:php

UrlToolkit {
ToolkitID = silverstripe
RequestURI isfile Return
Match (.*)\?(.*) Rewrite $1&$2 Continue
Match ^/(.*) Rewrite /sapphire/main.php?url=$1
}

VirtualHost {
Hostname = silverstripe.lan
WebsiteRoot = /home/websites/lan/silverstripe
ExecuteCGI = yes
UseToolkit = silverstripe
TriggerOnCGIstatus = no
}


Website is located in /home/websites/lan/silverstripe. As you can see, I've not defined a StartFile. It's the location of the startfile in Silverstripe which makes it weird. I believe that a well designed website should have a startfile located in its webroot. Silverstripe's startfile is silverstripe/main.php, which looks a live big design flaw to me.

I strongly believe the problems in the Hiawatha-Silverstripe combination lies in Silverstripe. Its clear Silverstripe is designed for Apache and has not been tested with other webservers. Hiawatha's debug log will therefor nog show you the necessary information. I will try to find an answer for the problem.
Phil Daintree
10 November 2008, 10:32
Using php as a standard CGI and this exact config:

UrlToolkit {
ToolkitID = silverstripe
RequestURI isfile Return
Match (.*)\?(.*) Rewrite $1&$2 Continue
Match ^/(.*) Rewrite /sapphire/main.php?url=$1
}

VirtualHost {
Hostname = localhost
WebsiteRoot = /root/httpd/hiawatha/silverstripe
ExecuteCGI = yes
UseToolkit = silverstripe
TriggerOnCGIstatus = no
}


I get:

Warning: file_get_contents(http://localhost/silverstripe/InstallerTest/testrewrite) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in /root/httpd/hiawatha/silverstripe/rewritetest.php on line 47

Warning: file_get_contents(http://localhost/silverstripe/InstallerTest/testrewrite) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in /root/httpd/hiawatha/silverstripe/rewritetest.php on line 47
mod_rewrite doesn't appear to be working. Make sure:

* mod_rewrite is enabled in your httpd.conf
* AllowOverride is enabled for the current path.

Please check these options, then refresh this page.If you believe that your configuration is correct, click here to proceed anyway.


Clicking the link to proceed anyway gives me a 404 Not Found
for the URL
http://localhost/silverstripe/home/successfullyinstalled?flush=1

Wigwam produces a URL:
url: /home/successfullyinstalled?flush=1
new: /sapphire/main.php?url=home/successfullyinstalled&flush=1

It grieves me that you have this going and I can't get there :-(
Obviously it is something I have done.
I think I have given this a pretty good go. Silverstripe is reported to work with lighthttpd though and is highly rated as the CMS du jour having just won some OSS award for best CMS.

Thanks for your efforts though Hugo - and thanks for Hiawatha and your great support. On this occasion it looks like we are beaten. I am determined not to have to use apache - any recommendations for a CMS that works with Hiawatha?

Phil
Hugo Leisink
10 November 2008, 10:47
Perhaps you could give http://www.joomla.org/ a try. It doesn't need URL rewriting and worked out of the box for me with Hiawatha. Joomla! is a well known CMS and has a very large community. Probably the most used CMS available.
Phil Daintree
10 November 2008, 10:55
Well just when I was about to move on I thought maybe I am misunderstanding the vritual host concept. I am just using hiawatha on the localhost with no other interfaces pointing towards the machine completely stand alone and I have :

VirtualHost {
Hostname = localhost
WebsiteRoot = /root/httpd/hiawatha
StartFile = index.php
UseToolkit = silverstripe
FastCGI = PHP5
}
VirtualHost {
Hostname = localhost
WebsiteRoot = /root/httpd/hiawatha/silverstripe
ExecuteCGI = yes
UseToolkit = silverstripe
TriggerOnCGIstatus = no
}


So in fact silverstripe is a sub-directory off the web-root off the main web-root document directory. Modifying the UrlToolkit to:

UrlToolkit {
ToolkitID = silverstripe
RequestURI isfile Return
Match (.*)\?(.*) Rewrite $1&$2 Continue
Match ^/silverstripe/(.*) Rewrite /silverstripe/sapphire/main.php?url=$1
}


and enabling the toolkit in the web-root localhost virtual host section has got me in. My mistake is in defining a separate virtual host for silverstipe or in not defining it correctly with its own name resolution.
Hugo Leisink
10 November 2008, 11:10
Ah, now we're getting somewhere. About the virtualhosts: you should never have two virtualhosts with the same hostname. If you do so, Hiawatha will always take the first one that matches. The second one will be ignored. You could simply create a hostname for your machine by adding one to your /etc/hosts file. Edit your /etc/hosts file like this:
127.0.0.1    localhost    silverstripe


Then you can use silverstripe as the hostname of your virtual host block:
VirtualHost {
Hostname = localhost
WebsiteRoot = /root/httpd/hiawatha
StartFile = index.php
FastCGI = PHP5
}

VirtualHost {
Hostname = silverstripe
WebsiteRoot = /root/httpd/hiawatha/silverstripe
ExecuteCGI = yes
UseToolkit = silverstripe
TriggerOnCGIstatus = no
}


You could also move the silverstripe directory to /root/httpd (out of the hiawatha directory) to have a seperate website.
Phil Daintree
10 November 2008, 11:25
Yes this virtual host thing was the trap... the morale of the story:

1. Virtual hosts must have their own name resolution going on in hosts or I imagine named/dns
2. Virtual host website root can be anywhere even outside the website root given at compile time.
3. Where there are more than one VirtualHost segments that resolves to the same hostname - only the first segment will be processed
Phil Daintree
10 November 2008, 11:25
Thanks again Hugo for your patience!!
Hugo Leisink
10 November 2008, 11:51
I'll add some virtual hostname checks to wigwam. Is silverstripe now working for you? Have we striked back after almost been beaten?
Phil Daintree
12 November 2008, 00:41
Silverstripe works with Hiawatha - we did it! A win for stubbon determination

PS I posted to the silverstripe forum asking for assistance and posted a reply to myself with the solution so others can benefit from web-serving the smart way with Hiawatha. Thanks again Hugo!!
This topic has been closed.