I am trying to take the backup of PostgreSQL database using php. I have written the below code to run a batch file which has the command to take the backup. I am using Wampserver for development and the below coed works perfectly. But the problem is that it is not working on the server which is Windows Server 2008 R2. Please help.
The code I posted is for the local Wamp server, and it is working correctly. The path is different on the server. I have not posted server path because of security issues. Anyway there is no mix of slashes in that file and it is creating the backup file if I double click and run the cron.bat file on the server. I have also tried with exec() also but with no success.
so it seems that PHP is not even running the command… system() returns false on failure so maybe check on that… also it’s possible that those functions like system(), exec() and similar are disabled on the server. Check in the server php.ini the disable_functions option.
Seems there is no failure… btw. in the second example you need to remove "/c"…
The next thing I would test is to see if pg_dump is the problem… to test this you can comment the pg_dump line and put there something like dir > a.txt… so after running the PHP code if there is a file "a.txt" it means that calling the script works but the problem is in the pg_dump command.
So it seems it’s about the system() call… try to check the php error log file if there is more info.
Btw, are you executing from the browser or from the command line? Executing the PHP script from the command line might give more info if there is some errors.
as on CLI the script calling works I have 2 ideas now:
the command line PHP and the web server PHP have different configurations files (php.ini)… for example on my system (linux) the web server configuration is in /etc/php5/apache2/php.ini while the CLI configuration is in /etc/php5/cli/php.ini… so maybe check them to see if there are some difference regarding running system commands
maybe it’s something with permissions because if you run from the command line it runs as your user while when you run from the browser it runs as another user