我正在尝试使用 PHP composer
命令安装shell_exec
,如composer official site中所述。
我的服务器linux是centOS 6
。
shell_exec('curl -sS https://getcomposer.org/installer | php');
/*
* OR
*/
shell_exec('php -r "readfile(\'https://getcomposer.org/installer\');" | php');
但是有权限错误:
> Downloading...
>Could not create file /myfolder/composer.phar
>
> fopen(/myfolder/composer.phar): failed to open stream: Permission denied Download failed:
>
> fopen(/myfolder/composer.phar): failed to open stream:
>
> Permission denied fwrite() expects parameter 1 to be
> resource, boolean given
>Downloading... Could not create file to open stream: composer.phar:
>
>etc...
因此,我尝试使用此命令将用户更改为root:
shell_exec('su -root; myPass; whoami');
//And
shell_exec('su - root; myPass; whoami');
//And
shell_exec('su -u root -p myPass; whoami');
再次whoami
返回 apache
似乎用户apache
没有安装编辑器和创建目录的权限,所以我尝试在之前的命令之后安装composer,但仍然存在同样的问题。
请您告诉我我的命令有问题或者问题是什么?
提前致谢
答案 0 :(得分:0)
您不能以这种方式提供su
密码。事实上,我认为根本没有办法(there is a way for sudo
)
但是出于安全原因,升级到root是一个非常糟糕的想法。相反,您应该对apache
授予/myfolder/
个写入权限。