如何configurationSELinux以允许Apache运行git

我有一个CentOS 6服务器,我试图让Apache Web服务器在目录中运行git pull

这个php文件很简单:

 <?php shellexec('cd /var/www/vhosts/domain;git pull'); 

但是,当通过浏览器请求文件时, git pull命令不会运行。

暂时closuresSELinux运行setenforce 0允许它运行,但这不是一个安全的解决scheme。

/ var / log / audit在请求文件时显示以下错误。

 type=AVC msg=audit(1401182476.567:363184): avc: denied { read } for pid=11082 comm="ssh" name="known_hosts" dev=dm-0 ino=11272197 scontext=system_u:system_r:httpd_sys_script_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file 

在Permissive模式(setenforce 0)下临时运行SELinux。 执行正常的操作,以便将错误logging到audit.log。

然后你可以使用audit2why来解释这个问题。 您可以使用audit2allow生成可加载的策略模块。 所以例如

 audit2allow <wyred.log type=AVC msg=audit(1401182476.567:363184): avc: denied { read } for pid=11082 comm="ssh" name="known_hosts" dev=dm-0 ino=11272197 scontext=system_u:system_r:httpd_sys_script_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file Was caused by: Missing type enforcement (TE) allow rule. You can use audit2allow to generate a loadable module to allow this access. 

然后

 audit2allow -M wyred <wyred.log ******************** IMPORTANT *********************** To make this policy package active, execute: semodule -i wyred.pp 

会生成一个.pp文件和一个可读的.te文件。