Hello from the other side! I’ve been developing web applications for a couple of years using Laminas MVC (formerly known as Zend Framework 3) and one thing that frustrate me the most in my past experiences is, when my development and staging sites were accidentally index by one of the search engines such as Google, Bing, Yahoo, DuckDuckGo, Baidu and Yandex. A common mistake that I need to think about and begin to deal with.
Now, I’d like to share my solution through this tutorial on how you can properly configure an automatic search engine protection in Laminas MVC. This tutorial is also inspired by Symfony 4.3: Automatic Search Engine Protection.
The good thing I like about Laminas MVC is its approach of configuration over convention, it means that I have the absolute control and knowledge on what I want to execute over my application. So before it will work, we have to do some configurations first and I assume that you have the basic knowledge in PHP and Laminas MVC (formerly known as Zend Framework 3).
Now lets get started. First we need to add a few handful of array data to our local configuration.
config/autoload/local.php
<?php return [ ... 'seo_manager' => [ 'disallow_search_engine_index' => false, 'disallow_google_tag_manager' => false, ], ];
config/autoload/development.local.php
<?php return [ ... 'seo_manager' => [ 'disallow_search_engine_index' => true, 'disallow_google_tag_manager' => true, ], ];
And this will be our default value when we run our application in development or staging. The option name is negative, so the “true” means: “protect my site and don’t index it” and “remove Google Tag Manager to avoid recording unnecessary load of traffic”.
The next thing we have to do is to configure the application module. See the code and the explanation below.
module/Application/src/Module.php
php composer.phar development-disable
or
composer development-disable
the config/autoload/development.local.php file that were created are then removed, leaving only the .dist version. In short only config/autoload/local.php will be merge into one application config.
You can test the status of development mode using:
php composer.phar development-status
or
composer development-status
That’s it, we have now configure our automatic search engine protection and we can now switch it easily using Development Mode. Have a great day!