# Dev environment not recognized in IpRestrictMiddleware.php

**URL:** <https://forum.mautic.org/t/dev-environment-not-recognized-in-iprestrictmiddleware-php/34976>\
**Category:** Documentation\
**Created:** [February 8, 2025, 5:55am UTC](https://forum.mautic.org/t/dev-environment-not-recognized-in-iprestrictmiddleware-php/34976 "2025-02-08T05:55:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dominic.mayers](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/dominic.mayers/32/13549_2.png) [@dominic.mayers](https://forum.mautic.org/u/dominic.mayers)\
**Post date:** [February 8, 2025, 5:55am UTC](https://forum.mautic.org/t/dev-environment-not-recognized-in-iprestrictmiddleware-php/34976/1 "2025-02-08T05:55:51Z")

</div>

I installed mautic in Ubuntu with nginx.  
I significantly adapted [the nginx configuration of proffalken](https://gist.github.com/proffalken/ebfa9debc4eef929b0163d11a80af349).  
I cloned the github repository and executed `composer install`  
The integration with a database using the web installer works fine.  
I got the success page.

I want to switch to the development mode before I integrate a mail server.  
I added a file .env.local in the mautic root folder with

```auto
APP_ENV=dev
APP_DEBUG=1

```

However, this apparently brakes the application.  
After that, the page /installer responded:  
`You are not allowed to access this file.`

My work around was to replace in `app/middlewares/Dev/IpRestrictMiddleware.php`:

```auto
if (in_array($request->getClientIp(), $this->allowedIps) || false !== getenv('DDEV_TLD') )`

```

with

```auto
if (in_array($request->getClientIp(), $this->allowedIps) || false !== getenv('DDEV_TLD') || $_SERVER['APP_ENV'] === 'dev')

```

But, there might be something else that would fix this problem  
in a better way. Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![dominic.mayers](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/dominic.mayers/32/13549_2.png) [@dominic.mayers](https://forum.mautic.org/u/dominic.mayers)\
**Post date:** [February 27, 2025, 5:53pm UTC](https://forum.mautic.org/t/dev-environment-not-recognized-in-iprestrictmiddleware-php/34976/2 "2025-02-27T17:53:56Z")

</div>

I now understand a bit better the situation. The code in `IpRestrictMiddleware.php` is executed when, in the .env file, APP\_DEV=dev. It is not executed when APP\_DEV=prod. The code requires that you are in a DDEV environment (not just any dev environment) or that the client Ip is in an allowed list of Ips This seems a reasonable requirement. Moreover, the ips `127.0.0.1`, `fe80::1` and `::1` are harcoded in the list of allowed Ips. So, in most cases, when you test locally it works. In my case, the client Ip was an Ip of the local network: 192.168.1.x. Fortunately, the code appends to the list of allowed Ips, the value of the environment variable `MAUTIC_CUSTOM_DEV_HOSTS`. I only had to add `env[MAUTIC_CUSTOM_DEV_HOSTS] = '["192.168.1.152"]'` in my php-fpm configuration file and it worked. If you are not using php-fpm, it is sufficient to export this environment variable in the usual way in your machine, for example, in your `.profile` file in linux. By the way, I tested this in the branch 5.2. There might be other issues in 6.x or later versions.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/1X/43c63600fe51440378769136903f1fa2a9a34102.png) [@system](https://forum.mautic.org/u/system)\
**Post date:** [March 1, 2025, 5:54am UTC](https://forum.mautic.org/t/dev-environment-not-recognized-in-iprestrictmiddleware-php/34976/3 "2025-03-01T05:54:31Z")

</div>

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.
