The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Setting Apache -D parameters

Discussion in 'EasyApache' started by MZL, Oct 30, 2014.

  1. MZL

    MZL Member

    Joined:
    Oct 30, 2014
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I want to add a flag (environment variable) to Apache when it starts, adding "-D MY_FLAG" to the Apache launch command. I did it on other servers but have a problem doing it on my cPanel VPS.

    I use this flag for managing a conditional configuration of a virtual host: the same conf file (included in httpd.conf) will then work on both my LOCAL, DEV and PROD environments. The advantage of doing so is that I can version a single project's virtual host conf file in the project's git repo and auto deploy it when it changes, auto relaunch the Apache server, etc.

    I managed to configure this on my local environment (Mac OS) and the dev server (another CentOS server without cPanel) using the $OPTIONS variable in apachectl: in /etc/sysconfig/httpd I have uncommented the "$OPTIONS" line and set $OPTIONS to "-D MY_ENV_FLAG". This flag is then added automatically whenever Apache starts so I can then use <IfDefine MY_ENV_FLAG> in apache conf files. Neat!

    The problem is that it doesn't work on my cPanel server: from what I've read on the web, the /usr/sbin/apachectl file that I edited is not used by EasyApache, which uses the apachectl located in /usr/local/apache/bin. This second apachectl is an older version that doesn't take into account an $OPTIONS parameter. I could edit this file and add $OPTIONS to the launch command lines... but editing an EasyApache "core" file doesn't sound good. I will do it only if I have no other solution.

    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?

    So, do you guys see a way of adding this flag at launch?
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    649
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
  3. MZL

    MZL Member

    Joined:
    Oct 30, 2014
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    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.
     
  4. MZL

    MZL Member

    Joined:
    Oct 30, 2014
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    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?
     
  5. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    649
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  6. MZL

    MZL Member

    Joined:
    Oct 30, 2014
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    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:
    Code:
    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 <IfDefine MY_FLAG> 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:

    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).
     
  7. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    649
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
  8. MZL

    MZL Member

    Joined:
    Oct 30, 2014
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I created the following ticket to get support for this issue: 5656317
     
  9. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    649
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    To update, here is a summary of the response sent by an analyst:

     
Loading...

Share This Page