Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Member
    Join Date
    Jun 2004
    Posts
    48

    Exclamation Set Safe_mode On and Off!

    Hi,
    My php.ini has safe_mode value On

    To check it we use:

    grep -i "safe_mode" /usr/lib/php.ini

    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?!
    http://www.yawsh.com

  2. #2
    Member
    Join Date
    Nov 2006
    Posts
    101

    Default

    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. #3
    Member
    Join Date
    Jun 2004
    Posts
    48

    Default

    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
    #Change php.ini safe_mode on to off
    mv /usr/local/lib/php.ini /usr/local/lib/php.ini.on
    mv /usr/local/lib/php.ini.off /usr/local/lib/php.ini
    #service httpd restart
    /etc/init.d/httpd restart
    _phpini-rename2on.sh
    #Change php.ini safe_mode off to on
    mv /usr/local/lib/php.ini /usr/local/lib/php.ini.off
    mv /usr/local/lib/php.ini.on /usr/local/lib/php.ini
    #service httpd restart
    /etc/init.d/httpd restart

    Thanks Nhojohl

    Any other way guys?
    http://www.yawsh.com

  4. #4
    Member
    Join Date
    Dec 2003
    Location
    France
    Posts
    300
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    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
    Marie - Co-Owner
    Need Further Assistance ? Here you go !
    English, french and spanish support

  5. #5
    Member
    Join Date
    Nov 2006
    Posts
    101

    Default

    Quote Originally Posted by yapluka View Post
    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
    I think you may be on to something...

  6. #6
    Member
    Join Date
    Jun 2004
    Posts
    48

    Default

    Thanks yapluka

    I tried to do it.

    It worked fine for me.


    php.ini is linked to Zend
    PHP Code:
    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 Code:
    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 Code:
    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

    Any fix!
    http://www.yawsh.com

  7. #7
    Member
    Join Date
    Dec 2003
    Location
    France
    Posts
    300
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Then you would use this command :

    Code:
    replace "safe_mode = On" "safe_mode = Off" -- /usr/local/Zend/etc/php.ini
    Marie - Co-Owner
    Need Further Assistance ? Here you go !
    English, french and spanish support

  8. #8
    Member
    Join Date
    Jun 2004
    Posts
    48

    Default

    It was giving same problem...

    But I did some tweaking

    PHP Code:
    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
    http://www.yawsh.com

  9. #9
    Member
    Join Date
    Dec 2003
    Location
    France
    Posts
    300
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Glad to know it's working now
    Marie - Co-Owner
    Need Further Assistance ? Here you go !
    English, french and spanish support

Similar Threads & Tags
Similar threads

  1. PEAR and safe_mode
    By nazoreen in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 06-05-2009, 09:14 AM
  2. Global safe_mode ON, want Local safe_mode OFF
    By hoball in forum cPanel and WHM Discussions
    Replies: 9
    Last Post: 06-04-2009, 10:29 AM
  3. enable safe_mode for particular account
    By valleytech in forum cPanel and WHM Discussions
    Replies: 9
    Last Post: 12-26-2007, 08:05 AM
  4. PHP safe_mode
    By Echelon17 in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 06-16-2006, 10:00 AM
  5. php safe_mode, phpSuExec and nobody
    By SupermanInNY in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 04-12-2004, 01:03 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube