Running composer installation in a Symfony 3.2 project on a machine that shares 2 environments

148 Views Asked by At

I have in the same server in 2 differents directories, like this:

  • /var/www/pre.myproject.com/
  • /var/www/myproject.com/

pre.myproject.com is a full copy from production myproject.com

When I am trying to run the command composer install inside the folder /var/www/pre.myproject.com/ with this:

 composer install --no-dev --optimize-autoloader

I see the following errors:

Cannot create cache directory /var/www/myproject.com/.composer/cache/repo/https---packagist.org/, or directory is not writable. Proceeding without cache
Cannot create cache directory /var/www/myproject.com/.composer/cache/files/, or directory is not writable.Proceeding without cache

Why is it trying to make changes in myproject.com if I am currently at pre.myproject.com?

What files should I change in my folder pre.myproject.com to enable a new environment in Symfony3? And so the composer can install correctly for this environment and within this directory?

2

There are 2 best solutions below

4
Vincent PHILIPPE On

What you trying to do is having a new installation of an existing Symfony project with an existing composer.json file containing all your dependencies.

What you should do is not composer install but composer update as the composer.json file should already exist, it'll just read it and download the dependencies packages

composer update :

The update command reads the composer.json file from the current directory, processes it, and updates, removes or installs all the
dependencies.

This is what I am using on my production server when I import a new feature from my development branch.


Edit

You should add --no-cache option to bypass the cache.

0
hakre On

This question was not answered so far:

Why is it trying to make changes in myproject.com [...]?

The changes are with the path from the error message:

/var/www/myproject.com/.composer/cache/repo/https---packagist.org/

Composer has a parameter for this path and that is the composer cache directory. In your case it is configured to point to the following base path:

/var/www/myproject.com/.composer/cache

It is often based on the COMPOSER_HOME parameter, but that is just a detail (existing Q&A covers this).

So use the correct composer configuration for each environment. As with each different environment things can become more demanding, use a build manager to ease the work. It can help you to control all build parameters of the in-tree build.

For your project it seems an in-tree build suffices. In case not, it is of benefit to make use of a deployment manager as well that takes care to deploy the application out of the project tree.