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.

Set Safe_mode On and Off!

Discussion in 'General Discussion' started by yawsh, Dec 31, 2006.

  1. yawsh

    yawsh Well-Known Member

    Joined:
    Jun 20, 2004
    Messages:
    48
    Likes Received:
    0
    Trophy Points:
    6
    Hi,
    My php.ini has safe_mode value On

    To check it we use:


    I need to set safe_mode = off for about 2 min daily to run some cron jobs.


    Is there any known ssh commands to set it from a command line rather than doing it from the editor? so I would make it in a file to switch it off at 0200 and run cron jobs at 0201 and then back on at 0202.

    Experts, Any help?! :rolleyes:
     
  2. Nhojohl

    Nhojohl Well-Known Member

    Joined:
    Nov 28, 2006
    Messages:
    101
    Likes Received:
    0
    Trophy Points:
    16
    You could have something like...two php.ini files. Make a cron job in...

    # crontab -e

    And have it execute something like...

    # cp /usr/local/Zend/etc/php.ini /usr/local/Zend/etc/php-safe.ini
    # cp /usr/local/Zend/etc/php-unsafe.ini /usr/local/Zend/etc/php.ini
    # service httpd restart

    And then do your cron job that you needed safemode off for and then have another cron executed lastly a minute later doing...

    # cp /usr/local/Zend/etc/php.ini /usr/local/Zend/etc/php-unsafe.ini
    # cp /usr/local/Zend/etc/php-safe.ini /usr/local/Zend/etc/php.ini
    # service httpd restart

    In the normal php.ini file you'd have your safe mode on, then all you'd need to do is copy your php.ini and make one named php-unsafe.ini and in it change safe_mode to off.

    Providing you can physically make a cron restart apache (httpd)... it should work;)
     
  3. yawsh

    yawsh Well-Known Member

    Joined:
    Jun 20, 2004
    Messages:
    48
    Likes Received:
    0
    Trophy Points:
    6
    I'm doing that currently. :) with 2 php.ini files called

    php.ini ----> safe mode = on
    php.ini.off ----> safe mode = off

    and renaming them by a 2 cron jobs files and restart apache

    _phpini-rename2off.sh
    _phpini-rename2on.sh

    Thanks Nhojohl

    Any other way guys?
     
  4. yapluka

    yapluka Well-Known Member

    Joined:
    Dec 24, 2003
    Messages:
    301
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    France
    cPanel Access Level:
    Root Administrator
    What about using the command "replace" ?

    Code:
    #!/bin/bash
    replace "safe mode = on" "safe mode = off" -- /usr/local/lib/php.ini
    /path/to/your/script
    replace "safe mode = off" "safe mode = on" -- /usr/local/lib/php.ini
     
  5. Nhojohl

    Nhojohl Well-Known Member

    Joined:
    Nov 28, 2006
    Messages:
    101
    Likes Received:
    0
    Trophy Points:
    16
    I think you may be on to something...:eek:
     
  6. yawsh

    yawsh Well-Known Member

    Joined:
    Jun 20, 2004
    Messages:
    48
    Likes Received:
    0
    Trophy Points:
    6
    Thanks yapluka

    I tried to do it.

    It worked fine for me.


    php.ini is linked to Zend
    PHP:
    php.ini -> /usr/local/Zend/etc/php.ini
    When I replaced Safe_mode = on to = off .. it converted the file and removed the link:
    PHP:
    replace "safe_mode = On" "safe_mode = Off" -- /usr/local/lib/php.ini ; /etc/init.d/httpd restart
    /usr/local/lib/php.ini converted
    /etc/init.d/httpd restarthttpd restarted
    Also when I did it visa versa:
    PHP:
    replace "safe_mode = Off" "safe_mode = On" -- /usr/local/lib/php.ini ; /etc/init.d/httpd restart
    /usr/local/lib/php.ini converted
    /etc/init.d/httpd restarthttpd restarted
    Then I lost Zend. All sites with zend scripts are down. Thanks GOD I had a backup of my php.ini file :D

    Any fix!
     
  7. yapluka

    yapluka Well-Known Member

    Joined:
    Dec 24, 2003
    Messages:
    301
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    France
    cPanel Access Level:
    Root Administrator
    Then you would use this command :

    Code:
    replace "safe_mode = On" "safe_mode = Off" -- /usr/local/Zend/etc/php.ini
     
  8. yawsh

    yawsh Well-Known Member

    Joined:
    Jun 20, 2004
    Messages:
    48
    Likes Received:
    0
    Trophy Points:
    6
    It was giving same problem...

    But I did some tweaking :)

    PHP:
    replace "safe_mode=on" ";safe_mode=on" -- /usr/local/Zend/etc/php.ini replace ";safe_mode=off" "safe_mode=off" -- /usr/local/Zend/etc/php.ini ; /etc/init.d/httpd restart
    replace 
    ";safe_mode=on" "safe_mode=on" -- /usr/local/Zend/etc/php.ini replace "safe_mode=off" ";safe_mode=off" -- /usr/local/Zend/etc/php.ini ; /etc/init.d/httpd restart
    The code woring fine now ... Thanks a lot yapluka
     
  9. yapluka

    yapluka Well-Known Member

    Joined:
    Dec 24, 2003
    Messages:
    301
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    France
    cPanel Access Level:
    Root Administrator
    Glad to know it's working now :)
     
Loading...

Share This Page