Skip to main content

Setting Apache -D parameters

Comments

8 comments

  • cPanelMichael
    ] I found this page in the documentation that explains how to add environment variables to EasyApache, but I understand this process adds the variables to the compiled Apache: building Apache again is needed for the new variable to be taken into account. This doesn't suit my needs, why should I compile the server when I only want to add a flag at launch command, which is a native feature of Apache?

    Hello :) Could you elaborate further on why you prefer to avoid running EasyApache? Is this something you will need to change multiple times where the amount of time to rebuild Apache will slow things down? Thank you.
    0
  • MZL
    First, and as said, it doesn't seem right to me, to rebuild the whole thing just in order to add a flag, while Apache allows this in the launch command. But I'll elaborate further anyway :) Actually, what I do on the other environments is I don't edit the $OPTIONS directly in the /etc/sysconfig/httpd file, I only source a file inside it. This sourced file is managed in git and auto deployed, and should it change, a restart of the Apache server is triggered. In this worfklow, if i decide to add a new flag and rely on it, I want the flag to be available at the same time the rest of the code that depends on it is deployed (I mean, just after Apache has restarted). I don't want to have to deal with controlling EasyApache in my deploy script, where only an "apachectl restart" (or "/scripts/restartsrv_httpd") command should suffice.
    0
  • MZL
    No one ? I have tried to add the -D MY_FLAG directly inside /usr/local/apache/bin/apachectl but even there it has no effect. I don't undestand, I have checked inside /scripts/restartsrv_httpd and this apachectl script is really called when Apache is (re)started, so how come I can access the flag?
    0
  • cPanelMichael
    I don't believe there's a supported alternative to what's documented here: Environment Variables You could submit a feature request for alternate functionality via: Submit A Feature Request Thank you.
    0
  • MZL
    I have tried the procedure explained in the link you provide and it doesn't work (neither the "add" nor the "append" methods work). For example, trying to add the variable, I did the following: 1. Create the mentioned file:
    echo 1 > /var/cpanel/easy/apache/rawenv/MY_FLAG
    2. Run EasyApache 3. Test an Apache rule in the virtual host which is embedded inside an block: the rule doesn't work, showing that MY_FLAG is not defined as a launch parameter. So the solution you propose doesn't work :-( (Another check: if I then test the build parameters of Apache using httpd -V, I see: Server compiled with... -D APACHE_MPM_DIR="server/mpm/prefork" -D APR_HAS_SENDFILE... But there is no "-D MY_FLAG in the list). I think that's because these are instructions to define Apache environment variables, whereas all I want is setting a parameter when the server is started, as explained in the Apache IfDefine documentation: The parameter-name argument is a define as given on the httpd command line via -Dparameter-, at the time the server was started.
    I have also tried to use Raw Opts, adding "MY_FLAG=1" into file /var/cpanel/easy/apache/rawopts/Apache2_2 as explained in the cPanel Raw Opts documentation, but this didn't work neither, I think because it adds an environment variable but that's not what I need. So, I come back to what I think is the heart of the problem: how come that when I add a "-D MY_FLAG" in the apachectl script that is used by EasyApache to launch httpd (/usr/local/apache/bin/apachectl), this flag isn't really created? Editing in the following way the line of the script where the path of the httpd binary is set: HTTPD='/usr/local/apache/bin/httpd -DMY_FLAG' should result in the availability of the flag after apache restart, and it doesn't. Why? (editing this file is not a long term solution as said in my previous posts, it just an attempt to understand what goes wrong).
    0
  • cPanelMichael
    Please considering opening a support ticket using the link in my signature so we can take a closer look. You can post the ticket number here so we can update this thread with the outcome. Thank you.
    0
  • MZL
    I created the following ticket to get support for this issue: 5656317
    0
  • cPanelMichael
    To update, here is a summary of the response sent by an analyst: Unfortunately there is no mechanism to set custom commandline flags in easyapache, nor is there a file to load them from. Currently, the only way to do this is to edit /usr/local/apache/bin/apachectl and /etc/init.d/httpd It is safe to modify these files provided it is done correctly, however as noted the modifications would be overwritten whenever easyapache is run. Note that it is possible to have a script that runs after easyapache, named /scripts/posteasyapache You could automate re-adding the flags as so: #!/bin/bash FLAGS="-Dwhat=1 -Dfoo=bar" perl -i -pe "s/^\s*(.HTTPD -k .ARGV.*|.HTTPD -k start -DSSL.*)/\$1 $FLAGS/g;" /usr/local/apache/bin/apachectl /etc/init.d/httpd Please note, the above example is *not* supported and can likely be written better.
    0

Please sign in to leave a comment.