Apache

Run php code as root (wrapper method)

1) Create a script (preferrably .sh) that contains what you want to be ran as root.

# cat > php_shell.sh < wrapper.c <<CONTENT
#include
#include
#include

int
main (int argc, char *argv[])
{
setuid (0);

/* WARNING: Only use an absolute path to the script to execute,
* a malicious user might fool the binary and execute
* arbitary commands if not.
* */

system (“/bin/sh /path/to/php_shell.sh”);

return 0;
}
CONTENT
4) Compile and set proper permissions, including the suid bit (saying that it should run with root privileges):

# gcc wrapper.c -o php_root
# chown root php_root
# chmod u=rwx,go=xr,+s php_root
php_root will now run with root permissions, and execute the commands specified in php_root.sh.

Address already in use: make_sock: could not bind to address 0.0.0.0:80

Happens with httpd with ssl and key with passphrase

Simply find the httpd process, kill it, restart from shell and insert passphrase

  1. netstat -ltnp | grep ‘:80’    (use sudo if u’re not root)
  2. the result is something like “tcp        0      0 0.0.0:80                       0.0.0.0*                        LISTEN      1524/httpd”
  3. kill -9 1524   (use sudo if not root)
  4. service httpd restart (and insert ssl pwd)