<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MariaDB &#8211; CodePills.com</title>
	<atom:link href="https://codepills.com/tag/mariadb/feed/" rel="self" type="application/rss+xml" />
	<link>https://codepills.com</link>
	<description>Helping you make a better code</description>
	<lastBuildDate>Sun, 19 Jun 2022 17:12:08 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>How to use Docker for WordPress development</title>
		<link>https://codepills.com/how-to-use-docker-for-wordpress-development/</link>
					<comments>https://codepills.com/how-to-use-docker-for-wordpress-development/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Mon, 25 Nov 2019 14:12:49 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<guid isPermaLink="false">https://codepills.com/?p=1036</guid>

					<description><![CDATA[This is a simple tutorial on how to start using Docker for WordPress development. <a href="https://codepills.com/how-to-use-docker-for-wordpress-development/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>This article is a simple tutorial on how to start using Docker for WordPress development.</p>
<p><span id="more-1036"></span></p>
<p>In the last couple of months, I had a problem with the XAMPP MySQL database. Without any particular reason, from one day to another, it just failed. XAMPP UI does not show any error.</p>
<p>DB recovery does not help, and it seems that every StackOverflow solution does not work. And digging deeper into the database stack did not bring any working solution.</p>
<p>The only solution which seems to work is to delete the XAMPP entirely and create a fresh new installation. Of course, this is a very tedious and time-consuming solution.</p>
<p>Moreover new MacOS update Catalina just made things worse, and XAMPP MySQL failed instantly. Instead of starting using MAMP, which is just the same way of doing things as XAMPP, I have decided it is the right time to start utilizing the power of Docker for WordPress development.</p>
<h2>Using Docker for WordPress development</h2>
<p>I have decided to create this simple tutorial for WordPress development with Docker for whoever would like to need it. This tutorial is written for macOS/Unix systems based operating systems. However, it is helpful for Windows users as well.</p>
<p>Here is a simple list of steps necessary for starting WordPress development with Docker:</p>
<h2>Step no. 1 &#8211; Install Docker</h2>
<p>Well, of course, the first step is to install Docker itself. I will step over this step while this could be a stand-alone tutorial for that. However, it is super easy, and it can complete even beginner PC user alone.</p>
<h2>Step no. 2 &#8211; Think what do you need for WordPress development</h2>
<p>We will need three containers for WordPress development with Docker. These containers will be:</p>
<ul>
<li>PHP server running WordPress</li>
<li>MySQL or MariaDB database based on your choice</li>
<li>Access to database (over phpMyAdmin GUI)</li>
</ul>
<p>Accessing the database over GUI is optional. Same as selecting the database of your choice. MySQL or MariaDB is up to your preference. So based on what are your needs, you should check the appropriate section in the next step.</p>
<h2>Step no. 2 &#8211; Create docker-compose.yml file</h2>
<p>Create a new directory for a project you want to develop. It will be the location of your choice. This folder should contain single file <code>docker-compose.yml</code>.</p>
<p><b>TIP:</b> There is a nice hack for doing all the steps in one. Just type in your terminal this command <code>mkdir NEW_PROJECT_NAME && cd $_ && touch docker-compose.yml</code> and you will all do this in one line.</p>
<p>Copy code below to <b>docker-compose.yml</b></p>
<pre><code class="language-yml">version: "3.1"

networks:
  wp:

volumes:
  db_storage:

services:

  wordpress:
    container_name: CUSTOM_PROJECT_NAME_wordpress
    image: wordpress
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
    volumes:
        - ./:/var/www/html/wp-content
    ports:
      - 80:80
      - 443:443
    networks:
      - wp
    depends_on:
      - db

  db:
    container_name: CUSTOM_PROJECT_NAME_db
    image: mariadb
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    volumes:
      - db_storage:/var/lib/mysql
    ports:
      - 3306:3306
    networks:
      - wp

  phpmyadmin:
    container_name: CUSTOM_PROJECT_NAME_db_gui
    image: phpmyadmin
    restart: always
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: password
    ports:
      - 8080:80
    networks:
      - wp
    depends_on:
      - db</code></pre>
<p>Let&#8217;s cut down the composer file to pieces and figure out what it does.</p>
<pre><code class="language-yml">version: "3.1"

networks:
  wp:

volumes:
  db_storage:

services:</code></pre>
<table class="table">
<thead>
<tr>
<th scope="col">Line</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td scope="row">version: &#8220;3.1&#8221;</td>
<td>Version of the Compose file format. Version 3 or higher is the most current and recommended to use.</td>
</tr>
<tr>
<td scope="row">networks: wp:</td>
<td>All networks used for the service. We need to create just one custom network for our containers.</td>
</tr>
<tr>
<td scope="row">volumes: db_storage:</td>
<td>All volumes used for the service. We need to create just one custom volume for our containers.</td>
</tr>
<tr>
<td scope="row">services:</td>
<td>All containers used for this service. We need to create just one custom service.</td>
</tr>
</tbody>
</table>
<pre><code class="language-yml">wordpress:
    container_name: CUSTOM_PROJECT_NAME_wordpress
    image: wordpress
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - ./:/var/www/html/wp-content
    ports:
      - 80:80
      - 443:443
    networks:
      - wp
    depends_on:
      - db</code></pre>
<table class="table">
<thead>
<tr>
<th scope="col">Line</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td scope="row">container_name</td>
<td>Define the container name in CUSTOM_PROJECT_NAME_wordpress.</td>
</tr>
<tr>
<td scope="row">image: wordpress</td>
<td>If you do not define nothing, latest version of Docker file will be downloaded. To specify custom version of WordPress just add double dot e.g.: wordpress:5.3.0</td>
</tr>
<tr>
<td scope="row">restart: always</td>
<td>Define restart policy &#8211; <a href="//docs.docker.com/compose/compose-file/#restart”" rel="”nofollow” noopener" target="”_blank”">Docker reference</a></td>
</tr>
<tr>
<td scope="row">volumes:<br />
                &#8211; ./:/var/www/html/wp-content</td>
<td>Local folder mapped to container wp-content path. For normal theme or plugin development we do not need to access WordPress core file. <a href="//hub.docker.com/_/wordpress”" rel="”nofollow” noopener" target="”_blank”">Docker WordPress image</a></td>
</tr>
<tr>
<td scope="row">environment:<br />
                WORDPRESS_DB_HOST: db:3306<br />
                WORDPRESS_DB_USER: wordpress<br />
                WORDPRESS_DB_PASSWORD: wordpress<br />
                WORDPRESS_DB_NAME: wordpress</td>
<td>WordPress Docker environment. If you use containers just locally, I would suggest to keep this dummy passwords. Otherwise you are free to change it to your needs. <a href="https://docs.docker.com/compose/compose-file/#environment" target="_blank" rel="nofollow noopener">Docker environment</a></td>
</tr>
<tr>
<td scope="row">ports:<br />
                &#8211; 80:80<br />
                &#8211; 443:443</td>
<td>I/O ports for HTTP and HTTPS</td>
</tr>
<tr>
<td scope="row">networks:<br />
                &#8211; wp</td>
<td>Network to join.</td>
</tr>
<tr>
<td scope="row">depends_on:<br />
                &#8211; db</td>
<td>Dependency declaration.</td>
</tr>
</tbody>
</table>
<p><strong>With just a simple change of DB image from MariaDB to MySQL, you can get different database engine according to your needs. Otherwise, everything is the same for both containers.</strong></p>
<pre><code class="language-yml">db:
    container_name: CUSTOM_PROJECT_NAME_db
    image: mariadb
    # image: mysql
    restart: always
    environment:
        MYSQL_ROOT_PASSWORD: password
        MYSQL_DATABASE: wordpress
        MYSQL_USER: wordpress
        MYSQL_PASSWORD: wordpress
    volumes:
        - db_storage:/var/lib/mysql
    ports:
        - 3306:3306
    networks:
        - wp
</code></pre>
<table class="table">
<thead>
<tr>
<th scope="col">Line</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td scope="row">container_name</td>
<td>Define the container name in CUSTOM_PROJECT_NAME_wordpress.</td>
</tr>
<tr>
<td scope="row">image: mariadb</td>
<td>If you do not define nothing, latest version of Docker file will be downloaded. <a href="//hub.docker.com/_/mariadb/”" rel="”nofollow” noopener" target="”_blank”">Docker MariaDB image</a><br />If you want to MySQL database instead of MariaDB, type just <code><b>image: mysql</b></code> and latest image of MySQL will be downloaded.</td>
</tr>
<tr>
<td scope="row">restart: always</td>
<td>Define restart policy &#8211; <a href="//docs.docker.com/compose/compose-file/#restart”" rel="”nofollow” noopener" target="”_blank”">Docker reference</a></td>
</tr>
<tr>
<td scope="row">volumes:<br />
                &#8211; db_storage:/var/lib/mysql</td>
<td>Name volume allow data persistence without bothering where the data are stored.</td>
</tr>
<tr>
<td scope="row">environment:<br />
                MYSQL_ROOT_PASSWORD: password<br />
                MYSQL_DATABASE: wordpress<br />
                MYSQL_USER: wordpress<br />
                MYSQL_PASSWORD: wordpress</td>
<td>WordPress Docker environment. If you use containers just locally, I would suggest to keep this dummy passwords. Otherwise you are free to change it to your needs. <a href="https://docs.docker.com/compose/compose-file/#environment" target="_blank" rel="nofollow noopener">Docker environment</a></td>
</tr>
<tr>
<td scope="row">ports:<br />
                &#8211; 3306:3306</td>
<td>Database access ports.</td>
</tr>
<tr>
<td scope="row">networks:<br />
                &#8211; wp</td>
<td>Network to join.</td>
</tr>
</tbody>
</table>
<pre><code class="language-yml">phpmyadmin:
  container_name: CUSTOM_PROJECT_NAME_db_gui
  image: phpmyadmin
  restart: always
  environment:
    PMA_HOST: db
    MYSQL_ROOT_PASSWORD: password
  ports:
    - 8080:80
  networks:
    - wp
  depends_on:
    - db</code></pre>
<table class="table">
<thead>
<tr>
<th scope="col">Line</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td scope="row">container_name</td>
<td>Define the container name in CUSTOM_PROJECT_NAME_wordpress.</td>
</tr>
<tr>
<td scope="row">image: phpmyadmin/phpmyadmin</td>
<td>If you do not define nothing, latest version of Docker file will be downloaded.</td>
</tr>
<tr>
<td scope="row">restart: always</td>
<td>Define restart policy &#8211; <a href="//docs.docker.com/compose/compose-file/#restart”" rel="”nofollow” noopener" target="”_blank”">Docker reference</a></td>
</tr>
<tr>
<td scope="row">  environment:<br />
                PMA_HOST: db<br />
                MYSQL_ROOT_PASSWORD: password</td>
<td>WordPress Docker environment. If you use containers just locally, I would suggest to keep this dummy passwords. Otherwise you are free to change it to your needs. <a href="https://docs.docker.com/compose/compose-file/#environment" target="_blank" rel="nofollow noopener">Docker environment</a></td>
</tr>
<tr>
<td scope="row">ports:<br />
                &#8211; 8080:80</td>
<td>Connect local 8080 port call to 80 port at Docker service.</td>
</tr>
<tr>
<td scope="row">networks:<br />
                &#8211; wp</td>
<td>Network to join.</td>
</tr>
<tr>
<td scope="row">depends_on:<br />
                &#8211; db</td>
<td>Dependency declaration.</td>
</tr>
</tbody>
</table>
<h2>Step no. 3 &#8211; Run Docker with docker-compose up -d</h2>
<p>From now on all will go quickly. Just type <code>docker-compose up -d</code> and after initial download of all dependencies everything goes smoothly. When all your containers will shine as <code>done</code> you are ready to proceed.</p>
<p>If you run <code>docker ps</code>, you should now see three services with the name you defined in the docker-compose.yml file.</p>
<h2>Step no. 4 &#8211; Install WordPress</h2>
<p>You can find the new WordPress installation at <code>http://localhost:8080/</code> address. Just proceed with the installation as usual and create a new WordPress installation in your local directory. From now on, you can access this WordPress installation as usual.</p>
<p>If you want to access database with phpMyAdmin use <code>http://localhost:8080/index.php</code> address. If you do not change password in yaml file, use name:<code>password</code> and password:<code>password</code> as login information.</p>
<p>So remember, to access:</p>
<ul>
<li><code>http://localhost:80/</code> &#8211; WordPress</li>
<li><code>http://localhost:8080/</code> &#8211; phpMyAdmin (name: password, password: password)</li>
</ul>
<h2>Step no. 5 &#8211; Load your Git theme/plugin repository</h2>
<p>Everything works as if you would be developing any other WordPress project now. If you have your project versioned in Git, go to themes or plugin folder and <code>Git clone</code> your project there. Any change made there will reflect as <code>git diff</code> in Git.</p>
<h2>Step no. 6 &#8211; Shutdown the Docker processes when you finished</h2>
<p>Finally, to proceed and stop Docker container lifecycle, you need to learn a few more commands. They are:</p>
<ul>
<li><code>docker-compose up</code> &#8211; run the processes, however they are attached to life of your terminal window. Docker process will be terminated on the terminal window close up.</li>
<li><code>docker-compose up -d</code> &#8211; leaves the processes running without being attached to your terminal window. Use <code>-d</code> as “detach” for Docker to starts the containers in the background and leaving them running, independently on your terminal window life. <a href="//docs.docker.com/compose/reference/up/”" target="”_blank”" rel="”nofollow” noopener">Docker reference for up</a></li>
<li><code>docker-compose stop</code> &#8211; stop the processes</li>
<li><code>docker-compose down</code> &#8211; stop and removes the processes</li>
<li><code>docker-compose rm -v</code> &#8211; docker cleanup</li>
<li><code>CTRL+C</code> &#8211; killing processes, terminal key shortcut</li>
</ul>
<p>I recommend you kill the Docker processes for your theme every time you think you finished the day. It is advice based on experience from life. If you kill the processes the next day, you can be sure they are not working because they are down, but not because something else went wrong. Plus, if you switch often projects as I do, it is good to keep the system utilization low and order everything.</p>
<h2>Known issues</h2>
<p>While dealing with Docker, some things can go wrong. However, we will not go through all of them here. Let&#8217;s take a look only at the most occurring issues.</p>
<h3>Error establishing a database connection</h3>
<p><img fetchpriority="high" decoding="async" src="https://codepills.com/wp-content/uploads/2019/11/error_establishing_a_database_connection-1024x229.png" alt="Error establishing a database connection - WordPress" width="640" height="143" class="size-large wp-image-1150" srcset="https://codepills.com/wp-content/uploads/2019/11/error_establishing_a_database_connection-1024x229.png 1024w, https://codepills.com/wp-content/uploads/2019/11/error_establishing_a_database_connection-300x67.png 300w, https://codepills.com/wp-content/uploads/2019/11/error_establishing_a_database_connection-768x172.png 768w, https://codepills.com/wp-content/uploads/2019/11/error_establishing_a_database_connection-1536x343.png 1536w, https://codepills.com/wp-content/uploads/2019/11/error_establishing_a_database_connection.png 1611w" sizes="(max-width: 640px) 100vw, 640px" /></p>
<p>If you get an error saying <code>Error establishing a database connection</code> check the name interconnecting database credentials and database name between WordPress and database.</p>
<h2>Conclusion</h2>
<p>I hope you liked this simple tutorial explaining how to quickly and effectively set up Docker for WordPress development. If you have any comments or constructive criticism or have other ideas on enhancing this YML file or tutorial, please write me a comment. I will appreciate it.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/how-to-use-docker-for-wordpress-development/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
