php no me permite hacer `shell_exec('git pull origin master 2>&1');`

php no me permite hacer `shell_exec('git pull origin master 2>&1');`

Cuando ejecuto el script <?php chdir('/var/www/html'); echo shell_exec('git pull origin master 2>&1'); ?>, aparece el mensaje de error:

error: cannot open .git/FETCH_HEAD: Permission denied

Esto es lo que hice:

ssh [email protected]
pwd # shows that I'm already at /var/www as my home directory
ls .ssh/ # shows that I have id_rsa and id_rsa.pub, and id_rsa.pub is given to github
cd html
git pull origin master # everything downloads perfectly
echo "<?php chdir('/var/www/html'); echo shell_exec('git pull origin master 2>&1'); " > pull.php

Ahora cuando voy a http://example.com/pull.phpme sale el error cannot open .git/FETCH_HEAD: Permission denied.

Para confirmar mis permisos, inicié sesión como root para realizar un archivo chown -R apache:apache /var/www. También tengo esto en mi/etc/passwd

apache:x:48:48:Apache:/var/www:/bin/bash

¿Qué estoy haciendo mal?

Respuesta1

SELinux no permite que el servidor web escriba en directorios aleatorios. Debe definir explícitamente qué directorios SELinux debería permitir que se puedan escribir configurando su contexto predeterminado httpd_sys_rw_content_ty luego configurando el contexto de cualquier archivo existente. Por ejemplo:

semanage fcontext -a -t httpd_sys_rw_content_t "/var/www(/.*)?"
restorecon -rv /var/www

Sin embargo, es casi seguro que no deberías hacer que el servidor web pueda escribir en todo el sitio, ni configurar una página web que llame directamente a git. Ambos niegan por completo cualquier beneficio de seguridad que hubiera obtenido de SELinux, y este último tiene su propio conjunto de problemas potenciales.

información relacionada