I have a environment variable called DISTANT_APP_ADDR:
$ echo $DISTANT_APP_ADDR
$ 172.17.0.102
I want to use this variable in my vhost, so I've added in the /etc/apache2/envvars file :
export DISTANT_APP_ADDR=${DISTANT_APP_ADDR}
In my vhost :
FastCgiExternalServer /var/www/cgi-bin/php5.external -host ${DISTANT_APP_ADDR}:9000
But when I restart apache, I've the error :
$ service apache2 restart
$ FastCgiExternalServer /var/www/cgi-bin/php5.external: failed to resolve "" to exactly one IP address
By replacing ${DISTANT_APP_ADDR} in the envvars file with the real value it's working.
I've also to to put a PassEnv DISTANT_APP_ADDR in my vhost file, but the result is the same.
How can I pass my env vars to my vhost file ?
export DISTANT_APP_ADDR=${DISTANT_APP_ADDR}
is nonsense. It does nothing if DISTANT_APP_ADDR is already set, and if it isn't set -- how does it know what to set?
You don't WANT the start script pulling your environment variable either. Suppose you, or someone else, does an apachectl restart one time, and you've forgotten you changed your env variable for some reason, 30 minutes ago. This is an administrator's nightmare - your web app "suddenly" stops working, but there's no change to any config file. It will be very very difficult to find out what went wrong.
So, by all means, set the DISTANT_APP_ADDR to something constant. Or use the SetEnv directive in httpd.conf or in some vhost config file. But never make a server service dependent on the environment the user happened to have when he started the service. (And when your system boots up, and apache gets started, the startup code doesn't know you're setting the variable in your .profile anyway).
If you really really want to shoot yourself in your foot, add
echo "DISTANT_APP_ADDR='$DISTANT_APP_ADDR'" > /tmp/apachefile
to the end of your .profile, and include that file into your envvars file.
Related
Is there any way we can override a value in a httpd configuration using system environment variables.
I have set env variable with export command and called that variable in to override a access.log to someone.log in httpd.conf file after restart of httpd it has created a log filename $someone.log.
I was logged in as a root user and set env, setting up for apache user will it help.
In Apache configuration files, the correct syntax is ${VAR}. If you used $VAR, it will not consider this a variable but a normal string.
See http://httpd.apache.org/docs/current/configuring.html
When writing configuration files for Apache web server I would like to have a quick feedback loop.
I, for example have a script that doesn't seem to work. It is either not picked up, or the variables I use are not set, or maybe overriding is not allowed. How to debug this?
I expected to at least print some debug log statements like REQUEST_URI: %{REQUEST_URI}. Can't find such a thing.
apachectl is a front end to the Apache HyperText Transfer Protocol (HTTP) server. It is designed to help the administrator control the functioning of the Apache httpd daemon.
Here is a link to the documentation.
Different platform might use different binary names such as apache, apache2 or apache2ctl. To test the configuration - just run:
apachectl configtest
# or, depending on your OS
httpd -t
EDIT
If you are trying to debug your virtual host configuration, you may find the Apache -S command line switch useful. That is, type the following command:
httpd -S
This command will dump out a description of how Apache parsed the configuration file
I have several vhost configured with there own conf file under conf.d. This works fine, but ever so often i have to make changes to one of the files and the reload apache. Is there a way where apache would skip that file if there is an error so that the other sites still goes up on a reload?
This is a prod site (and yes i should test all first, but that is not always practical).
It would be nice if I could change the file for domain1.conf do a service httpd restart and then if there is an error in the file that today would cause apache not to start at all it would simply skip that conf file and load start with all the others.
Hope this would work
Regards
Tore
This did the trick
apachectl configtest
https://serverfault.com/questions/774719/make-apache-reload-skipping-vhost-on-error
I've got a .htaccess file that I copied from one Apache HTTPD server and deployed onto another. Unfortunately, I foolishly didn't check the version of the destination server and just put the file in place; the site stopped working because it's Apache 2.4 and the file has 2.2 syntax. So I quickly reverted it to the previous version and hoped that nobody noticed!
Now, of course, I'm paranoid.
I tried copying the broken-on-2.4 version elsewhere and using apache2 -t .htaccess to find out what's wrong, but I get this error:
apache2: Could not open configuration file /etc/apache2/.htaccess: No such file or directory
If I supply the full path (i.e. apache2 -t /path/to/it/.htaccess) I get:
AH00534: apache2: Configuration error: No MPM loaded.
This error appears to be unrelated but I get the same error message and exit code (1) regardless of whether or not there's an error in the .htaccess file.
So my question is: can I use apache2 -t [...] to test a .htaccess file, and if not, what can I use instead (aside from the manual)? There is this site but it doesn't seem to allow me to say what version of Apache to check against.
I haven't found out how to do what I asked, but I have come up with a workaround.
I created a new directory on the server and put the incompatible .htaccess file in there. I then accessed the directory via my browser whilst tail -fing the error log (/var/log/apache2/error.log) to see what the problem was.
I am trying to set up Apache http 2.2, with mod_jk module.
The intention is to set up a load balancer right on my PC, for test purposes.
So I made some changes to httpd.conf to set some parameters, then I run it and I get the popup:
"Windows couldn't start Apache 2.2 on local PC. For more information check system events log. If it's not a windows service contact service provider and reference the code:1"
I check on the log and I get:
httpd.exe: Could not reliably determine the server's fully qualified domain name, using 192.168.0.35 for ServerName
So I uncomment on httpd.conf line: ServerName myPcName:80 and run it again.
I get the same popup, but this time I don't get anything on the events log.
Any idea on how to let it work?
(Nothing is bound on 80 port.)
Thank you
Please check if port 80 is being used by other application or not. Most of the time in my case "Skype" was using port 80. So I had to stop it and then I used to start Apache service.
To troubleshoot further what you can do is, goto apache's bin directory and run httpd.exe -t option. This will show you exactly what is causing problem.
The configuration file in the apache /conf folder, has a piece of code that starts from C:. It is copyrighted and therefore you cannot change the code.
All you have to do is make a second copy of the whole apache folder and put it directly in your C: directory. Your apache file is in System 32 causing you to use cprompt right. Having 2 identical apache folders one in C: and one in System 32 bypasses the problem.