Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

[Windows/WSL2] Permission issue on nitro create / nitro composer install #280

Closed
umkasanki opened this issue Mar 6, 2021 · 15 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@umkasanki
Copy link

Description

I get an error when trying to execute nitro create or nitro composer install.

Steps to reproduce

  1. Install Nitro
  2. Try to create 1st project

Additional info

  • Nitro version: 2.0.3
  • Docker version: 3.2.1
  • Windows 10 / WSL2
mishkin@DESKTOP-ELHJ3EU:~/dev$ nitro create tutorial
Downloading https://github.com/craftcms/craft/archive/HEAD.zip ...
  … setting up project ✓
New site downloaded 🤓
Enter the hostname [tutorial.nitro]:
  ✓ setting hostname to tutorial.nitro
  ✓ adding site ~/dev/tutorial
Enter the webroot for the site [web]:
  ✓ using webroot web
Choose a PHP version:
  1. 8.0
  2. 7.4
  3. 7.3
  4. 7.2
  5. 7.1
  6. 7.0
Enter your selection: 1
  ✓ setting PHP version 8.0
Add a database for the site [Y/n] y
Enter the new database name: tutorial
  … creating database tutorial ✓
Database added 💪
Should we update the env file? [Y/n] y
.env updated!
Loading composer repositories with package information
Updating dependencies
Lock file operations: 87 installs, 0 updates, 0 removals
  - Locking cebe/markdown (1.2.1)
  - Locking composer/ca-bundle (1.2.9)
  - Locking composer/composer (2.0.10)
  - Locking composer/semver (3.2.4)
  - Locking composer/spdx-licenses (1.5.5)
  - Locking composer/xdebug-handler (1.4.5)
  - Locking craftcms/cms (3.6.9)
  - Locking craftcms/oauth2-craftid (1.0.0.1)
  - Locking craftcms/plugin-installer (1.5.7)
  - Locking craftcms/server-check (1.2.0)
  - Locking creocoder/yii2-nested-sets (0.9.0)
  - Locking defuse/php-encryption (v2.2.1)
  - Locking dnoegel/php-xdg-base-dir (v0.1.1)
  - Locking doctrine/lexer (1.2.1)
  - Locking egulias/email-validator (2.1.25)
  - Locking elvanto/litemoji (3.0.1)
  - Locking enshrined/svg-sanitize (0.14.0)
  - Locking ezyang/htmlpurifier (v4.13.0)
  - Locking guzzlehttp/guzzle (7.2.0)
  - Locking guzzlehttp/promises (1.4.0)
  - Locking guzzlehttp/psr7 (1.7.0)
  - Locking justinrainbow/json-schema (5.2.10)
  - Locking laminas/laminas-escaper (2.7.0)
  - Locking laminas/laminas-feed (2.13.1)
  - Locking laminas/laminas-stdlib (3.3.1)
  - Locking laminas/laminas-zendframework-bridge (1.2.0)
  - Locking league/flysystem (1.1.3)
  - Locking league/mime-type-detection (1.7.0)
  - Locking league/oauth2-client (2.6.0)
  - Locking mikehaertl/php-shellcommand (1.6.3)
  - Locking nikic/php-parser (v4.10.4)
  - Locking opis/closure (3.6.1)
  - Locking paragonie/random_compat (v9.99.100)
  - Locking phpdocumentor/reflection-common (2.2.0)
  - Locking phpdocumentor/reflection-docblock (5.2.2)
  - Locking phpdocumentor/type-resolver (1.4.0)
  - Locking phpoption/phpoption (1.7.5)
  - Locking pixelandtonic/imagine (1.2.4.1)
  - Locking psr/container (1.1.1)
  - Locking psr/http-client (1.0.1)
  - Locking psr/http-message (1.0.1)
  - Locking psr/log (1.1.3)
  - Locking psy/psysh (v0.10.6)
  - Locking ralouphie/getallheaders (3.0.3)
  - Locking react/promise (v2.8.0)
  - Locking seld/cli-prompt (1.0.4)
  - Locking seld/jsonlint (1.8.3)
  - Locking seld/phar-utils (1.1.1)
  - Locking swiftmailer/swiftmailer (v6.2.6)
  - Locking symfony/console (v5.2.4)
  - Locking symfony/deprecation-contracts (v2.2.0)
  - Locking symfony/filesystem (v5.2.4)
  - Locking symfony/finder (v5.2.4)
  - Locking symfony/polyfill-ctype (v1.22.1)
  - Locking symfony/polyfill-iconv (v1.22.1)
  - Locking symfony/polyfill-intl-grapheme (v1.22.1)
  - Locking symfony/polyfill-intl-idn (v1.22.1)
  - Locking symfony/polyfill-intl-normalizer (v1.22.1)
  - Locking symfony/polyfill-mbstring (v1.22.1)
  - Locking symfony/polyfill-php72 (v1.22.1)
  - Locking symfony/polyfill-php73 (v1.22.1)
  - Locking symfony/polyfill-php80 (v1.22.1)
  - Locking symfony/process (v5.2.4)
  - Locking symfony/service-contracts (v2.2.0)
  - Locking symfony/string (v5.2.4)
  - Locking symfony/var-dumper (v5.2.4)
  - Locking symfony/yaml (v5.2.4)
  - Locking true/punycode (v2.1.1)
  - Locking twig/twig (v2.14.3)
  - Locking vlucas/phpdotenv (v3.6.8)
  - Locking voku/anti-xss (4.1.31)
  - Locking voku/arrayy (7.8.7)
  - Locking voku/email-check (3.1.0)
  - Locking voku/portable-ascii (1.5.6)
  - Locking voku/portable-utf8 (5.4.51)
  - Locking voku/stop-words (2.0.1)
  - Locking voku/stringy (6.4.0)
  - Locking voku/urlify (5.0.5)
  - Locking webmozart/assert (1.9.1)
  - Locking webonyx/graphql-php (v14.4.1)
  - Locking yii2tech/ar-softdelete (1.0.4)
  - Locking yiisoft/yii2 (2.0.41.1)
  - Locking yiisoft/yii2-composer (2.0.10)
  - Locking yiisoft/yii2-debug (2.1.16)
  - Locking yiisoft/yii2-queue (2.3.1)
  - Locking yiisoft/yii2-shell (2.0.4)
  - Locking yiisoft/yii2-swiftmailer (2.1.2)


  [ErrorException]
  file_put_contents(./composer.lock): failed to open stream: Permission denied


create-project [-s|--stability STABILITY] [--prefer-source] [--prefer-dist] [--repository REPOSITORY] [--repository-url REPOSITORY-URL] [--add-repository] [--dev] [--no-dev] [--no-custom-installers] [--no-scripts] [--no-progress] [--no-secure-http] [--keep-vcs] [--remove-vcs] [--no-install] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--ask] [--] [<package>] [<directory>] [<version>]

composer create-project completed 🤘
Checking network…
  ✓ network ready
Checking proxy…
  ✓ proxy ready
Checking databases…
  … checking mysql-8.0-3306.database.nitro ✓
Checking services…
  … checking dynamodb service ✓
  … checking mailhog service ✓
  … checking redis service ✓
Checking sites…
  … checking tutorial.nitro ✓
Checking proxy…
  … updating proxy ✓
Updating hosts file (you might be prompted for your password)
Adding sites to hosts file…
  … modifying hosts file ✓
mishkin@DESKTOP-ELHJ3EU:~/dev$
mishkin@DESKTOP-ELHJ3EU:~/dev/tutorial$ nitro composer install
  … checking /home/mishkin/dev/tutorial/composer.json ✓
No lock file found. Updating dependencies instead of installing from lock file. Use composer update over composer install if you do not have a lock file.
Loading composer repositories with package information
Updating dependencies
Lock file operations: 87 installs, 0 updates, 0 removals
  - Locking cebe/markdown (1.2.1)
  - Locking composer/ca-bundle (1.2.9)
  - Locking composer/composer (2.0.10)
  - Locking composer/semver (3.2.4)
  - Locking composer/spdx-licenses (1.5.5)
  - Locking composer/xdebug-handler (1.4.5)
  - Locking craftcms/cms (3.6.9)
  - Locking craftcms/oauth2-craftid (1.0.0.1)
  - Locking craftcms/plugin-installer (1.5.7)
  - Locking craftcms/server-check (1.2.0)
  - Locking creocoder/yii2-nested-sets (0.9.0)
  - Locking defuse/php-encryption (v2.2.1)
  - Locking dnoegel/php-xdg-base-dir (v0.1.1)
  - Locking doctrine/lexer (1.2.1)
  - Locking egulias/email-validator (2.1.25)
  - Locking elvanto/litemoji (3.0.1)
  - Locking enshrined/svg-sanitize (0.14.0)
  - Locking ezyang/htmlpurifier (v4.13.0)
  - Locking guzzlehttp/guzzle (7.2.0)
  - Locking guzzlehttp/promises (1.4.0)
  - Locking guzzlehttp/psr7 (1.7.0)
  - Locking justinrainbow/json-schema (5.2.10)
  - Locking laminas/laminas-escaper (2.6.1)
  - Locking laminas/laminas-feed (2.12.3)
  - Locking laminas/laminas-stdlib (3.2.1)
  - Locking laminas/laminas-zendframework-bridge (1.1.1)
  - Locking league/flysystem (1.1.3)
  - Locking league/mime-type-detection (1.7.0)
  - Locking league/oauth2-client (2.6.0)
  - Locking mikehaertl/php-shellcommand (1.6.3)
  - Locking nikic/php-parser (v4.10.4)
  - Locking opis/closure (3.6.1)
  - Locking paragonie/random_compat (v9.99.100)
  - Locking phpdocumentor/reflection-common (2.2.0)
  - Locking phpdocumentor/reflection-docblock (5.2.2)
  - Locking phpdocumentor/type-resolver (1.4.0)
  - Locking phpoption/phpoption (1.7.5)
  - Locking pixelandtonic/imagine (1.2.4.1)
  - Locking psr/container (1.1.1)
  - Locking psr/http-client (1.0.1)
  - Locking psr/http-message (1.0.1)
  - Locking psr/log (1.1.3)
  - Locking psy/psysh (v0.10.6)
  - Locking ralouphie/getallheaders (3.0.3)
  - Locking react/promise (v2.8.0)
  - Locking seld/cli-prompt (1.0.4)
  - Locking seld/jsonlint (1.8.3)
  - Locking seld/phar-utils (1.1.1)
  - Locking swiftmailer/swiftmailer (v6.2.6)
  - Locking symfony/console (v5.2.4)
  - Locking symfony/deprecation-contracts (v2.2.0)
  - Locking symfony/filesystem (v5.2.4)
  - Locking symfony/finder (v5.2.4)
  - Locking symfony/polyfill-ctype (v1.22.1)
  - Locking symfony/polyfill-iconv (v1.22.1)
  - Locking symfony/polyfill-intl-grapheme (v1.22.1)
  - Locking symfony/polyfill-intl-idn (v1.22.1)
  - Locking symfony/polyfill-intl-normalizer (v1.22.1)
  - Locking symfony/polyfill-mbstring (v1.22.1)
  - Locking symfony/polyfill-php72 (v1.22.1)
  - Locking symfony/polyfill-php73 (v1.22.1)
  - Locking symfony/polyfill-php80 (v1.22.1)
  - Locking symfony/process (v5.2.4)
  - Locking symfony/service-contracts (v2.2.0)
  - Locking symfony/string (v5.2.4)
  - Locking symfony/var-dumper (v5.2.4)
  - Locking symfony/yaml (v5.2.4)
  - Locking true/punycode (v2.1.1)
  - Locking twig/twig (v2.14.3)
  - Locking vlucas/phpdotenv (v3.6.8)
  - Locking voku/anti-xss (4.1.31)
  - Locking voku/arrayy (7.8.7)
  - Locking voku/email-check (3.1.0)
  - Locking voku/portable-ascii (1.5.6)
  - Locking voku/portable-utf8 (5.4.51)
  - Locking voku/stop-words (2.0.1)
  - Locking voku/stringy (6.4.0)
  - Locking voku/urlify (5.0.5)
  - Locking webmozart/assert (1.9.1)
  - Locking webonyx/graphql-php (v14.4.1)
  - Locking yii2tech/ar-softdelete (1.0.4)
  - Locking yiisoft/yii2 (2.0.41.1)
  - Locking yiisoft/yii2-composer (2.0.10)
  - Locking yiisoft/yii2-debug (2.1.16)
  - Locking yiisoft/yii2-queue (2.3.1)
  - Locking yiisoft/yii2-shell (2.0.4)
  - Locking yiisoft/yii2-swiftmailer (2.1.2)


  [ErrorException]
  file_put_contents(./composer.lock): failed to open stream: Permission denied


install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-suggest] [--no-dev] [--no-autoloader] [--no-scripts] [--no-progress] [--no-install] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--] [<packages>]...

composer install completed 🤘
mishkin@DESKTOP-ELHJ3EU:~/dev/tutorial$
@umkasanki umkasanki added the bug Something isn't working label Mar 6, 2021
@umkasanki umkasanki changed the title [Windows/WSL2] Permission issue on nitro create / nitro composer install [ErrorException] file_put_contents(./composer.lock): failed to open stream: Permission denied [Windows/WSL2] Permission issue on nitro create / nitro composer install Mar 6, 2021
@jamesmacwhite
Copy link
Contributor

jamesmacwhite commented Mar 7, 2021

For Windows, you will encounter permission issues because of the way Docker and WSL integration is. It's actually a WSL/Docker level problem not specific to Nitro as you'll encounter the same issues with php-fpm containers with Docker generally. The quickest way to resolve is to do chmod 777 on certain paths:

https://craftcms.com/docs/nitro/2.x/windows.html#permissions-and-manual-setup-steps

In your case the composer process within the container cannot write to the composer.lock file., Run chmod 777 ./composer.lock from the project path within WSL to allow this and it should be fine.

@umkasanki
Copy link
Author

Thanks.
Yes, I understand.
There is no question when you deploy an existing project in Nitro. But when creating a new project, when the composer.lock file does not exist yet, this is not very convenient. Because after running the 'nitro create' command, I should remember to add write permissions before proceeding to next steps...

@jasonmccallister
Copy link
Contributor

@umkasanki can you provide the output of ls -la in your directory where you are running create and composer commands?

@jasonmccallister jasonmccallister self-assigned this Mar 8, 2021
@umkasanki
Copy link
Author

@jasonmccallister
изображение

@jasonmccallister
Copy link
Contributor

How was the test-project directory created?

@umkasanki
Copy link
Author

umkasanki commented Mar 8, 2021

@jasonmccallister
test-project and test-project2 created by nitro create project-name command

@jasonmccallister
Copy link
Contributor

Thank you, I will look into the best way to resolve this going forward.

For now, you can run sudo chown -R mishkin:mishkin test-project to set the permissions based on your user.

@umkasanki
Copy link
Author

Thanks

@emarthinsen
Copy link

emarthinsen commented Mar 9, 2021

FWIW, I'm running into the same issue using Craft Nitro on Ubuntu. The group and owner for all created files is emarthinsen:emarthinsen, so my user account. I get the same "file_put_contents(./composer.lock): failed to open stream: Permission denied" error if I run nitro composer install. The same error popped up when I initially ran nitro create test-site.

For me, having Nitro make the permissions "just work" would be an amazing win.

@theduxinlux
Copy link

Additional workaround comment.
using Windows 10 with WSL Ubuntu 20.04
I set up my working directory in the Linux directory system as per the recommendation.
I ran nitro create tutorial
This gets stuck at the composer.lock as per this issue.
What I then did was
cd tutorial
touch compose.lock # as it doesn't exist
mkdir vendor # as it also doesn't exist yet
cd .. # to go back up to do a lazy chmod rather than the specific one detailed in the documentation
chmod -R 777 tutorial # which sets everything to open access
cd tutorial
nitro compose update # this now populates the content needed in vendor
nitro apply # might not be necessary
nitro craft setup # did the setup

then updated the hosts file using administrator windows cmd to copy the nitro hosts content

nitro apply # for good measure

I could now access the Craft UI finally as intended.
Hope that helps people in the interim while this gets ironed out.

@johnwbaxter
Copy link

I have this also and I'm on linux desktop, not WSL.

@aloco
Copy link

aloco commented Mar 24, 2021

Hi we also have this issue with linux desktop,

talked to a colleague who worked on https://github.com/allaboutapps/go-starter where they had a similar issue. They worked around the problem by setting a specific user https://github.com/allaboutapps/go-starter/blob/master/Dockerfile#L134

Not sure if this is the same root cause of the problem, but this article might summarize the issues around it https://jtreminio.com/blog/running-docker-containers-as-current-host-user/

@jamesmacwhite
Copy link
Contributor

jamesmacwhite commented Mar 24, 2021

Yes, it is due to the UID/GUID being 1000 which is www-data, but the host will be a username like jameswhite:jameswhite. In most cases it works for reading, but writing is a problem.

Running chmod 777 basically makes any user be able to read/write any file, but the problem is when directories or files like composer.lock don't exist initially from a project setup. Doing chmod 777 on ephemeral locations i.e. storage is fine, but a whole project is bad idea.

I think the only way is for the UID and GID to be the same as the host which I believe @jasonmccallister was looking into.

@jasonmccallister
Copy link
Contributor

@aloco we have pushed a change that resolves this for linux users, we will be verifying today to make sure everything is good to go so it can go out with the next release.

What @jamesmacwhite mentioned is part of the resolution, we grab the user information dynamically on Linux and tell the container to connect/execute as that host user https://github.com/craftcms/nitro/blob/develop/command/ssh/ssh_linux.go#L186.

It does create some strange behavior, since things like whoami will return an error, but it seems to be working as expected. Looking forward to getting this release out!

@jasonmccallister
Copy link
Contributor

Just released 2.0.7 with better support on Linux and WSL machines.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants