yawsh

Well-Known Member
Jun 20, 2004
48
0
156
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?! :rolleyes:
 

Nhojohl

Well-Known Member
Nov 28, 2006
101
0
166
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;)
 

yawsh

Well-Known Member
Jun 20, 2004
48
0
156
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?
 

yapluka

Well-Known Member
Dec 24, 2003
301
1
168
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
 

Nhojohl

Well-Known Member
Nov 28, 2006
101
0
166
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...:eek:
 

yawsh

Well-Known Member
Jun 20, 2004
48
0
156
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 restart: httpd 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 restart: httpd 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!
 

yapluka

Well-Known Member
Dec 24, 2003
301
1
168
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
 

yawsh

Well-Known Member
Jun 20, 2004
48
0
156
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