Enable CORS with wamp on windows 8 - apache

I have a cross domain request problem with an application I'm doing. I really spent hours looking for a solution on how to enable CORS with wamp (localhost) but nothing worked for me.
I have Apache 2.4.9 on Windows 8.1. I have enable the headers, I tried to put
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"
in a .htaccess and in the http.conf as well as countless other variations.
If anyone had a solution that'd be awesome!

I had the same problem and i solved it with these 3 steps:
1) in Apache config file (for me the path was C:\wamp\bin\apache\apache2.4.18\conf\httpd.conf)
add the line:
Header set Access-Control-Allow-Origin "*"
in the content of the <Directory> tag:
DocumentRoot "c:/wamp/www"
<Directory "c:/wamp/www/">
Options +Indexes +FollowSymLinks
Header set Access-Control-Allow-Origin "*"
AllowOverride all
Require local
</Directory>
2) activate the "headers_module" in apache's modules (it will also restart your apache server, effectively applying the change made in step 1)
3) clear your browser cache (I am using chrome and i was told the best way to "hard clear" the cache was to go in the developper tools -> Networks tab -> right click -> clear browser cache)
(by the way, clearing the browser cache is often useful when debugging in chrome)
Now it should work. Good luck !

You must also activate the Apache Headers module.
Using the wampmanager menus do this :-
wampmanager -> Apache -> Apache modules -> headers_module
Make sure this is ticked, if its not, click that menu item and wait a few seconds while WampServer restarts Apache.

Related

XAMPP managing headers (server response headers)

I need to modify my localhost page server response (edit headers) - I'm using XAMPP (apache + msql, on linux machine). I can't find how to do that. Maybe some of the programmers/admins know how I can make it happened - share their knowledge and save me time.
If there is any article/link I would use it gladly.
I cannot use live server (my page is a total mess - it working on localhost by miracle...), and the only thing I have installed is xampp, so editing response headers through xampp would be perfect.
Thanks for any directions.
EDIT:
https://www.a2hosting.com/kb/developer-corner/apache-web-server/modifying-http-headers
is not working for me.
<IfModule mod_headers.c>
Header set Test "testing"
</IfModule>
inside of .htaccess
In you .htaccess file (witch should be placed where your index.html is) type:
### add custom header to all server responses from ALL files:
Header add Custom-Header: "parameter=value"
### add custom header to SINGLE file:
<Files someOtherFile.html>
Header add Custom-Header: "parameter=value"
</Files>
I'm using linux, maybe on windows there is something more you should do but remember to restart xampp after editing .htaccess.

cakephp setting custom header does not work, htaccess, apache

I am experiencing some odd behaviour.
I have debian 7(on the vmware if it matters) with apache 2.2.22. For my cakephp application I want to set custom header, so I put this in app/webroot/.htaccess file (without removing what already exists of course)
<IfModule mod_headers.c>
Header append X-FRAME-OPTIONS: DENY
</IfModule>
but when I request the page, in firebug net panel it does not show X-FRAME-OPTIONS header. Headers mod is enabled. a2enmod headers outputs Module headers already enabled. Apache is restarted (even OS is rebooted). This cakephp application(copied by 100%) I tested on my vps(again debian 7), and it shows that header just fine. So, first it made me believe there is smth wrong with my local debian, but then I tested this. I created single file index.php in www/some_test folder and put echo "ok". Also created .htaccess with the same content
<IfModule mod_headers.c>
Header append X-FRAME-OPTIONS: DENY
</IfModule>
And the funny part is, I could see in firebug that X-FRAME-OPTIONS header. So, the bottom line with cakephp application, in the server1 custom headers are fine, in server2 - does not show, for simple index.php 'app' in server2 headers are fine again. Can someone help what the problem can be. I need to set custom headers.
Thanks
I am not sure what was the problem, but removing and reinstalling the php solved it
apt-get remove php5*
apt-get install php5
https://superuser.com/questions/673837/php5-ini-file-is-blank/674408#674408

When typing "localhost" in the address bar, I want to see a directory of files/folders

I recently installed XAMPP. I notice that when I type 'localhost' in the address bar of my browser, it shows a nice XAMPP welcome page. But I wish I could figure out how to show a directory of files and folders in my htdocs. I've seen this work on my old stack - 'parent directory', etc.
I've been digging around my httpd.conf file, and have found things on Google about AllowOverride, etc. Other sources say I should write a .htaccess file, but I can't get clarity on how to tweek my settings somehow to make this work.
Thanks!
Turn on your directory listing in apache configuration filehttpd.conf
For example if you projects are in /var/www/html, edit httpd.conf to add
<Directory /var/www/html >
Options Indexes FollowSymLinks
</Directory>
Following this, restart the httpd service

Apache 2.4 + PHP-FPM and Authorization headers

Summary:
Apache 2.4's mod_proxy does not seem to be passing the Authorization headers to PHP-FPM. Is there any way to fix this?
Long version:
I am running a server with Apache 2.4 and PHP-FPM. I am using APC for both opcode caching and user caching. As recommended by the Internet, I am using Apache 2.4's mod_proxy_fcgi to proxy the requests to FPM, like this:
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/foo/bar/$1
The setup works fine, except one thing: APC's bundled apc.php, used to monitor the status of APC does not allow me to log in (required for looking at user cache entries). When I click "User cache entries" to see the user cache, it asks me to log in, clicking on the login button displays the usual HTTP login form, but entering the correct login and password yields no success. This function is working perfectly when running with mod_php instead of mod_proxy + php-fpm.
After some googling I found that other people had the same issue and figured out that it was because Apache was not passing the Authorization HTTP headers to the external FastCgi process. Unfortunately I only found a fix for mod_fastcgi, which looked like this:
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization
Is there an equivalent setting or some workaround which would also work with mod_proxy_fcgi?
Various Apache modules will strip the Authorization header, usually for "security reasons". They all have different obscure settings you can tweak to overrule this behaviour, but you'll need to determine exactly which module is to blame.
You can work around this issue by passing the header directly to PHP via the env:
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
See also Zend Server Windows - Authorization header is not passed to PHP script
In some scenarios, even this won't work directly and you must also change your PHP code to access $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] rather than $_SERVER['HTTP_AUTHORIZATION']. See When setting environment variables in Apache RewriteRule directives, what causes the variable name to be prefixed with "REDIRECT_"?
This took me a long time to crack, since it's not documented under mod_proxy or mod_proxy_fcgi.
Add the following directive to your apache conf or .htaccess:
CGIPassAuth on
See here for details.
Recently I haven'd problem with this arch.
In my environement, the proxy to php-fpm was configured as follow:
<IfModule proxy_module>
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache2/htdocs/$1
ProxyTimeout 1800
</IfModule>
I fixed the issue set up the SetEnvIf directive as follow:
<IfModule proxy_module>
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache2/htdocs/$1
ProxyTimeout 1800
</IfModule>
I didn't find any similar settings with mod_proxy_fcgi BUT it just works for me by default. It asks for user authorization (.htaccess as usual) and the php gets it, and works like with mod_php or fastcgi and pass-header. I don't know if I was helpful...
EDIT:
it only works on teszt.com/ when using the DirectoryIndex... If i pass the php file name (even if the index.php!) it just doesn't work, don't pass the auth to the php. This is a blocker for me, but I don't want to downgrade to apache 2.2 (and mod_fastgi) so I migrate to nginx (on this machine too).

Broken links in local Wordpress site

I have a wordpress site set up on a live server, and I have replicated the site locally by following these steps:
FTPed live files to local
Set up virtual host (dev.domain.com) to point at local version of site
Imported the db locally
changed wp-config.php to the correct local db settings
changed 'home' and siteurl' in db.wp_options to point to http://dev.domain.com (from http://www.domain.com)
Home page loads fine, /wp-admin all loads fine.
Problem is in links to pages:
Permalinks are set to point to post name: http://dev.example.com/sample-post/, just as on live server. However, locally, all links to posts are broken, and Apache (2.2.17) is responding with the following error: "The requested URL /sample-post/ was not found on this server."
I'm assuming I've missed a configuration step somewhere, though I've followed this process umpteen times in the past with no problems. The issue with this particular site is that the theme has been hacked with lots and lots of absolute paths entered, meaning setting up a dev site has required loads of code changes.
I'm not really sure how to further trouble shoot this, not completely understanding how Wordpress / Apache handles permalinks
Copy the .htaccess if you haven't already
I think that might be the problem
OK - sorted this, it was to do with mod_rewrite on apache.
To fix (this is for my install of Ubuntu 11.04):
first enable mod_rewrite in apache
sudo a2enmod rewrite
Then edit the relevant file in /etc/apache2/sites-available (could be 'default', or one specific to site):
sudo vi /etc/apache2/sites-available/site-file
Change AllowOverride directive for your site document root from None to All:
:
<Directory /var/www/site.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
That seems to have done it.