在ubuntu 16上运行composer时出现权限拒绝错误

时间:2019-06-17 11:59:45

标签: laravel-5 composer-php ubuntu-16.04

我在AWS下安装了ubuntu 16,并尝试安装laravel 5.8应用程序,但是 用

打开服务器
ssh  -i /home/user/pemkeys.pem

命令 运行作曲家

时出现权限拒绝错误
ubuntu@ip-172-31-34-88:/var/www/html/lprods$ clear
ubuntu@ip-172-31-34-88:/var/www/html/lprods$ sudo chmod -R 775 /var/www/html/lprods/
ubuntu@ip-172-31-34-88:/var/www/html/lprods$ composer install 
Cannot create cache directory /home/ubuntu/.composer/cache/repo/https---packagist.org/, or directory is not writable. Proceeding without cache
Cannot create cache directory /home/ubuntu/.composer/cache/files/, or directory is not writable. Proceeding without cache
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update


  [ErrorException]                                                                                                  
  file_put_contents(/var/www/html/lprods/vendor/composer/installed.json): failed to open stream: Permission denied  


install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-plugins] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--ignore-platform-reqs] [--] [<packages>]...

ubuntu@ip-172-31-34-88:/var/www/html/lprods$ whoami
ubuntu
ubuntu@ip-172-31-34-88:/var/www/html/lprods$ lsb_release -d; uname -r; uname -i
Description:    Ubuntu 16.04.6 LTS
4.4.0-1084-aws
x86_64

据我所知,这不是一个好主意

composer install

在根目录下。 我应该采取哪些步骤才能正确安装我的应用程序?

已更新: 1)我的项目目录:

$ cd /var/www/html/lprods
$ ls -ld
drwxrwxrwx 16 root root 4096 Jun 17 12:34 .

(这些输出是什么意思?)

$ ls -la
total 600
drwxrwxrwx  16 root root   4096 Jun 17 12:34 .
drwxr-xr-x   4 root root   4096 Jun 17 11:42 ..
-rwxrwxrwx   1 root root    625 Jun 17 12:03 .env
-rwxrwxrwx   1 root root    521 Jun 17 11:42 .env.example
drwxrwxrwx   8 root root   4096 Jun 17 11:42 .git
-rwxrwxrwx   1 root root    111 Jun 17 11:42 .gitattributes
-rwxrwxrwx   1 root root    135 Jun 17 11:42 .gitignore
-rwxrwxrwx   1 root root    122 Jun 17 11:42 .htaccess
drwxrwxrwx   3 root root   4096 Jun 17 11:42 Modules
-rwxrwxrwx   1 root root   1110 Jun 17 11:42 Release.key
drwxrwxrwx   2 root root   4096 Jun 17 11:42 __SQL
drwxrwxrwx  10 root root   4096 Jun 17 11:42 app
-rwxrwxrwx   1 root root   1646 Jun 17 11:42 artisan
drwxrwxrwx   3 root root   4096 Jun 17 11:42 bootstrap
-rwxrwxrwx   1 root root    430 Jun 17 11:42 code.html
-rwxrwxrwx   1 root root    186 Jun 17 11:42 code.php
-rwxrwxrwx   1 root root   5746 Jun 17 11:42 code.txt
-rwxrwxrwx   1 root root   8244 Jun 17 11:42 commands.txt                                                                                                                                                              
-rwxrwxrwx   1 root root   1953 Jun 17 11:42 composer.json                                                                                                                                                             
-rwxrwxrwx   1 root root 187263 Jun 17 11:42 composer.lock                                                                                                                                                             
drwxrwxrwx   2 root root   4096 Jun 17 11:42 config                                                                                                                                                                    
drwxrwxrwx   5 root root   4096 Jun 17 11:42 database                                                                                                                                                                  
-rwxrwxrwx   1 root root   2860 Jun 17 11:42 env.txt                                                                                                                                                                   
-rwxrwxrwx   1 root root   4236 Jun 17 11:42 good.html                                                                                                                                                                 
-rwxrwxrwx   1 root root     83 Jun 17 11:42 lprods.sublime-project                                                                                                                                                    
-rwxrwxrwx   1 root root   8460 Jun 17 11:42 lprods.sublime-workspace                                                                                                                                                  
-rwxrwxrwx   1 root root    388 Jun 17 11:42 md.txt                                                                                                                                                                    
drwxrwxrwx 834 root root  36864 Jun 17 11:42 node_modules
-rwxrwxrwx   1 root root   1114 Jun 17 11:42 package.json
-rwxrwxrwx   1 root root   1055 Jun 17 11:42 phpunit.xml
drwxrwxrwx  11 root root   4096 Jun 17 11:42 public
-rwxrwxrwx   1 root root   1465 Jun 17 11:42 q.twig
drwxrwxrwx   5 root root   4096 Jun 17 11:42 resources
drwxrwxrwx   2 root root   4096 Jun 17 11:42 routes
-rwxrwxrwx   1 root root    563 Jun 17 11:42 server.php
drwxrwxrwx   6 root root   4096 Jun 17 11:42 storage
drwxrwxrwx   4 root root   4096 Jun 17 11:42 tests
drwxrwxrwx  46 root root   4096 Jun 17 11:58 vendor
-rwxrwxrwx   1 root root   1549 Jun 17 11:42 webpack.mix.js
-rwxrwxrwx   1 root root 204808 Jun 17 11:42 yarn.lock

2)我删除了dirs:

rm -R vendor
rm -R /home/ubuntu/.composer

然后在我的应用中运行

composer install

我的项目已成功安装。 您能否给出一些解释,为什么呢?

谢谢!

1 个答案:

答案 0 :(得分:0)

如果出现拒绝权限,则可以使用sudo composer update。或者您应该像composer global require laravel/installer这样全局地添加composer,并且可以从任何地方轻松访问composer,还可以尝试更改sudo chown -R user:user project

等项目的权限