0

I found a cool MySQL backup script. It's working fine on some hosting companies. Now I'm trying it on a different host running PHP Version 5.2.8.

I have a php.ini file that contains this (in both root dir and current dir):

disable_functions =. 

I'm getting these warnings, and it seems like they are more than warnings. If exec() doesn't run, the database is not backed-up.

Undefined variable: output in /home/nealsent/public_html/backups/backup_dbs.php on line 21
Undefined variable: res in /home/nealsent/public_html/backups/backup_dbs.php on line 210
exec() has been disabled for security reasons in /home/nealsent/public_html/backups/backup_dbs.php on line 210

The code is the following one.

// dump db
unset($output);

    // Line 210:
exec("$MYSQL_PATH/mysqldump $db_auth --opt $db 2>&1 >$BACKUP_TEMP/$db.sql", $output, $res);
apaderno
  • 28,547
  • 16
  • 75
  • 90
NealWalters
  • 17,197
  • 42
  • 141
  • 251

2 Answers2

4

Many hosts disable certain functions, and do not allow overriding them in custom php.ini's (just because PHP offers the ability to have a custom php.ini, does not mean that all PHP setups are necessarily configured to allow you to change that option via such).

Chances are that host simply doesn't allow exec() period. Not much you can really do about that.

Amber
  • 507,862
  • 82
  • 626
  • 550
  • (this Q&A now sits at the end of a lot od duplicate question links - but not all start with a question about managed/shared hosts) If you have control over the configuration, this behaviour is controlled by the disable_functions and safe_mode ini directives – symcbean May 04 '18 at 11:38
2

Another possibility is that exec has been disable by PHP safe mode. From the referenced page, it looks like you could avoid this by putting the script you are exec-ing into the PHP "safe mode exec dir".

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216