Run windows command in php
exec, php, system
Solution
If you are able to run your commands manually from the command-line, but not via WAMP, than the user the Apache Service runs as does not have the needed permissions to execute your commands and binaries (nor interact with the desktop if it is GUI related).
By default, Apache service run under user account: nt authority\system
Change it to your custom user (user with administrative rights) by following below steps,
- Hit Windows+R which opens Run
- Type "services.msc" which opens list of windows services
- Find and select your apache service and open its properties
- Go to Logon tab and change the account From “Local System” to another user/account
- Restart your Apache service
Happy coding :-)
Problem
Is it possible to run windows command line code from php ? My windows command line code is: ``` <?php error_reporting(E_ALL); try { echo exec('C:\xampp\mysql\bin>mysqlbinlog --start-datetime="2011-04-21 10:31:44" c:\xampp\mysql\data\binlog\bin-log.000001 > c:\xampp\mysql\data\binlog\sql.txt'); } catch (Exception $e) { echo $e->getMessage(); } ``` Now I want to run this code from PHP using `system()` or `exec()` etc. any help appreciated.