npm install 错误:EACCES:权限被拒绝,访问'/var/www/html'。

7
我正在尝试在生产环境下运行 npm install,但它给了我一个错误。
npm ERR! path /var/www/html
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/var/www/html'
npm ERR!  { [Error: EACCES: permission denied, access '/var/www/html']
npm ERR!   stack: 'Error: EACCES: permission denied, access \'/var/www/html\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/var/www/html' }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

/var/www/html 是我的服务器网站目录。

我尝试过这个方法,但仍然出现错误。

有什么想法吗?


2
你检查了 '/var/www/html' 文件夹的权限吗? - Veve
1
sudo chown -R $USER /var/www/html . refer : https://dev59.com/rmQo5IYBdhLWcg3wUd-L - IftekharDani
刚刚执行了 sudo chown -R $USER /var/www/html 命令,它起作用了,但也导致我的网站崩溃,出现以下错误:prod.ERROR: file_put_contents(/var/www/html/storage/framework/views/fc62ea85cb79efbc10ea806eb27bde7ad95abc56.php): failed to open stream: Permission denied {"exception":"[object] (ErrorException(code: 0): file_put_contents(/var/www/html/storage/framework/views/fc62ea85cb79efbc10ea806eb27bde7ad95abc56.php): failed to open stream: Permission denied at /var/www/html/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:122) - cawecoy
3个回答

12

感谢robrogers3和@IftekharDani,我已经得到了解决方案。

完整的解决方案:

  1. 将安装用户(npm)授予对/var/www/html目录的权限:

    sudo chown -R $USER /var/www/html

  2. 向web服务器授予/var/www/html/storage/framework目录的权限:

    sudo chown -R www-data:www-data /var/www/html/storage/framework


1
https://laracasts.com/discuss/channels/vue/npm-install-error-eacces-permission-denied-access-varwwwhtml - Gufran Hasan

0

我在Win 7上遇到了同样的问题。正如之前提到的,这与文件权限有关。在我的Homestead.yml中,我有以下内容:

folders:
    - map: ...
      to: ...
      options: 
          owner: "www-data"
          group: "www-data"
          mount_options: ["dmode=775,fmode=664"]

请注意 "options" 键。默认情况下,它不会显示,但我曾试图解决符号链接的另一个问题...一旦我将其删除,一切就正常了。此外,我在使用 npm install 命令时使用--no-bin-links

-10

你可以重试:

sudo npm install

3
过去“sudo npm install”命令曾导致系统出现故障。你应该至少澄清这个命令的不同之处。 - Botje

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接