By 大伟哥 |
昨天只是按常规安装和配置了composer,现在我们在接下来的学习和实践中会碰到一个问题,就是如何以www-data的身份运行Composer。
为什么用www-data用户运行Composer?
因为Ubuntu Server下面,Apache的用户组www-data,运行PHP的也是www-data,把网站文件的所有者和组属性设置成www-data:www-data,可以在保证安全的前提下避免网站运行中出现权限问题,所以很多教程都会告诉你修改网站文件的所有权或者权限。
如果如果使用www-data用户运行Composer,那么下载下来的文件所有者就会自动设置为www-data,这样就可以避免每次都要手动运行chown命令了。
那么如何使用www-data用户运行Composer呢?
我们需要解决一个问题,就是www-data这个用户,不是一个普通的用户,没法直接登录。因为/etc/passwd文件里,www-data是这样定义的:
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
如果我们使用sudo su www-data切换用户,就会得到“This account is currently not available.”的错误提示。但我们可以使用sudo su - www-data -s /bin/bash命令给www-data用户启动一个bash,来执行composer命令:
daweibro@ubuntu:~$ sudo su - www-data -s /bin/bash www-data@ubuntu:~$ ls html
这时我们再次修改配置文件,使用阿里云给大家提供的国内Composer镜像:
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
再查看composer的全局配置文件,就会发现Composer的运行环境都放在/var/www/目录下了:
www-data@KingChef-Workstation:~$ composer config -gl
[repositories.packagist.org.type] composer
[repositories.packagist.org.url] https://mirrors.aliyun.com/composer/
[process-timeout] 300
[use-include-path] false
[preferred-install] auto
[notify-on-install] true
[github-protocols] [https, ssh]
[vendor-dir] vendor (/var/www/vendor)
[bin-dir] {$vendor-dir}/bin (/var/www/vendor/bin)
[cache-dir] /var/www/.cache/composer
[data-dir] /var/www/.local/share/composer
[cache-files-dir] {$cache-dir}/files (/var/www/.cache/composer/files)
[cache-repo-dir] {$cache-dir}/repo (/var/www/.cache/composer/repo)
[cache-vcs-dir] {$cache-dir}/vcs (/var/www/.cache/composer/vcs)
[cache-ttl] 15552000
[cache-files-ttl] 15552000
[cache-files-maxsize] 300MiB (314572800)
[bin-compat] auto
[discard-changes] false
[autoloader-suffix]
[sort-packages] false
[optimize-autoloader] false
[classmap-authoritative] false
[apcu-autoloader] false
[prepend-autoloader] true
[github-domains] [github.com]
[bitbucket-expose-hostname] true
[disable-tls] false
[secure-http] true
[cafile]
[capath]
[github-expose-hostname] true
[gitlab-domains] [gitlab.com]
[store-auths] prompt
[archive-format] tar
[archive-dir] .
[htaccess-protect] true
[use-github-api] true
[lock] true
[home] /var/www/.config/composer
这样使用www-data用户配置网站服务,整个环境就会很清爽,也不会产生权限问题,我们就可以集中精力使用Drupal了。
- 1615 阅读
添加新评论