<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Agustín Houlgrave on Medium]]></title>
        <description><![CDATA[Stories by Agustín Houlgrave on Medium]]></description>
        <link>https://medium.com/@a.houlgrave?source=rss-84589008bfd9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Ng6YKBB0Lpf1NREGD-Td0w.jpeg</url>
            <title>Stories by Agustín Houlgrave on Medium</title>
            <link>https://medium.com/@a.houlgrave?source=rss-84589008bfd9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 05:21:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@a.houlgrave/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Install New Relic on your PHP Application Docker image]]></title>
            <link>https://medium.com/@a.houlgrave/install-new-relic-on-your-php-application-docker-image-263b16a8b42c?source=rss-84589008bfd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/263b16a8b42c</guid>
            <category><![CDATA[new-relic]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Agustín Houlgrave]]></dc:creator>
            <pubDate>Thu, 10 May 2018 19:08:07 GMT</pubDate>
            <atom:updated>2018-05-10T19:08:07.849Z</atom:updated>
            <content:encoded><![CDATA[<p>New Relic is a great tool for monitoring your app’s performance. It also can be tricky to install, and the php script provided in the <a href="https://www.agustinhoulgrave.com/articles/2018-05/new-relic-installation">manual installation</a> does not work very well. Here’s how I installed quite manually:</p><h3>Know your PHP</h3><p>Let’s implement it on the dockerized project of <a href="https://www.agustinhoulgrave.com/articles/2018-05/getting-your-php-app-ready-for-deployment">this previous article</a>. This means we will use the same directory structure. If you don’t feel like reading it, at least look at the Dockerfile.</p><p>First, you will need information about the php installation of the platform your app will be running. In this case, will be the container of the docker image. Build it and access the container by running</p><p>docker exec -it &lt;container name&gt; bash</p><p>Now, let’s get the information we need:</p><h4>PHP Extension</h4><p>php -i|grep &quot;PHP Extension&quot;</p><p>The value you need should be a number like 20160303</p><h4>Architecture</h4><p>file $(which php)</p><p>This should get you x86 or x64</p><h4>Extension dir</h4><p>php -i|grep extension_dir</p><p>You’ll need the directory. For example: /usr/lib/php/20160303</p><h4>Thread Safety</h4><p>See if it’s enabled or disabled:</p><p>php -i|grep &quot;Thread Safety&quot;</p><h3>Updating your Dockerfile</h3><p>We’ll implement this in a Dockerfile, but you can always run manually the commands. This is up to your implementation.</p><p>First, we’ll write our New Relic’s configuration file, so it’s easy to modify. Put it in build/newrelic.ini.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50d66f8bcfd566bca38d75d0cf8618f5/href">https://medium.com/media/50d66f8bcfd566bca38d75d0cf8618f5/href</a></iframe><p>For more information, check <a href="https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-configuration">New Relic’s documentation on configuration</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/99d41742eb0e6cec221de48869a2c1f1/href">https://medium.com/media/99d41742eb0e6cec221de48869a2c1f1/href</a></iframe><h3>Naming your application instances</h3><p>It is true that New Relic identifies your application by the newrelic.appname configuration. If you hard code your configuration in the build/newrelic.ini file, then if you run multiple instances of it, you won’t be able to know which application is which. If you are ok with this, feel free to hard code it. If not, keep reading.</p><p>In our newrelic.ini file, we have the default name New Relic provides. We will leave it like this and change it according to an environment variable that lives inside the docker container, so you can change it depending on which environment you deploy. You will have, for example, this names on New Relic applications list:</p><ul><li>Application prod</li><li>Application test</li><li>Application dev</li></ul><p>Currently, our Dockerfile runs this at the bottom:</p><pre><em># (...)</em><br><br><strong>WORKDIR</strong> /var/www/html<br><br><em># Run supervisor</em><br><strong>CMD</strong> [&quot;supervisord&quot;, &quot;-n&quot;]</pre><p>In the Dockerfile we don’t have access to the container’s environment variables, but we can create an entrypoint.sh file that our Dockerfile can run, where we do have access to them. Put it in your build folder.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/46aa93442f630f9fe0293acdf8c6f670/href">https://medium.com/media/46aa93442f630f9fe0293acdf8c6f670/href</a></iframe><p>In your Dockerfile, copy the build/entrypoint.sh file to the root directory and add execution permissions:</p><pre><em># Dockerfile</em><br><strong>COPY</strong> ./build/entrypoint.sh /entrypoint.sh<br><strong>RUN </strong>chmod +x /entrypoint.sh</pre><p>Now you can edit your Dockerfile, remove the CMD [&quot;supervisord&quot;, &quot;-n&quot;] line and add the following:</p><pre><em>#(...)</em><br><br><strong>ENTRYPOINT</strong> [&quot;/entrypoint.sh&quot;]</pre><p>This should allow you to deploy different instances of your application and New Relic will be able to differentiate them like this:</p><ul><li>My prod application</li><li>My test application</li><li>My dev application</li></ul><p>Remember that this article is written assuming you followed <a href="https://www.agustinhoulgrave.com/articles/2018-05/getting-your-php-app-ready-for-deployment">this previous article</a>.</p><p>Now, your Dockerfile should look like this:</p><p>Don’t forget to replace the New Relic’s installation part with your custom code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/41b0f2b7150201441daa9a08706aa6cd/href">https://medium.com/media/41b0f2b7150201441daa9a08706aa6cd/href</a></iframe><p><em>Originally published at </em><a href="https://www.agustinhoulgrave.com/articles/2018-05/install-new-relic-on-your-php-application-docker-image"><em>www.agustinhoulgrave.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=263b16a8b42c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting your PHP app ready for deployment]]></title>
            <link>https://medium.com/@a.houlgrave/getting-your-php-app-ready-for-deployment-2b3676364682?source=rss-84589008bfd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b3676364682</guid>
            <category><![CDATA[supervisor]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[nginx]]></category>
            <dc:creator><![CDATA[Agustín Houlgrave]]></dc:creator>
            <pubDate>Sun, 06 May 2018 11:53:17 GMT</pubDate>
            <atom:updated>2018-05-06T11:53:17.696Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cMpXpJBb40UDBEYI7Kxj4g.png" /></figure><p>So you have your php application running smoothly on your local machine. That’s really good! But preparing it for deployment can be tricky. Here’s some things I learned by doing it:</p><p>What we’ll do is to create a docker image with our application, so we can just docker run it.</p><p>If you are not familiarised with Docker, I recommend <a href="https://docs.docker.com/get-started/#docker-concepts">learning</a> some before continuing since nowadays it is a must-know for developers.</p><h3>Setting everything up</h3><p>The application will run in only one container with PHP-FPM, NGINX and Supervisor.</p><p>I’ve seen lots of tutorials and articles about running PHP-FPM and NGINX in different containers. This is not good for deployment because both PHP-FPM and NGINX need to access the code and the only way to achieve this is to share the source code through a volume (named or local), which is not very good: we want our code to be immutable, encapsulated within the docker image.</p><p>Let’s create some files for our build process:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a25e6370018ecd7482b6fa62fb3afc3/href">https://medium.com/media/5a25e6370018ecd7482b6fa62fb3afc3/href</a></iframe><p>The Dockerfile will be in our root-level dir because we want to copy our source code to the image, and we cannot copy anything outside the build context.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b39c6b04c7f8324aa60e90f034fad49/href">https://medium.com/media/2b39c6b04c7f8324aa60e90f034fad49/href</a></iframe><p>This will be the configuration for our NGINX</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ff22e5a518915f1e01903949a2c600f/href">https://medium.com/media/9ff22e5a518915f1e01903949a2c600f/href</a></iframe><p>The supervisor configuration file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cca51f02bf7452db405a28abf2ba3be5/href">https://medium.com/media/cca51f02bf7452db405a28abf2ba3be5/href</a></iframe><p>This composer installation file is taken from <a href="https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md">Composer’s documentation</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a92456077b6928fe90133168a14a5724/href">https://medium.com/media/a92456077b6928fe90133168a14a5724/href</a></iframe><p>Remember to add volumes for other data you want to keep.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32901276e02af7f9574cb702c0ded862/href">https://medium.com/media/32901276e02af7f9574cb702c0ded862/href</a></iframe><p>Here we will set some file we don’t want to COPY to our image:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05f520b105c8cf8166af2179dc24305d/href">https://medium.com/media/05f520b105c8cf8166af2179dc24305d/href</a></iframe><h3>The environment</h3><p>It is important that your application knows the environment it’s running on by reading an environment variable. We’ll call it APP_ENV. You should be able to read it in your app with</p><p>getenv(&#39;APP_ENV&#39;);</p><p>This variable should be available inside the docker container. The idea is to build only one image that you can deploy in different environments.</p><p>docker build -t my-image .</p><p>That should get you the final image. To run it, you can</p><p>docker run -v &quot;cache:/data/cache&quot; -v &quot;logs:/data/logs&quot; -e &quot;APP_ENV=dev&quot; -p 80:80 my-image:latest</p><p>Here, we say: “Ok docker, run the image i just built, create the volumes to persist data outside the image, expose the port 80 and set environment to dev”.</p><p>You can read more about volumes <a href="https://docs.docker.com/storage/volumes/">here</a>.</p><p>Here’s a nice article that helped me a lot: <a href="https://vsupalov.com/docker-arg-env-variable-guide/">https://vsupalov.com/docker-arg-env-variable-guide/</a>.</p><p>The idea is to keep it fairly simple: don’t get tangled with ENV and ARG keywords. If you get to that, take a walk and start from scratch: it will come around :)</p><p><em>Originally published at </em><a href="https://www.agustinhoulgrave.com/articles/2018-05/getting-your-php-app-ready-for-deployment"><em>www.agustinhoulgrave.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b3676364682" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My experience using standalone Symfony Components]]></title>
            <link>https://medium.com/@a.houlgrave/my-experience-using-standalone-symfony-components-61e0251f833b?source=rss-84589008bfd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/61e0251f833b</guid>
            <category><![CDATA[symfony]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Agustín Houlgrave]]></dc:creator>
            <pubDate>Sun, 15 Apr 2018 13:40:58 GMT</pubDate>
            <atom:updated>2018-05-06T12:02:24.546Z</atom:updated>
            <content:encoded><![CDATA[<p>A while ago, I was not convinced about <a href="https://symfony.com/doc/current/components/dependency_injection.html">Symfony’s DI</a>. Instead, I liked <a href="https://docs.zendframework.com/zend-servicemanager/">Zend Service Manager</a>, but <a href="https://symfony.com/doc/current/components/form.html">Symfony Forms</a> as well, also ZendFramework won’t let you use Symfony Forms. So I just got a basic little project started that could enable you to get a routing library and wire it to any <a href="https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md">PSR-11</a> compiling container.<br>This allowed me to insert any component from <a href="http://symfony.com/">Symfony</a>, <a href="http://auraphp.com/">Aura</a>, <a href="https://framework.zend.com/">ZendFramework</a>, etc.</p><p>Yay! I was able to pick any flavour I wanted to fit my needs! My first thoughts for a web application were:</p><ul><li>Zend Service Manager</li><li>Symfony Forms and <a href="https://symfony.com/doc/current/components/validator.html">Validator</a></li><li><a href="https://www.doctrine-project.org/">Doctrine</a></li><li><a href="https://symfony.com/doc/current/components/security.html">Symfony’s security component</a></li></ul><p>So, everything went well. I could set up Symfony Forms with no problems, until I wanted to use Doctrine’s Form Types: These have dependencies on <a href="https://github.com/doctrine/common/blob/master/lib/Doctrine/Common/Persistence/ManagerRegistry.php">ManagerRegistry</a>, which is the object than manages all the EntityManagers you have on your Symfony application. It’s responsible for getting the right manager for the right entity, etc.</p><p>In my application I had only an EntityManager, so I had lots of trouble, not only with the forms, but with <a href="https://stackoverflow.com/a/49841579/2307986">Symfony’s validator</a> as well. I guess that you can use a ManagerRegistry to wrap your EntityManager from the start of the project, but this is only needed for Symfony’s components integration, which are supposed to be standalone.</p><p>Ok, it wasn’t that bad, I could manage to integrate these. But then the Security Component was next: It’s <strong>binded to the full-stack framework at a very deep level</strong> and I decided it was not worth it: I had a framework-agnostic application! So in the end I went with <a href="https://github.com/auraphp/Aura.Auth">Aura’s auth component</a>, which was much easier to work with.</p><p>Symfony Components are easy to integrate, as long as their functionality is very isolated, like <a href="https://symfony.com/doc/current/components/serializer.html">Serializer</a> or Forms (with no doctrine extension). All the doctrine bridges need the ManagerRegistry, so take this in account when planning a project. Big components as the security one it’s not worth it. I know they’re supposed to be able to work outside the full-stack framework, but they’re also made to work with it as better as possible.</p><p>Link to my blog’s post: <a href="https://www.agustinhoulgrave.com/articles/2018-04/my-experience-using-standalone-symfony-components">https://www.agustinhoulgrave.com/articles/2018-04/my-experience-using-standalone-symfony-components</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61e0251f833b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A guide to a proper PHP Symfony Console Application]]></title>
            <link>https://medium.com/@a.houlgrave/a-guide-to-a-proper-php-console-application-325ef677faf1?source=rss-84589008bfd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/325ef677faf1</guid>
            <category><![CDATA[symfony]]></category>
            <category><![CDATA[application]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[console]]></category>
            <dc:creator><![CDATA[Agustín Houlgrave]]></dc:creator>
            <pubDate>Thu, 01 Feb 2018 11:48:38 GMT</pubDate>
            <atom:updated>2018-05-19T09:16:24.999Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*_vwwl1HhdAQ8jPdPHkRs3A.jpeg" /></figure><p>Googling this topic, I could only find official documentation on <a href="https://symfony.com/doc/current/components/console/single_command_tool.html">Symfony’s Console Component</a> and some tutorials on quick building, but i’d like to write about making a real scalable console application that you could use in an actual production project. I’ll explain the reasons we do each of the things.</p><p>I like to write decoupled, reusable and as raw as possible code, so we’ll try to aim on that direction. Also, we’ll take advantage of all of the new features of PHP 7. Remember that this means that you’ll require a version higher than 7.1.</p><p>Basically, we will only use a dependency container and <a href="https://symfony.com/doc/current/components/console.html">Symfony’s Console Component</a> and put them together. Should be fairly easy and simple. Personally, I like <a href="https://docs.zendframework.com/zend-servicemanager/">Zend’s Service Manager</a>, but you can use any dependency container you like. Try to pick a <a href="https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md">PSR-11</a> compiling one.</p><p>Let’s start by initialising a composer definition and requiring the service manager:</p><pre>composer init --require zendframework/zend-servicemanager &amp;&amp; composer install</pre><p>We must also require Symfony’s console component:</p><pre>composer require symfony/console</pre><p>Let’s create a console command. Nothing fancy, just a standard Symfony Command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b759c411cbfe441569ca708f8d4fb3b/href">https://medium.com/media/3b759c411cbfe441569ca708f8d4fb3b/href</a></iframe><p>Remember to autoload your code in your composer.json:</p><pre>“autoload”: {<br>    “psr-4”: {<br>        “App\\”: “src/App/”<br>    }<br>}</pre><p>Next step would be registering this command as a service. We want this application to be able to scale, that’s why it’s important to keep a clean dependency injection control.</p><p>For simplicity’s sake, I will use anonymous functions for the factories, but in a real project, I’d use proper factory classes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae702c05f9f1c6eccc35e6dc5118fa2d/href">https://medium.com/media/ae702c05f9f1c6eccc35e6dc5118fa2d/href</a></iframe><p>I recommend to keep all of your commands as services, even if they won’t have dependencies. Also, we’ll create a config file that returns all of the commands for the application.</p><p>The only thing left would be to create the front controller. We just need to instantiate a new Console and register all of our commands, that we’ll load from our confir file and pull from our container ;)</p><p>We’ll use an extension-less file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d4b00e2270efb9fa842fad52f053e1f/href">https://medium.com/media/3d4b00e2270efb9fa842fad52f053e1f/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f0259ba76d94b9ff0852bac612c3727/href">https://medium.com/media/7f0259ba76d94b9ff0852bac612c3727/href</a></iframe><p>That’s it!</p><p>You should be able to run php application my:command and see My awesome command! printed in the console.</p><p>Some people would extend Symfony’s Application class, but I think it’s not necessary since that class is already meant to be extended for this use case.</p><p>You can create all the commands and services you need. Just add the commands you create to the config file. This intended to be scalable and PHP 7 standard compiling.</p><p>I created a <a href="https://github.com/ahoulgrave/console-application">Github repository</a> where you can see a fully-running example.</p><p>I’d be glad to answer any questions you have.</p><p>Hope this is useful to someone! Cheers!</p><p>Link to this article on my blog: <a href="https://www.agustinhoulgrave.com/articles/2018-02/a-guide-to-a-nice-php-console-application">https://www.agustinhoulgrave.com/articles/2018-02/a-guide-to-a-nice-php-console-application</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=325ef677faf1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>