logo
Apache Lounge
Webmasters

 


About

Forum Index Downloads Search Register Log in  RSS Apache Lounge
 



Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Apache Lounge is not sponsored.

Your donations will help to keep this site alive and well, and continuing building binaries.



can't figure out what is wrong in config

 
Post new topic   Reply to topic    Apache Forum Index -> Apache



View previous topic :: View next topic  
Author Message
pato.llaguno



Joined: 26 Oct 2017
Posts: 5

PostPosted: Thu 26 Oct '17 14:39    Post subject: can't figure out what is wrong in config Reply with quote

I have been having some issues, i am using https://github.com/pabloroca/slim3-simple-rest-skeleton oauth library and at first I thought it had an error on it since i could get my tokens correctly but when consuming the tokens i got a 401 error, after some experimentation i found out that it has something to do with apache. If I start the php server from a command line it does work correctly, so now I am in a point where I have no idea what can apache be doing to make the scripts malfunction.

I have XAMPP installed on a windows machine. (Apache/2.4.27 (Win32) OpenSSL/1.0.2l PHP/7.1.9)

I have the virtualhost configured in apache, like this.

Code:
<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/slim3-simple-rest-skeleton-master/public"
    ServerName TestSite
</VirtualHost>

and my etc hosts file added the line
Code:
127.0.0.1 TestSite


with that configuration i am able to make a request to http://testsite/oauth/token and get my access token, so here everything works just fine.

but when i go to http://testsite/books i get a blank page with 401 unauthorized header.

in the other hand, if i go to my folder slim3-simple-rest-skeleton-master and run this
Code:
php -S 0.0.0.0:8888 -t public/


i can get my token at http://localhost:8888/oauth/token just as before, and when i do a get to http://localhost:8888/books it works correctly.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 6255
Location: Germany, Next to Hamburg

PostPosted: Tue 31 Oct '17 17:55    Post subject: Reply with quote

The included .htaccess file does do some magic for the auth in apache. So you have to enable it in apache.

Code:

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/slim3-simple-rest-skeleton-master/public"
    ServerName TestSite

    <Directory "C:/xampp/htdocs/slim3-simple-rest-skeleton-master/public">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
Back to top
pato.llaguno



Joined: 26 Oct 2017
Posts: 5

PostPosted: Tue 31 Oct '17 18:06    Post subject: Reply with quote

Im not sure what you mean, inside my public folder i have a .htaccess with this:

Code:
<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]


    RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]
    RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
</IfModule>
[/code]

And that code i need it so i can run my slim framework, on the other hand, on the httpd-vhosts.conf i added what you said with no luck.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 6255
Location: Germany, Next to Hamburg

PostPosted: Tue 31 Oct '17 18:08    Post subject: Reply with quote

Is mod rewrite loaded?

if you are not sure cd into apache bin folder and run
httpd.exe -M
Back to top
pato.llaguno



Joined: 26 Oct 2017
Posts: 5

PostPosted: Tue 31 Oct '17 18:13    Post subject: Reply with quote

yes, it is loaded cause other routes do work correctly, by doing some logging i found out that for some reason the header authorization is not reaching with apache.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 6255
Location: Germany, Next to Hamburg

PostPosted: Tue 31 Oct '17 18:25    Post subject: Reply with quote

Apache sometimes strips that auth header, but you can re add it
Code:

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1


or
Code:

RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

I'm not sure which is the right one.


if you are using mod_fcgid you also need to add

Code:
FcgidPassHeader Authorization
Back to top
pato.llaguno



Joined: 26 Oct 2017
Posts: 5

PostPosted: Tue 31 Oct '17 18:51    Post subject: Reply with quote

where do i need to add the fcgid? i tried adding

Quote:
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]


to .htaccess and now i get error 404[/quote]
Back to top
pato.llaguno



Joined: 26 Oct 2017
Posts: 5

PostPosted: Tue 31 Oct '17 18:53    Post subject: Reply with quote

Thanks for your help, doing some resaerch i found out the solution.

adding this to .htaccess solved it

Code:
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
Back to top


Post new topic   Reply to topic    Apache Forum Index -> Apache
Page 1 of 1