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.

Help to mass-change php_value in all .htaccess

Discussion in 'General Discussion' started by kjetiljen, Aug 18, 2009.

  1. kjetiljen

    kjetiljen Registered

    Joined:
    Aug 18, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Hi folks,

    I was wondering if someone could help me with a small thing, I got around 450 users on a server that newly upgraded to PHP-CGI, and of course php_value is not supported so I manage all via the global php.ini file now instead which is just fine.

    But can someone help me to remove all the php_value tags in all .htaccess files?

    Some .htaccess has around 3-4 php_value commands and some files just one php_value command, and that is kind of driving me crazy, tried this one but I am not sure if I got it right.

    ls -1 /home/*/domains/*/public_html/.htaccess | xargs sed -i 's/^php_value/#php_value/g'

    But the problem here is that the list will be too long and similar, or it just changes the "first" rows and not all php_value it finds in the .htaccess file.

    So in other words.

    php_value register_globals=on

    to:

    #php_value register_globals=on

    Thanks in advance, and I hope you understood what I ment.
     
  2. xprt5

    xprt5 Well-Known Member

    Joined:
    Apr 6, 2003
    Messages:
    72
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Houston
    Crude but the following command will add the # before every php_value for all users disabling the option.

    find /home/*/public_html -type f -name .htaccess |xargs replace "php_value" "#php_value" --
     
  3. kjetiljen

    kjetiljen Registered

    Joined:
    Aug 18, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Thanks so much for your fast reply.

    I guess you mean --replace after xargs?

    If not, then you have this error:

    # find . -type f -name .htaccess |xargs replace "php_value" "#php_value" --
    xargs: replace: No such file or directory

    But if I try this one where I got a .htaccess in that directory I am standing in and 3 lines of php_value in that file I get this error:

    # find . -type f -name .htaccess |xargs --replace "php_value" "#php_value" --
    xargs: php_value: No such file or directory

    I am not a big fan of all this so that is why I am asking for help, which is highly appreciated.
     
  4. xprt5

    xprt5 Well-Known Member

    Joined:
    Apr 6, 2003
    Messages:
    72
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Houston
    The command should work as i provided it.

    find /home/*/public_html -type f -name .htaccess |xargs replace "php_value" "#php_value" --

    This will look for all .htaccess files in /home/anyuser/public_html then replace the value in quotes "" with the 2nd value in quotes "".

    I tested this on my own server and it worked just as typed.
     
  5. thewebhosting

    thewebhosting Well-Known Member

    Joined:
    May 9, 2008
    Messages:
    1,201
    Likes Received:
    1
    Trophy Points:
    38
    Yes, the command seems to be correct. It should work.
     
  6. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    The instructions given in this thread only focus on helping you to disable any custom PHP commands found in .htaccess files which in some cases could cause some scripts to function incorrectly if they actually do really need the settings which you are disabling.

    I have a scanning application which will check your entire server for .htaccess files with embedded PHP override commands (PHP_FLAG and PHP_VALUE) and will remove those commands from the .htaccess file and help you automatically build custom PHP configurations for those accounts that need the setting changes and export the previous .htaccess commands off to the new custom configuration for the account.

    In addition to the above, my program also repairs any file ownership or permission problems in the process that you also commonly run into during the transition from DSO based PHP to SuPHP based PHP.

    This makes the transition much easier and pretty much takes away all of the usual typical headaches you get with this type of migration since everything is done entirely automated and takes only a few minutes to update the server.

    If interested in the above, contact me ....

    Otherwise, I would recommend you go through each account and review all the .htaccess files where you have disabled PHP override commands by commenting them out as recommended by previous users and try to determine which of those overrides are necessary for user scripts and see about moving those off to custom PHP.INI configurations for the user(s).

    Also, since you mentioned you just moved away from DSO (Apache module) based PHP, you will also need to make sure that your users do not have any script files or folders with 0777 or 0666 permission settings. For any folders with either of these, I would set the folder to permission 0755. For PHP scripts, generally set to 0400, 0600, or 0640.

    None of the user files should be owned by user "nobody" anymore, so if you run into any files under the accounts
    setup as these, they will need to be reset back to the account owner login name.
     
    #6 Spiral, Aug 18, 2009
    Last edited: Aug 18, 2009
  7. kjetiljen

    kjetiljen Registered

    Joined:
    Aug 18, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    It worked just fine, thank you very much.

    In my case, I needed to install the MySQL package so I could use the replace command.
     
  8. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    Regarding your last statement, "php_value" is only one of the override commands you need to comment out in the .htaccess files.

    You also need to comment out any "php_flag" commands as well! :rolleyes:

    Basically issue the same command you used again but change "php_value" to "php_flag" everywhere it appeared in the comand you used.

    Beyond that, take note of the other items given in my previous post above.
     
Loading...

Share This Page