.htaccess not working apache

I have a server from amazon's ec2 service running on linux ubuntu and I have installed apache, php, and mysql. I have added a .htaccess file in my document root /var/www/html. I entered this code in it: ErrorDocument 400 /var/www/html/404.php and it is still not showing up. I kept entered this command multiple times: sudo service httpd restart to restart the server but no changes displayed... How can I fix this... Did I do something wrong? Thanks in advance!

Apache shows php code instead of executing

I have recently been trying to install php and apache on my computer. After many hours, they're installed. I have modified the httpd.conf and php.ini files like everyone says. I then created a simple php script:

<?php phpinfo(); ?>

But when I try to run it with http://127.0.0.1/phpinfo.php it just shows the source code instead of executing. I am using apache2, php5 and windows vista. I have been searching all over the internet without success and am almost banging my head against the wall. Can anyone save me from a concussion?

EDITED LINES:

PHP.INI:

short_open_tag = On

HTTPD.CONF

LoadModule php5_module "C:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
PHPIniDir "C:/php"

installing cakephp 2.0.0 in a subdirectory

i found a similar problem here but did not find a solution. basically i have installed an existing cakephp application in a subdirectory 'localhost/dyod'. without editing the htaccess files, i get an error telling me that the app is looking for the dyod controller, so seemingly the uri is off somehow. when i add a rewritebase to the htaccess files (/dyod/) then all the assets' urls are off and don't include the webroot. also, it is still looking for a dyod controller. my htaccess files are copied from here.

thanks in advance.

How to run php in a java web application project in NetBeans

I have a java web application created in NetBeans from 'File-->New Project-->Java Web-->Web Application'.
I have Tomcat as the server. In my computer I can run php without any problem in a NetBeans php project, or in XAMPP.
But I want to run php commands in a java web application project. I tried by adding this code to index.jsp file

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <?php echo 'php code here'; ?>
        <h1>Hello World!</h1>
    </body>
</html>  

It doesn't print 'php code here' string but print 'Hello World!' string.
I tried renaming file name index.jsp to index.php (And also change the name in web.xml file). But it still gives me the same output

Can anyone please tell me how to do this?

Apache httpd restart failed

I'm restarting my apache server by this command "service httpd restart" and getting the following message:

Stopping httpd: [FAILED]
Starting httpd: [ OK ]

Before the problem happened, what I've done is simply to replace an old database file with new one. This database file will be used by another php file. When I did the replacement, I didn't stop httpd.

After failing to restart apache server, I surfed the web to find solution and tried the following methods.

1) Try this "netstat -lnp | grep httpd" and "lsof -i:80" to find if there's any process binding port 80. The result is none process.

2) Remove locked subsys by this "rm -f /var/lock/subsys/httpd" and restart httpd again, but the result is the same as the above message:

Stopping httpd:                                            [FAILED]  
Starting httpd:                                            [  OK  ]

3) It didn't seem to work even if I reboot the server

How to tackle this problem?

The error_log shows the following message:

[Thu Aug 09 15:10:34 2012] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) [Thu Aug 09 15:10:34 2012] [info] Init: Seeding PRNG with 256 bytes of entropy [Thu Aug 09 15:10:34 2012] [info] Init: Generating temporary RSA private keys (512/1024 bits) [Thu Aug 09 15:10:34 2012] [info] Init: Generating temporary DH parameters (512/1024 bits) [Thu Aug 09 15:10:34 2012] [info] Init: Initializing (virtual) servers for SSL [Thu Aug 09 15:10:34 2012] [info] Server: Apache/2.2.3, Interface: mod_ssl/2.2.3, Library: OpenSSL/0.9.8e-fips-rhel5 [Thu Aug 09 15:10:34 2012] [notice] Digest: generating secret for digest authentication ... [Thu Aug 09 15:10:34 2012] [notice] Digest: done [Thu Aug 09 15:10:34 2012] [debug] util_ldap.c(2052): LDAP merging Shared Cache conf: shm=0x8541df0 rmm=0x8541e20 for VHOST: localhost.localdomain [Thu Aug 09 15:10:34 2012] [info] APR LDAP: Built with OpenLDAP LDAP SDK
[Thu Aug 09 15:10:34 2012] [info] LDAP: SSL support available [Thu Aug 09 15:27:26 2012] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) [Thu Aug 09 15:27:26 2012] [info] Init: Seeding PRNG with 256 bytes of entropy [Thu Aug 09 15:27:26 2012] [info] Init: Generating temporary RSA private keys (512/1024 bits) [Thu Aug 09 15:27:26 2012] [info] Init: Generating temporary DH parameters (512/1024 bits) [Thu Aug 09 15:27:26 2012] [info] Init: Initializing (virtual) servers for SSL [Thu Aug 09 15:27:26 2012] [info] Server: Apache/2.2.3, Interface: mod_ssl/2.2.3, Library: OpenSSL/0.9.8e-fips-rhel5 [Thu Aug 09 15:27:26 2012] [notice] Digest: generating secret for digest authentication ... [Thu Aug 09 15:27:26 2012] [notice] Digest: done [Thu Aug 09 15:27:26 2012] [debug] util_ldap.c(2052): LDAP merging Shared Cache conf: shm=0x97f4df0 rmm=0x97f4e20 for VHOST: localhost.localdomain [Thu Aug 09 15:27:26 2012] [info] APR LDAP: Built with OpenLDAP LDAP SDK
[Thu Aug 09 15:27:26 2012] [info] LDAP: SSL support available

ssl_error_log: [Thu Aug 09 15:10:34 2012] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) [Thu Aug 09 15:10:34 2012] [info] Init: Seeding PRNG with 256 bytes of entropy [Thu Aug 09 15:10:34 2012] [info] Init: Generating temporary RSA private keys (512/1024 bits) [Thu Aug 09 15:10:34 2012] [info] Init: Generating temporary DH parameters (512/1024 bits) [Thu Aug 09 15:10:34 2012] [info] Init: Initializing (virtual) servers for SSL [Thu Aug 09 15:10:34 2012] [info] Server: Apache/2.2.3, Interface: mod_ssl/2.2.3, Library: OpenSSL/0.9.8e-fips-rhel5 [Thu Aug 09 15:10:34 2012] [notice] Digest: generating secret for digest authentication ...
[Thu Aug 09 15:10:34 2012] [notice] Digest: done [Thu Aug 09 15:10:34 2012] [debug] util_ldap.c(2052): LDAP merging Shared Cache conf: shm=0x8541df0 rmm=0x8541e20 for VHOST: localhost.localdomain
[Thu Aug 09 15:10:34 2012] [info] APR LDAP: Built with OpenLDAP LDAP SDK [Thu Aug 09 15:10:34 2012] [info] LDAP: SSL support available
[Thu Aug 09 15:27:26 2012] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) [Thu Aug 09 15:27:26 2012] [info] Init: Seeding PRNG with 256 bytes of entropy [Thu Aug 09 15:27:26 2012] [info] Init: Generating temporary RSA private keys (512/1024 bits) [Thu Aug 09 15:27:26 2012] [info] Init: Generating temporary DH parameters (512/1024 bits) [Thu Aug 09 15:27:26 2012] [info] Init: Initializing (virtual) servers for SSL [Thu Aug 09 15:27:26 2012] [info] Server: Apache/2.2.3, Interface: mod_ssl/2.2.3, Library: OpenSSL/0.9.8e-fips-rhel5 [Thu Aug 09 15:27:26 2012] [notice] Digest: generating secret for digest authentication ... [Thu Aug 09 15:27:26 2012] [notice] Digest: done [Thu Aug 09 15:27:26 2012] [debug] util_ldap.c(2052): LDAP merging Shared Cache conf: shm=0x97f4df0 rmm=0x97f4e20 for VHOST: localhost.localdomain [Thu Aug 09 15:27:26 2012] [info] APR LDAP: Built with OpenLDAP LDAP SDK
[Thu Aug 09 15:27:26 2012] [info] LDAP: SSL support available

Thanks for any help!

Apache proxy load balancing backend server failure detection

Here's my scenario (designed by my predecessor):

Two Apache servers serving reverse proxy duty for a number of mixed backend web servers (Apache, IIS, Tomcat, etc.). There are some sites for which we have multiple backend web servers, and in those cases, we do something like:

<Proxy balancer://www.example.com>
    BalancerMember http://192.168.1.40:80
    BalancerMember http://192.168.1.41:80
</Proxy>
<VirtualHost *:80>
    ServerName www.example.com:80
    CustomLog /var/log/apache2/www.example.com.log combined
    <Location />
        Order allow,deny
        Allow from all
        ProxyPass balancer://www.example.com/
        ProxyPassReverse balancer://www.example.com/
    </Location>
</VirtualHost>

So in this example, I've got one site (www.example.com) in the proxy servers' configs, and that site is proxied to one or the other of the two backend servers, 192.168.1.40 and .41.

I'm evaluating this to make sure that we are fault tolerant on all of our web services (I've already put the two reverse proxy servers into a shared IP cluster for this reason), and I want to make sure that the load-balanced backend servers are fault tolerant as well. But I'm having trouble figuring out if backend failure detection (and the logic to avoid the failed backend server) is built into the mod_proxy_balancer module...

So if 192.168.202.40 goes down, will Apache detect this (I'll understand if it takes a failed request first) and automatically route all requests to the other backend, 192.168.202.41? Or will it continue to balance requests between the failed backend and the operational backend?

I've found some clues in the Apache documentation for mod_proxy and mod_proxy_balancer that seem to indicate that failure can be detected ("maxattempts = Maximum number of failover attempts before giving up.", "failonstatus = A single or comma-separated list of HTTP status codes. If set this will force the worker into error state when the backend returns any status code in the list."), but after a few days of searching, I've found nothing conclusive saying for sure that it will (or at least "should") detect backend failure and recovery.

I will say that most of the search results reference using the AJP protocol to pass the traffic to the backend servers, and this apparently does support failure detection-- but my backends are a mixture of Apache, IIS, Tomcat and others, and I am fairly sure that many of them don't support AJP. They are also a mixture of Windows 2k3/2k8 and Linux (mostly Ubuntu Lucid) boxes running various different applications with various different requirements, so add-on modules like Backhand and LVS aren't an option for me.

I've also tried to empirically test this feature, by creating a new test site like this:

<Proxy balancer://test.example.com>
    BalancerMember http://192.168.1.40:80
    BalancerMember http://192.168.1.200:80
</Proxy>
<VirtualHost *:80>
    ServerName test.example.com:80
    CustomLog /var/log/apache2/test.example.com.log combined
    LogLevel debug
    <Location />
        Order allow,deny
        Allow from all
        ProxyPass balancer://test.example.com/
        ProxyPassReverse balancer://test.example.com/
    </Location>
</VirtualHost>

Where 192.168.1.200 is a bogus address that isn't running any web server, to simulate a backend failure. The test site was served up without a problem for a bunch of different client machines, but even with the LogLevel set to debug, I didn't see anything logged to indicate that it detected that one of the backend servers was down... And I'd like to make 100% sure that I can take our load-balanced backends down for maintenance (one at a time, of course) without affecting production sites.

Thanks in advance for any advice and/or assistance!

Regards,

Jon Heese

pass arguments to apache-ant exec task based on the variable’s value

I am only using apache-ant and not ant-contrib

I have an ant target

<target name="stop" depends="init" >
...
</target>

In which i want to invoke exec task.

If the value of a variable HOST_NAME is all

<exec executable="${executeSSH.shell}" >
    <arg value="-h ${HOST_NAME}" />
    <arg value="-i ${INSTANCE}" />
    <arg value="-w 10" />
    <arg value="-e ${myOperation.shell} " />
    <arg value=" -- " />
    <arg value="${INSTANCE} ${USERNAME} ${PASSWORD}" />
</exec>

If the value of a variable HOST_NAME is anything else

<exec executable="${executeSSH.shell}">
    <arg value="-h ${HOST_NAME}" />
    <arg value="-i ${INSTANCE}" />
    <arg value="-e ${myOperation.shell} " />
    <arg value=" -- " />
    <arg value="${INSTANCE} ${USERNAME} ${PASSWORD}" />
</exec>

But i would like to write only one task and not to repeatexec. I have used HOST_NAME parameter but what to do about the second parameter -w 10 which is different in both calls.

I have tried a couple of ways by searching on SO by using condition and if else but nothing seems to be applicable for exec or arg.

Apache httpd module to authenticate against web service?

I'm looking to see if there's an available apache httpd module to do this or if I'll have to write my own. I want to be able to authenticate and authorize a user based on a RESTful web service call that returns JSON from to our SSO application. It has to do this:

Extract a cookie value from the request. If no cookie jump to the redirect.

Construct a URL based on it

Fetch the URL

Check the JSON object for an authorized boolean. If not authorized redirect to a login application passing the original request URL as a parameter.

If authorized, check the allowed groups against an array in the JSON object. Return a 401 if not in the list or let the request continue if it is.

We do this with servlet filters in our Java applications, but it would be handy to be able to restrict any URL with it whether it's static content or code.

Apache Server Won’t Start in MAMP

Apache server won't start when in MAMP. Here are the error logs:

[Wed Aug 01 21:07:34 2012] [notice] Digest: generating secret for digest authentication ...
[Wed Aug 01 21:07:34 2012] [notice] Digest: done
[Wed Aug 01 21:07:34 2012] [notice] Apache/2.0.63 (Unix) PHP/5.3.2 DAV/2 configured -- resuming normal operations
[Wed Aug 01 21:08:00 2012] [notice] caught SIGTERM, shutting down
[Wed Aug 01 21:08:01 2012] [notice] Digest: generating secret for digest authentication ...
[Wed Aug 01 21:08:01 2012] [notice] Digest: done
[Wed Aug 01 21:08:01 2012] [notice] Apache/2.0.63 (Unix) PHP/5.3.2 DAV/2 configured -- resuming normal operations
[Wed Aug 01 21:08:51 2012] [notice] caught SIGTERM, shutting down

I don't think I did anything our of the ordinary except create a new folder in htdocs. Any suggestions?