This is a very quick answer (a work in progress if you will), as I have not had time to test it, and it is way past my bed time. I will tidy up this answer tomorrow, once I have time to run it myself.
I think (I may be wrong) that you are missing an
export to expose the GPIO pins to PHP. You may need to do
gpio export 29
Thus, your script will become
system("gpio export 29");
system("gpio -g mode 29 out");
system("gpio -g write 29 1");
I have just found a thread on the Pi forums, PHP GPIO Library, that says the same thing, so maybe I am correct. There are some other interesting points raised in that thread, which you may find useful.
However, the export command is not included in many other examples/tutorials, so maybe it is not the way forward. For example, from PHP on Raspberry Pi, this HTML/PHP script does not include the
<meta name="viewport" content="width=device-width" />
<form method="get" action="gpio.php">
<input type="submit" value="ON" name="on">
<input type="submit" value="OFF" name="off">
$setmode17 = shell_exec("/usr/local/bin/gpio -g mode 17 out");
$gpio_on = shell_exec("/usr/local/bin/gpio -g write 17 1");
echo "LED is on";
$gpio_off = shell_exec("/usr/local/bin/gpio -g write 17 0");
echo "LED is off";
Note: As PandaLion98 says in their comment, getting scripts to run in Apache can be dangerous, if they are publicly facing.