<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Simon Frey</title>
    <description>The latest articles on DEV Community by Simon Frey (@simonfrey).</description>
    <link>https://dev.to/simonfrey</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F339629%2F1d68effc-48f8-4014-9c0a-b75bc7750bd9.png</url>
      <title>DEV Community: Simon Frey</title>
      <link>https://dev.to/simonfrey</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/simonfrey"/>
    <language>en</language>
    <item>
      <title>Local WordPress plugin development with docker-compose</title>
      <dc:creator>Simon Frey</dc:creator>
      <pubDate>Wed, 27 May 2020 13:40:58 +0000</pubDate>
      <link>https://dev.to/simonfrey/local-wordpress-plugin-development-with-docker-compose-nil</link>
      <guid>https://dev.to/simonfrey/local-wordpress-plugin-development-with-docker-compose-nil</guid>
      <description>&lt;p&gt;As my WordPress plugin development process was quite flawed (Write code locally =&amp;gt; upload via FTP =&amp;gt; test on server =&amp;gt; repeat :’D) I had to search for a better solution for being able to local develop plugins and test them.&lt;/p&gt;

&lt;p&gt;I used this awful process before as I did not want to install all required software for running WordPress (Apache, MySQL, PHP) on my local machine as I like it being clean and only having services running I really need at that certain moment.&lt;/p&gt;

&lt;p&gt;The better sysadmins of you would claim that I still could easily start/stop the services for only having them running when I am developing…but boy that still sounds like a way to big hassle for me.&lt;/p&gt;

&lt;p&gt;And as you always do this nowadays: Docker for the rescue 😉&lt;br&gt;
After researching and working my way to build a docker-compose file I now can say: This time this approach worked like a charm.&lt;/p&gt;

&lt;p&gt;It now only is docker-compose up and WordPress is running. I can live edit the files of my plugins, and they are loaded and used instantly.&lt;/p&gt;
&lt;h2&gt;
  
  
  docker-compose.yml
&lt;/h2&gt;

&lt;p&gt;I assume you know about docker and docker-compose, if not give this article a read.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;3.3'&lt;/span&gt;
&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
   &lt;span class="na"&gt;db&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
     &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;mysql:5.7&lt;/span&gt;
     &lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
       &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;db_data:/var/lib/mysql&lt;/span&gt;
     &lt;span class="na"&gt;restart&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;always&lt;/span&gt;
     &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
       &lt;span class="na"&gt;MYSQL_ROOT_PASSWORD&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;rootpw&lt;/span&gt;
       &lt;span class="na"&gt;MYSQL_DATABASE&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;wordpress&lt;/span&gt;
       &lt;span class="na"&gt;MYSQL_USER&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;wordpress&lt;/span&gt;
       &lt;span class="na"&gt;MYSQL_PASSWORD&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;wordpress&lt;/span&gt;
   &lt;span class="na"&gt;wordpress&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
     &lt;span class="na"&gt;depends_on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
       &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;db&lt;/span&gt;
     &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;wordpress:latest&lt;/span&gt;
     &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
       &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;8080:80"&lt;/span&gt;
     &lt;span class="na"&gt;restart&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;always&lt;/span&gt;
     &lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
         &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;../mastodon_wordpress_autopost/autopost-to-mastodon/trunk:/var/www/html/wp-content/plugins/autopost-to-mastodon:ro&lt;/span&gt;
     &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
       &lt;span class="na"&gt;WORDPRESS_DB_HOST&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;db:3306&lt;/span&gt;
       &lt;span class="na"&gt;WORDPRESS_DB_USER&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;wordpress&lt;/span&gt;
       &lt;span class="na"&gt;WORDPRESS_DB_PASSWORD&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;wordpress&lt;/span&gt;
       &lt;span class="na"&gt;WORDPRESS_DB_NAME&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;wordpress&lt;/span&gt;
&lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;db_data&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After executing &lt;code&gt;docker-compose up&lt;/code&gt; in the directory of the &lt;code&gt;docker-compose.yml&lt;/code&gt; all the services are started up and you are greeted with a WordPress installer on &lt;code&gt;localhost:8080&lt;/code&gt; (as I mapped the WordPress port to 8080).&lt;/p&gt;

&lt;p&gt;Click trough the WordPress installer and you got a working instance running.&lt;/p&gt;

&lt;p&gt;Via the volumes section you can map outside directories into the installation.&lt;br&gt;
E.g. The following config maps my local developer directory &lt;code&gt;../mastodon_wordpress_autopost/autopost-to-mastodon/trunk&lt;/code&gt; (which I have open in my editor) into the plugins directory of WordPress.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt; &lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
         &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;../mastodon_wordpress_autopost/autopost-to-mastodon/trunk:/var/www/html/wp-content/plugins/autopost-to-mastodon:ro&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can map as many directories as you want. Keep in mind that the path is relative to the location of the &lt;code&gt;docker-compose.yml&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After activating the plugin in the WordPress GUI the plugin is up and running and I can live edit at in my editor. As it is mapped and not copied into the docker container all changes are reflected live.&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>docker</category>
    </item>
  </channel>
</rss>
