# Deployment messes up the dev environment because everything happens in the same folder

**URL:** <https://forum.serverless.com/t/deployment-messes-up-the-dev-environment-because-everything-happens-in-the-same-folder/3293>\
**Category:** Serverless Framework\
**Created:** [December 10, 2017, 5:44pm UTC](https://forum.serverless.com/t/deployment-messes-up-the-dev-environment-because-everything-happens-in-the-same-folder/3293 "2017-12-10T17:44:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mnapoli](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/mnapoli/32/6575_2.png) [@mnapoli](https://forum.serverless.com/u/mnapoli)\
**Post date:** [December 10, 2017, 5:44pm UTC](https://forum.serverless.com/t/deployment-messes-up-the-dev-environment-because-everything-happens-in-the-same-folder/3293/1 "2017-12-10T17:44:55Z")

</div>

Hi,

I am a bit confused by the fact that deploying a lambda means building (or packaging) it in the project’s directory.

For example, in production I need to have a file in the lambda. I wrote a plugin that generates the file when the lambda is packaged (thanks to a hook).

But now every time I deploy the file is generated in the project’s directory!

That doesn’t sound so bad, but I’m working on whole PHP support and I’m writing caches for production, and after each deploy the app is basically broken in the dev environment because caches are made for the prod environment.

**Is there a way to make serverless prepare the application for packaging in another folder?** (and I’m not talking about generating the zip file in another folder!)

---

<div class="post-metadata">

**Author:** ![bill](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/bill/32/1072_2.png) [@bill](https://forum.serverless.com/u/bill)\
**Post date:** [December 11, 2017, 11:01am UTC](https://forum.serverless.com/t/deployment-messes-up-the-dev-environment-because-everything-happens-in-the-same-folder/3293/2 "2017-12-11T11:01:47Z")

</div>

suppose you have two environment files

```
$ cat production.yml

exclude:
    - abc/**
    - .*.yml
    - .*.md

$ cat dev.yml

exclude:
    - .*.md

```

So in `serverless.yml`, you can easily manage which files need be excluded when packaging for different environments.

```
custom: ${file(${opt:stage, self:provider.stage}.yml)}

package:
  exclude: ${self:custom.exclude}
```

---

<div class="post-metadata">

**Author:** ![mnapoli](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/mnapoli/32/6575_2.png) [@mnapoli](https://forum.serverless.com/u/mnapoli)\
**Post date:** [December 11, 2017, 11:17am UTC](https://forum.serverless.com/t/deployment-messes-up-the-dev-environment-because-everything-happens-in-the-same-folder/3293/3 "2017-12-11T11:17:03Z")

</div>

Thanks! However that is not related to what I want to do.

I am deploying a PHP lambda. So in the deploy step, I download the PHP binary and put it in the project directory (thanks to a plugin). `serverless deploy` then uploads that and it works.

The problem is I have this PHP binary in my project now…

And I have the same problem with many files : e.g. I generate cache files, optimized autoloader, etc. And all those files are left in my project (i.e. on my PC) after `serverless deploy`.

So I would like to prepare the zip file **in a separate directory** (even a temp directory is fine).

Can I do that?

---

<div class="post-metadata">

**Author:** ![bill](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/bill/32/1072_2.png) [@bill](https://forum.serverless.com/u/bill)\
**Post date:** [December 11, 2017, 11:23am UTC](https://forum.serverless.com/t/deployment-messes-up-the-dev-environment-because-everything-happens-in-the-same-folder/3293/4 "2017-12-11T11:23:03Z")

</div>

Only for package? So option `--package` is what you are looking for?

```
$ sls package --help
Plugin: Package
package ....................... Packages a Serverless service
    --stage / -s ....................... Stage of the service
    --region / -r ...................... Region of the service
    --package / -p ..................... Output path for the package
```

---

<div class="post-metadata">

**Author:** ![mnapoli](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/mnapoli/32/6575_2.png) [@mnapoli](https://forum.serverless.com/u/mnapoli)\
**Post date:** [December 11, 2017, 3:11pm UTC](https://forum.serverless.com/t/deployment-messes-up-the-dev-environment-because-everything-happens-in-the-same-folder/3293/5 "2017-12-11T15:11:13Z")

</div>

But this will just put the zip in the “output path” right? (it will still zip the content of the folder’s directory)

---

<div class="post-metadata">

**Author:** ![bill](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/bill/32/1072_2.png) [@bill](https://forum.serverless.com/u/bill)\
**Post date:** [December 11, 2017, 9:03pm UTC](https://forum.serverless.com/t/deployment-messes-up-the-dev-environment-because-everything-happens-in-the-same-folder/3293/6 "2017-12-11T21:03:45Z")

</div>

if you add the folders in exclude list, it will not package into zip

---

<div class="post-metadata">

**Author:** ![mnapoli](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/mnapoli/32/6575_2.png) [@mnapoli](https://forum.serverless.com/u/mnapoli)\
**Post date:** [December 11, 2017, 10:35pm UTC](https://forum.serverless.com/t/deployment-messes-up-the-dev-environment-because-everything-happens-in-the-same-folder/3293/7 "2017-12-11T22:35:01Z")

</div>

I do not want to exclude it, the PHP binary should be deployed into the lambda.

Here is another way to explain it:

Expected files:

```auto
# Locally
handler.js
test.php
# In the lambda
handler.js
test.php
bin/php

```

Actual files:

```auto
# Locally
handler.js
test.php
bin/php
# In the lambda
handler.js
test.php
bin/php

```

`bin/php` is created by my serverless plugin which generates it when running `serverless deploy` or `serverless package`. I want this file on the lambda, **but not in my project**.

I would like the lambda to be generated in a temporary directory (where I could add `bin/php` without affecting my local files).

---

<div class="post-metadata">

**Author:** ![bill](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/bill/32/1072_2.png) [@bill](https://forum.serverless.com/u/bill)\
**Post date:** [December 11, 2017, 10:38pm UTC](https://forum.serverless.com/t/deployment-messes-up-the-dev-environment-because-everything-happens-in-the-same-folder/3293/8 "2017-12-11T22:38:39Z")

</div>

I still don’t get your points.

If you don’t want `bin/php` to be in project (your meaning is not controlled by source control, right?), you can exclude it via .gitignore

```
$ cat .gitignore
bin/php
```

---

<div class="post-metadata">

**Author:** ![mnapoli](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/mnapoli/32/6575_2.png) [@mnapoli](https://forum.serverless.com/u/mnapoli)\
**Post date:** [December 12, 2017, 7:32am UTC](https://forum.serverless.com/t/deployment-messes-up-the-dev-environment-because-everything-happens-in-the-same-folder/3293/9 "2017-12-12T07:32:38Z")

</div>

We are getting closer to my point: I don’t want it in my project at all 🙂

Here is another problem: I need to install Composer dependencies (it’s npm for PHP basically) optimized for production in the lambda. I want them optimized for development on my machine.

So `serverless deploy` optimizes them for production (thanks to my plugin) but then my dev environment is all messed up.
