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.

change ScriptAlias for one VirtualHost

Discussion in 'General Discussion' started by danf, Apr 3, 2008.

  1. danf

    danf Active Member

    Joined:
    Apr 10, 2006
    Messages:
    26
    Likes Received:
    0
    Trophy Points:
    1
    How can I change ScriptAlias for /cgi-bin/ for just one VirtualHost? I have this in /usr/local/apache/conf/httpd.conf:

    ScriptAlias /cgi-bin/ /home/example/public_html/cgi-bin/

    Include "/usr/local/apache/conf/userdata/*.conf"
    Include "/usr/local/apache/conf/userdata/*.owner-root"
    Include "/usr/local/apache/conf/userdata/std/*.conf"
    Include "/usr/local/apache/conf/userdata/std/*.owner-root"
    Include "/usr/local/apache/conf/userdata/std/2/*.conf"
    Include "/usr/local/apache/conf/userdata/std/2/*.owner-root"
    Include "/usr/local/apache/conf/userdata/std/2/example/*.conf"
    Include "/usr/local/apache/conf/userdata/std/2/example/example.com/*.conf"

    In /usr/local/apache/conf/userdata/std/2/example/example.com/vhost.conf, I have this:

    ScriptAlias /cgi-bin/ /home/example/cgi-bin/

    When I restart Apache, I get this message:

    [Thu Apr 03 03:00:30 2008] [warn] The ScriptAlias directive in /usr/local/apache/conf/userdata/std/2/example/example.com/vhost.conf at line 1 will probably never match because it overlaps an earlier ScriptAlias.

    Sure enough, the later ScriptAlias is ignored. I would like to use /home/example/cgi-bin/ as /cgi-bin. How can I do that?

    Thanks.

    --df
     
  2. LiNUxG0d

    LiNUxG0d Well-Known Member

    Joined:
    Jun 25, 2003
    Messages:
    206
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Gatineau, Quebec, Canada
    Hey there,

    My suggestion, if it's for just one VHost is to edit "/usr/local/apache/conf/httpd.conf" using your favorite editor. My pick is nano, the search feature is awesome.

    In nano, I hit CTRL-W to prompt a search, and search for: ServerName example.com

    You should be on the "example.com" VAlias, which might look something like this:

    Code:
    <VirtualHost 1.2.3.4:80>
        ServerName example.com
        ServerAlias www.example.com
        DocumentRoot /home/example/public_html
        ServerAdmin webmaster@example.com
        UseCanonicalName Off
        CustomLog /usr/local/apache/domlogs/example.com combined
        CustomLog /usr/local/apache/domlogs/example.com-bytes_log "%{%s}t %I .\n%{%s}t %O ."
        ## User example # Needed for Cpanel::ApacheConf
        <IfModule mod_suphp.c>
            suPHP_UserGroup example example
        </IfModule>
        <IfModule concurrent_php.c>
            php4_admin_value open_basedir "/home/example:/usr/lib/php:/usr/php4/lib/php:/usr/local/lib/php:/usr/local/php4/lib/php:/tmp"
            php5_admin_value open_basedir "/home/example:/usr/lib/php:/usr/local/lib/php:/tmp"
        </IfModule>
        <IfModule !concurrent_php.c>
            <IfModule mod_php4.c>
                php_admin_value open_basedir "/home/example:/usr/lib/php:/usr/php4/lib/php:/usr/local/lib/php:/usr/local/php4/lib/php:/tmp"
            </IfModule>
            <IfModule mod_php5.c>
                php_admin_value open_basedir "/home/example:/usr/lib/php:/usr/local/lib/php:/tmp"
            </IfModule>
            <IfModule sapi_apache2.c>
                php_admin_value open_basedir "/home/example:/usr/lib/php:/usr/php4/lib/php:/usr/local/lib/php:/usr/local/php4/lib/php:/tmp"
            </IfModule>
        </IfModule>
        <IfModule !mod_disable_suexec.c>
            SuexecUserGroup example example
        </IfModule>
        ScriptAlias /cgi-bin/ /home/example/public_html/cgi-bin/
    </VirtualHost>
    
    The very last line, before the </Virtualhost> directive is the CGI-BIN location. You can change it there. The destination must be readable by Apache. If you're running SuPHP, you might need to make sure the ownerships are correct as well.

    Hope this helps you,
     
  3. danf

    danf Active Member

    Joined:
    Apr 10, 2006
    Messages:
    26
    Likes Received:
    0
    Trophy Points:
    1
    Thanks, but I didn't think it was safe to edit that file directly. It is full of comments like this:

    # DO NOT EDIT. AUTOMATICALLY GENERATED. IF YOU NEED TO MAKE A CHANGE PLEASE USE THE INCLUDE FILES.

    I don't want to make manual changes to a file that will be overwritten by cPanel later.

    --df
     
  4. LiNUxG0d

    LiNUxG0d Well-Known Member

    Joined:
    Jun 25, 2003
    Messages:
    206
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Gatineau, Quebec, Canada
    Hey there,

    Yeah, I know what you mean. I've never had any really bad experiences with it though. Perhaps someone has another suggestion. When it comes to custom CGI bins, I suggest manual edits.

    I am not 100% sure if cPanel can change the location of the ScriptAlias directive as defaults for VHosts are usually "/home/user/public_html/cgi-bin/".

    Let me know if you get a better solution. This one is tried, tested and true. I've rebuilt Apache before and never had disappearing ScriptAlias tweaks... then again, I don't really do it too often.

    :)

    Cheers,
     
  5. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    It's generally a bad idea to edit httpd.conf directly in a cPanel/WHM environment. As noted, use the include files which you can edit in WHM -> Service Configuration -> Apache Setup -> Include Editor otherwise if the include editor is insufficient, refer to the documentation at http://www.cPanel.net/support/docs/ea/ea3
     
  6. LiNUxG0d

    LiNUxG0d Well-Known Member

    Joined:
    Jun 25, 2003
    Messages:
    206
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Gatineau, Quebec, Canada
    David,

    Granted, there's those Include Editors, can you clarify on exactly how to achieve modifying a default CGI-BIN ScriptAlias for ONE VHost using it? I don't think this is possible is it?

    In my travels, the only way to do this is via the /usr/local/apache/conf/httpd.conf file directly.

    Please advise,
     
    #6 LiNUxG0d, Apr 4, 2008
    Last edited: Apr 4, 2008
  7. danf

    danf Active Member

    Joined:
    Apr 10, 2006
    Messages:
    26
    Likes Received:
    0
    Trophy Points:
    1
    I only want to change ScriptAlias for one VirtualHost. If you re-read my original post, you'll see that I've already tried adding the correct ScriptAlias to /usr/local/apache/conf/userdata/std/2/example/example.com/vhost.conf, but then I get an error, and the new setting is ignored. Please see original post.

    Thanks.

    --df
     
  8. FeeL

    FeeL Well-Known Member

    Joined:
    Apr 17, 2004
    Messages:
    135
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    Rio de janeiro
    cPanel Access Level:
    Reseller Owner
    same here

    I have the sema problem as Danf.

    DocumentRoot /home/client/public_html

    I only need to change this single line.:confused:

    Thank you
     
  9. LiNUxG0d

    LiNUxG0d Well-Known Member

    Joined:
    Jun 25, 2003
    Messages:
    206
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Gatineau, Quebec, Canada
    Hey guys,

    If you're looking to make this a feature, please write up a cPanel ticket or make a request via their site. If you're looking to fix it now, edit the httpd.conf and change the VHost manually as I suggested above.

    I know the httpd.conf is auto-generated, but I have rarely seen changes just... vanish.

    It's just like if you wanted to add a wildcarded Valias, you have to edit the httpd.conf to change the ServerAlias to "*.domain.com". You can't do it anywhere else, and you really don't have a choice but to manually edit the httpd.conf. If cPanel is so adamant on getting changes to go through the WHM, they should make this file editable via the WHM interface just like they do for the exim.conf, AKA: "httpd configuration file editor".

    I really don't think cPanel facilitate this kind of thing right now via the WHM interface.

    Regards,
     
    #9 LiNUxG0d, Apr 11, 2008
    Last edited: Apr 11, 2008
  10. brondsem

    brondsem Registered

    Joined:
    Apr 4, 2008
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    You can put additional Apache directives in a file at /usr/local/apache/conf/userdata/std/2/username/my.domain.com/*.conf After that you should run /scripts/ensure_vhost_includes --user=username to make sure all the "Include" statements are in the main httpd.conf (danf's original post has those).

    To change Apache directives, like a DocumentRoot or ScriptAlias, you can modify /var/cpanel/userdata/username/my.domain.com and change/delete "documentroot:" line or the "scriptalias:" lines. Then run /scripts/buildhttpdconf

    That file gets processed through one of the templates at /var/cpanel/templates/apache2/ If you need to, you can copy the appropriate template (vhost.default or ssl_vhost.default) and then change that even more. To use the new template, modify the file mentioned in the above paragraph, and add a line "custom_vhost_template_ap2: /var/cpanel/templates/apache2/vhost.mycustom". Then run /scripts/buildhttpdconf

    I'm pretty sure that cpanel/whm writes and reads these config files but doesn't have a way to change all the values, like you can if you edit the file directly. Using these will let you preserve your changes, instead of putting them directly in httpd.conf and risking them getting overwritten.

    See http://www.cpanel.net/support/docs/ea/ea3/index.html for more documentation on this.
     
  11. Stefaans

    Stefaans Well-Known Member

    Joined:
    Mar 5, 2002
    Messages:
    451
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    Vancouver, Canada
    Brondsem, everything you say is indeed explained in http://www.cpanel.net/support/docs/ea/ea3/index.html. However, that document is so bloated that I could not drill down to the essentials for customizing httpd.conf. Your explanation puts it in a nutshell. Thanks!
     
  12. LiNUxG0d

    LiNUxG0d Well-Known Member

    Joined:
    Jun 25, 2003
    Messages:
    206
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Gatineau, Quebec, Canada
    Excellent post my friend!

    This piece has been missing in my book. :) I always like using "you have to edit the httpd.conf" because it usually prompts someone to correct me. ;)

    Thanks for the correction; danf should be good to go now!

    Have a great weekend!
     
Loading...

Share This Page