WebFaction
Community site: login faq

Hi. I've succesfully installed OwnCloud on Webfaction server and it works fine on the web. I'm unable to log in using WEBDAV (thus, I also cannot use the desktop and mobile clients). This kind of problem is already solved in http://www.blaicher.com/2012/07/fixing-authentication-of-owncloud-for-webfaction/, but I'm unable to implement the solution. Now I can authenticate my user, but I can't do anything more, it gives me a 404 page not found when i tried to access /remote.php/caldav (or any other *dav), so I think that the modification in the .htaccess is messing up with the redirection to the apps of owncloud (caldav, cardav, etc). This problem is related to the way webfaction handle the enviroment variables in the login of the users.

My .htaccess (an access configuration file for owncloud) is:

<IfModule mod_fcgid.c>
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
SetEnvIfNoCase ^Authorization$ "(.+)" XAUTHORIZATION=$1
RequestHeader set XAuthorization %{XAUTHORIZATION}e env=XAUTHORIZATION
</IfModule>
</IfModule>
</IfModule>
ErrorDocument 403 /owncloud/core/templates/403.php
ErrorDocument 404 /owncloud/core/templates/404.php
<IfModule mod_php5.c>
php_value upload_max_filesize 512M
php_value post_max_size 512M
php_value memory_limit 512M
<IfModule env_module>
  SetEnv htaccessWorking true
</IfModule>
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP:Authorization} ^Basic.*
RewriteRule ^(.*) $1?Authorization=%{HTTP:Authorization} [QSA,C]
RequestHeader unset Authorization
RewriteRule ^.well-known/host-meta /public.php?service=host-meta [QSA,L]
RewriteRule ^.well-known/carddav /remote.php/carddav/ [R]
RewriteRule ^.well-known/caldav /remote.php/caldav/ [R]
RewriteRule ^apps/([^/]*)/(.*\.(css|php))$ index.php?app=$1&getfile=$2 [QSA,L]
RewriteRule ^remote/(.*) remote.php [QSA,L]
</IfModule>
<IfModule mod_mime.c>
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
</IfModule>
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
AddDefaultCharset utf-8

And I pasted the code for the lib/base.php inside the public static function init() between the two if statements:

if (isset($_SERVER['REDIRECT_REMOTE_USER']) && preg_match('/Basic\s+(.*)$/i', $_SERVER['REDIRECT_REMOTE_USER'], $matches))

and

if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])

If anybody can help me I would really appreciated it.

I'm using OwnCloud 5.0.7, with almost stock configuration, except for some modifications in the css (that doesn't alter the functionality of the page). Something else that might be helpful is that with this modification on .htaccess the webpage now ignore the css, so it appears as it is not stylized.

Sorry for my english and if I didn't comply with some rules of the forum, this is my first post here.

And thank you in advance.

P.D. I had already asked this in the owncloud forum and was redirected here.

asked 05 Aug '13, 11:58

quique7991
1112
accept rate: 0%

edited 05 Aug '13, 23:37

ryans ♦♦
5.0k93360

Please open a support ticket via our control panel so that I can have a look at your installation. Thanks!

(06 Aug '13, 12:10) seanf

Got ownCloud working and synching perfectly with the desktop client thanks in part to the link quique7991 provided above (http://www.blaicher.com/2012/07/fixing-authentication-of-owncloud-for-webfaction/) and in part thanks to Valentin I. of WF support.

Here's the solution:

1) In /owncloud/lib/base.php, look for //set http auth headers for apache+php-cgi work around, //set http auth headers for apache+php-cgi work around if variable gets renamed by apache, etc. (Thanks Chuck) At the end of that section and before self::initPaths(); (which is on line 516 as of ownCloud 6.0.4) add these lines:

//set http auth headers for Webfaction workaround
if(isset($_GET['Authorization']) && preg_match('/Basic\s+(.*)$/i', $_GET['Authorization'], $matches))
{
    list($name, $password) = explode(':', base64_decode($matches[1]));<br />
    $_SERVER['PHP_AUTH_USER'] = strip_tags($name);<br />
    $_SERVER['PHP_AUTH_PW'] = strip_tags($password);<br />
}

2) In /owncloud/.htaccess, add the following lines after RewriteEngine on (Thanks Valentin):

RewriteCond %{HTTP:Authorization} ^Basic.*
RewriteRule ^(.*) $1?Authorization=%{HTTP:Authorization} [QSA,C]
RequestHeader unset Authorization

And that's it — ownCloud works!

permanent link

answered 16 Jul '14, 14:38

PeterA
10431022
accept rate: 14%

edited 16 Jul '14, 14:39

I just added a RequestHeader set in my .htaccess file and it works without modifying the owncloud 8.0 source.

Locate the following line:

RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

And add after it:

RequestHeader set XAuthorization %{HTTP_AUTHORIZATION}e env=HTTP_AUTHORIZATION
permanent link

answered 03 Mar '15, 22:31

osamyn
312
accept rate: 0%

Hi- looks like this no longer works with 7.0- does anyone have any workaround for the new version?

permanent link

answered 21 Oct '14, 21:15

alexanderhowell
1
accept rate: 0%

The same technique should work for Owncloud 7. The only difference is that the init() function in lib/base.php starts at line 430 instead of line 350.

(21 Oct '14, 21:52) seanf

Ah yes- thanks! I had it in the higher up init() block and that seemed to upset it!

(21 Oct '14, 22:27) alexanderhowell

I just installed 7.03 and I can't find this section of the base.php file. Searching for "apache+cgi" is bringing up something around line 800 - but it doesn't look like it's the same thing.

Can somebody with better php skills than me take a peek and let me know if they've changed something drastically? I did download the client and try to sync - no dice - so the fix apparently is needed.

Thanks.

permanent link

answered 01 Dec '14, 01:45

chrisod
4128
accept rate: 0%

For OwnCloud 7.0.3, use the following rewrite directives in .htaccess just below the existing HTTP_AUTHORIZATION rewrite...

RewriteCond %{HTTP:Authorization} ^Basic.*
RewriteRule ^(.*) $1?Authorization=%{HTTP:Authorization} [QSA,C]
RequestHeader unset Authorization

... and at line 800 of lib/base.php replace the handleAuthHeaders() function with this one:

 protected static function handleAuthHeaders() {
         //sett http auth headers for Webfaction workaround
         if(isset($_GET['Authorization']) && preg_match('/Basic\s+(.*)$/i', $_GET['Authorization'], $matches))
         {
             list($name, $password) = explode(':', base64_decode($matches[1]));
             $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
             $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
         }
 }
(01 Dec '14, 17:39) seanf

Just had a chance to try this and it works. Thanks!

(05 Dec '14, 02:48) chrisod

Are those workarounds required only when one using Apache server or they are necessary when using 'custom' web servers as well?

(06 Feb '15, 09:07) gour

These workarounds are required when using PHP-CGI and PHP-FastCGI in a suexec Apache environment, which is what we run here at WebFaction. If you're running something similar as your custom back-end web server, then you might need to use them for that as well.

(06 Feb '15, 17:30) seanf

So, if I use, as planned, my own instances of PHP-FPM and Hiawatha webserver, it won't be required?

(06 Feb '15, 17:55) gour

I'm not familiar with Hiawatha, and their website seems to be down, so I'm not able to answer that. All I can say is give it a try :)

(06 Feb '15, 18:21) seanf

Hiawatha site is working here...and i'm waiting for WF support to provide me some help (configure line to build latest php-fpm) so I can try it out...

(06 Feb '15, 19:48) gour

The following configure line should work to build PHP 5.6.5 with php-fpm support:

./configure --enable-fpm --prefix=$HOME/local/php --with-curl=/usr --with-pdo-pgsql --with-pgsql --with-pdo-mysql --with-mysql --enable-bcmath --enable-calendar --enable-exif --enable-ftp --with-gd --with-gettext --with-gmp --enable-intl --enable-mbstring --with-mhash --with-mysqli --with-openssl --with-pspell --enable-soap --enable-sockets --with-xmlrpc --with-xsl --enable-zip --with-zlib-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-kerberos --with-mysql-sock=/var/lib/mysql/mysql.sock --with-iconv --with-regex

Hope that helps!

(06 Feb '15, 20:44) seanf

Hiya Sean,

Hope that helps!

Your support rocks!!

Now I'm running my own PHP as well as (light) Hiawatha server. :-)

Most of the migration Linode --> Webfaction work was done and I believe I'm going to stay this time @Webfaction for looooooong time. ;)

(07 Feb '15, 08:56) gour
showing 5 of 9 show 4 more comments
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×262
×40
×16
×7

question asked: 05 Aug '13, 11:58

question was seen: 7,823 times

last updated: 03 Mar '15, 22:31

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM