65

I've tried other posts I found online but none seemed to work correctly. I'm working with this. And I make my way to the root of it, which is /var/www/. So then I do composer install and I have a composer.json file in there. I get

[RuntimeException]                               
vendor does not exist and could not be created.

Here's the file

{
    "name": "panique/php-login",
    "type": "project",
    "description": "A PHP login system embedded in a simple MVC framework",
    "keywords": ["login", "auth", "user", "authentification", "mvc"],
    "homepage": "https://github.com/panique/php-login",
    "license": "MIT",
    "authors": [
        {
            "name": "Panique",
            "homepage": "http://careers.stackoverflow.com/panique",
            "role": "Developer"
        }
    ],
    "support": {
        "issues": "https://github.com/panique/php-login/issues",
        "source": "https://github.com/panique/php-login"
    },
    "require":{
        "php": ">=5.3.7",
        "ircmaxell/password-compat": "1.0.*",
        "phpmailer/phpmailer": "5.2.*",
        "gregwar/captcha": "dev-master",
        "facebook/php-sdk": "@stable",
        "raveren/kint": "dev-1.0.0-wip"
    }
}

I'm not really sure where to go from here....

MrUpsidown
  • 21,592
  • 15
  • 77
  • 131
user3413366
  • 653
  • 1
  • 5
  • 7

8 Answers8

133

Googlers, do not use composer with sudo:

Add your user in the www-data group (this action require you to logout and login again)

sudo usermod -a -G www-data `whoami`

Give the right permissions to /var/www

sudo chown root:root /var/www
sudo chmod 755 /var/www/

Give these permissions to your project

sudo chown -R www-data:www-data /var/www/<project>
sudo chmod -R 774 /var/www/<project>
Etienne Gautier
  • 2,901
  • 4
  • 26
  • 35
  • 3
    Reasons this question is correct: a) You're allowing third party scripts to execute as ROOT... big security risk! b) you're ssh key will no longer be available (cant pull from github/bitbucket) c) you will be forever chowning things back to `www-data` or `username` (like `/home/user/.composer` file) – Edward Jun 28 '17 at 16:15
  • 1
    When I add these permissions from host machine, I get this error: `OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "chdir to cwd (\"/var/www/project\") set in config.json failed: permission denied": unknown` Any idea why I am getting this? – Ariful Haque Mar 03 '20 at 02:30
  • Run `sudo chown root:root /var/www`, I get `chown: cannot access '/var/www': No such file or directory` – Gloria Chen Sep 22 '21 at 06:45
36

@Etienne Gautier's solution will certainly work.

Another solution is just to change the permissions of the user/group of /vendor.

e.g.

sudo chmod -R 775  /ROOT_OF_YOUR_APP/vendor/
sudo chown -R $USER:$USER /ROOT_OF_YOUR_APP/vendor/
Nelson Sammy
  • 404
  • 2
  • 7
  • 16
Hiroki
  • 3,893
  • 13
  • 51
  • 90
  • 2
    Verry usefull answer but before doing this first creat a vendor folder in your project folder – Saddan Nov 12 '20 at 10:06
22

if you are a linux user, run the following command

sudo chown -R user projectFolder/

then run composer install. user is the username of your machine. If you are not sure just run

whoami

from the terminal

Nelson Sammy
  • 404
  • 2
  • 7
  • 16
7

I was able to solve this type of issue by removing the vendor folder and then re-installing using composer update. Hope this helps someone like me.

Clark Nelson
  • 171
  • 1
  • 6
2

I also had this issue with updating my package. The reason why it did not work for me is that this folder 'to be created' already existed and had to be deleted before this composer update could be done.

Klyner
  • 3,983
  • 4
  • 26
  • 50
1

Manually create vendor folder inside of your laravel app sudo mkdir vendor and give 777 permission to it sudo chmod 777 vendor/ and then go back to your app location and run composer update.

Then, again bootstrap/cache permission may occur give 777 permission recursively to cache folder sudo chmod -R 777 cache/ then go back to your app location and run composer update.

Make sure you have setup your .env file in your laravel app.

Then you are good to go:)

0

Same thing happened to me, seems like a permission issue, you got two choices:

  1. Give you user permissions like mentioned in Etienne Gautier's answer above or
  2. Log in with your root user
Armin
  • 2,021
  • 2
  • 19
  • 17
-4

This happens because we do not have administrator permissions, we just have to put the word sudo, it would look like this: sudo composer install