<?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>Forem: truthseekers</title>
    <description>The latest articles on Forem by truthseekers (@truthseekers).</description>
    <link>https://forem.com/truthseekers</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%2F417132%2F26113c95-cf7f-4cd3-92b6-5ecdb43c5599.png</url>
      <title>Forem: truthseekers</title>
      <link>https://forem.com/truthseekers</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/truthseekers"/>
    <language>en</language>
    <item>
      <title>How to Setup an ideal WordPress Development Environment</title>
      <dc:creator>truthseekers</dc:creator>
      <pubDate>Thu, 02 Jul 2020 03:48:12 +0000</pubDate>
      <link>https://forem.com/truthseekers/how-to-setup-an-ideal-wordpress-development-environment-12n6</link>
      <guid>https://forem.com/truthseekers/how-to-setup-an-ideal-wordpress-development-environment-12n6</guid>
      <description>&lt;p&gt;WordPress is not my primary development environment. I only go in when I need certain functionality or design fixes for my own site, and by far the most painful part is getting set up. (Maybe I'm just a N00b). The biggest problem I had with my former development environments was not being able to access the source code and poke around.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://truthseekers.io/latest-tutorials-signup/"&gt;Learn to code with our beginner friendly tutorials on programming, Linux, Docker, and more&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sure, I can READ it on Github, but it's hard for me to figure out what's going on by just reading. &lt;strong&gt;I need to be able to interact with the WordPress source code.&lt;/strong&gt; Also, being the large beast that WordPress has become, documentation can't keep up, so it's necessary to access the source code... So here's how I've been able to do that by setting up an &lt;span&gt;"ideal WordPress Development Environment"&lt;/span&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Edit: I spent way too many hours debugging NPM errors on a new windows machine to get this setup working. &lt;/strong&gt;&lt;a rel="noreferrer noopener" href="https://github.com/felixrieseberg/windows-build-tools/issues/56"&gt;The solution I found here&lt;/a&gt; appears to be &lt;code&gt;npm install --global --production windows-build-tools&lt;/code&gt; and if your install failed before doing this, you'll probably have to DELETE the $HOME/.node-gyp folder  (when you install something that needs it, it will automatically be re-installed.&lt;/p&gt;

&lt;h3&gt;What you need:&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/WordPress/wordpress-develop" rel="noreferrer noopener"&gt;WordPress-Develop Github Repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/WordPress/gutenberg/blob/master/docs/contributors/getting-started.md" rel="noreferrer noopener"&gt;Gutenberg Github Repository&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;Step 1. Setup the WordPress-Develop repository locally.&lt;/h3&gt;

&lt;p&gt;go through their instructions. Currently you just need Node.js and Docker installed &lt;strong&gt;and running&lt;/strong&gt;. So do that and come back.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/SiaXzkZN_fM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;clone the wordpress-develop repository. I created a folder on my Desktop where the entire setup will go called "hello-wordpress" and then inside "hello-wordpress" is where I cloned the wordpress-develop repository. Then cd in and setup the environment as it explains in the readme:&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;mkdir hello-wordpress
cd hello-wordpress
git clone https://github.com/WordPress/wordpress-develop.git
cd wordpress-develop
npm install
npm run watch&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note that we skip a lot of instructions on the wordpress-develop docs page because we're going to be using Gutenberg for the Docker setup. If we were to run the other commands in the wordpress-develop then they would interfere with Gutenberg.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;npm run watch&lt;/strong&gt; is important because it gives us the "build" folder inside wordpress-develop that the gutenberg code relies on.&lt;/p&gt;

&lt;p&gt; that's as far as we go in these instructions for now. &lt;strong&gt;Next step is to download and install Gutenberg Core.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now change OUT of the wordpress-develop folder and back INTO hello-wordpress... Then clone gutenberg:&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;cd ../
git clone https://github.com/WordPress/gutenberg.git
cd gutenberg
npm install&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now we'll want to setup where our plugin code goes. Make another folder inside the "hello-wordpress" folder called "plugins", and create your plugins in there. Mine will be "my-cool-plugin"  So here's my  basic plugin code in this file:&lt;strong&gt; hello-wordpress/plugins/my-cool-plugin/my-cool-plugin.php&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;&amp;lt;?php
/**
 * Plugin Name: My cool plugin
 * Plugin URI: https://truthseekers.io
 * Description: cool plugin stuff
 * Author: John
 * Author URI: https://truthseekers.io
 */&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That should be enough to activate our plugin.&lt;/p&gt;

&lt;p&gt;Next, we need to "connect" our plugins folder with Gutenberg. We do that in &lt;code&gt;.wp-env.override.json&lt;/code&gt; inside our &lt;strong&gt;gutenberg folder&lt;/strong&gt;. This file doesn't exist by default (as of writing this) so we'll need to create it. (in the same level as the package.json file)&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;{
    "core": "../wordpress-develop/build",
    "plugins": [
        ".",
        "../plugins/my-cool-plugin"
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The "core" line tells the Gutenberg plugin that the rest of the wordpress project is located in the wordpress-develop/build folder. That's where it will grab all the source... &lt;/p&gt;

&lt;p&gt;Each element in the "plugins" array is a directory for each plugin that you want activated. So.. "." for the gutenberg plugin, and then the location of the plugin you're developing.&lt;/p&gt;

&lt;p&gt;Almost done. Now we just need to go back to the &lt;strong&gt;gutenberg folder&lt;/strong&gt; and start things up.&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;npx wp-env start
npm run dev&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now you can access the WP dashboard area by visiting localhost:8888  and use "admin" and "password" as the credentials. Go visit the "plugins" section to see your plugin is activated.  To test, go to the "wordpress-develop" folder, and &lt;strong&gt;run a die statement in wp-includes/blocks.php&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tq3rB5fk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://truthseekers.io/wp-content/uploads/2020/06/image-29.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tq3rB5fk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://truthseekers.io/wp-content/uploads/2020/06/image-29.png" alt="" class="wp-image-4202"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And refresh your admin area and hopefully you'll see it:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nUkz3i98--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://truthseekers.io/wp-content/uploads/2020/06/image-30.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nUkz3i98--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://truthseekers.io/wp-content/uploads/2020/06/image-30.png" alt="" class="wp-image-4204"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now test Gutenberg code. In the gutenberg folder, inside &lt;strong&gt;packages/blocks/src/index.js run a console.log...&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;and you should see the results of your console.log inside the dev tools when you're in the gutenberg editor area.&lt;/p&gt;

&lt;p&gt;When you're done coding, &lt;strong&gt;kill everything with &lt;code&gt;CTRL+C&lt;/code&gt; to kill npm run dev.. Then &lt;/strong&gt;&lt;code&gt;npx wp-env stop&lt;/code&gt; to kill Gutenberg/Docker. Finally, &lt;/p&gt;

&lt;p&gt;hit&lt;code&gt; CTRL+C&lt;/code&gt; in wordpress-develop to kill wordpress-develop.&lt;/p&gt;

&lt;p&gt;To start everything back up, &lt;code&gt;npm run watch&lt;/code&gt;  in wordpress-develop,   then inside "gutenberg" run &lt;code&gt;npx wp-env start&lt;/code&gt;   and then &lt;code&gt;npm run dev&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You should have access to wp-cli utilities within the Gutenberg folder.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://truthseekers.io/latest-tutorials-signup/"&gt;Don't miss our next tutorials!&lt;/a&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>gutenberg</category>
      <category>plugins</category>
    </item>
    <item>
      <title>Setup a basic Local PHP Development Environment in Docker</title>
      <dc:creator>truthseekers</dc:creator>
      <pubDate>Sat, 27 Jun 2020 00:29:48 +0000</pubDate>
      <link>https://forem.com/truthseekers/setup-a-basic-local-php-development-environment-in-docker-kod</link>
      <guid>https://forem.com/truthseekers/setup-a-basic-local-php-development-environment-in-docker-kod</guid>
      <description>&lt;p&gt;In this post we'll learn how to setup a basic local PHP development environment in Docker. We'll be using docker-compose and Dockerfile to achieve this. We'll use PHP, Apache, and Mysql. Setting up a comprehensive environment with things like task runners, composer, etc... will come in later tutorials.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://truthseekers.io/latest-tutorials-signup/" rel="noopener noreferrer"&gt;Learn to code with our beginner friendly tutorials&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you just want the quick and dirty source code, then skip to the bottom. We're going to take this nice and slowly going step-by-step.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pre-Requisites: Docker &amp;amp; Docker-compose installed.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/ThpnqYpvnIM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First step: Get a simple PHP script to run with Dockerfile&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you take a look at the &lt;a rel="noreferrer noopener" href="https://hub.docker.com/_/php"&gt;PHP Docker docs&lt;/a&gt; you won't see anything about a docker-compose file, but we can figure out how to do it with what they do give us. At the very beginning they give us a simple Dockerfile setup. Let's use that for our Dockerfile in the root of our project directory: I'm calling my project "php-docker". Then inside make a &lt;code&gt;Dockerfile&lt;/code&gt; with this code:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;FROM php:7.4-cli
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
CMD [ "php", "./index.php" ]&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This code is the setup to create the image we'll use.  This setup pulls in PHP 7.4 with some command line stuff.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;COPY . /usr/src/myapp&lt;/code&gt; copies the contents of the current directory into /usr/src/myapp inside the Docker container. The next line: &lt;code&gt;WORKDIR /usr/src/myapp&lt;/code&gt; sets the /usr/src/myapp as the "working directory", kind of like you would cd /to/your/project.&lt;/p&gt;

&lt;p&gt;Then from inside the /usr/src/myapp folder we run the command &lt;code&gt;$ php ./index.php&lt;/code&gt; where index.php is our script. So that means we need a PHP script. Let's create our &lt;code&gt;index.php&lt;/code&gt; file inside the project directory like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;?php

echo "Hello from the docker container";&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now we can continue with their instructions, which is to build and run the docker image:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ docker build -t my-php-app .
$ docker run -it --rm --name my-running-app my-php-app&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The first command is going to build the image with the name "my-php-app" on your computer using the contents of the current directory. The second command prepares a container called "my-running-app based off the image we just created "my-php-app". We setup to run the index.php script, so our script runs in the command line. We should get something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftruthseekers.io%2Fwp-content%2Fuploads%2F2020%2F06%2Fimage-20.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftruthseekers.io%2Fwp-content%2Fuploads%2F2020%2F06%2Fimage-20.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First step accomplished! But simple PHP scripts aren't very useful. Let's set this up on an Apache web server. If you scroll further down the documentation you'll see an "Image variants" section with one of them being php-apache. This image has Apache bundled with PHP. This will allow us to easily get our script running on a webserver and display the script results in a browser. Again, let's follow the directions. &lt;strong&gt;To run the Apache/php image WITHOUT a dockerfile, run this command:&lt;/strong&gt;  (Note the first line is for Linux/Mac users and the 2nd line is for the lonely Windows users&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;docker run -d -p 80:80 --name my-apache-php-app -v "$PWD":/var/www/html php:7.2-apache # This line for *nix users
docker run -d -p 80:80 --name my-apache-php-app -v C:\Users\fastp\Desktop\Code\tutorials\php-docker:/var/www/html php:7.2-apache   # For Windows users&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This line is basically saying RUN the container and set the name as "my-apache-php-app.  -p is to set the PORT mapping from our local machine to the port on the container. the left side is our local port, the right side is the port on the container.  Then use -v to set the VOLUME, or... basically bind our present working directory to the /var/www/html folder. This essentially puts the contents of our current directory into the html directory on the container so our code can run inside it. At the end we define the image we build from, which is&lt;strong&gt; php:7.2-apache&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Note that Windows doesn't have a $PWD command, so I had to manually put my path for this to work.&lt;/p&gt;

&lt;p&gt;Okay, so we setup to have our script run on port 80, so go ahead and visit &lt;a rel="noreferrer noopener" href="http://localhost:80"&gt;http://localhost:80&lt;/a&gt; and you should see your script running in the browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftruthseekers.io%2Fwp-content%2Fuploads%2F2020%2F06%2Fimage-21.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftruthseekers.io%2Fwp-content%2Fuploads%2F2020%2F06%2Fimage-21.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;PHP and docker-compose&lt;/h3&gt;

&lt;p&gt;Now let's start moving stuff into a docker-compose file, but first let's stop that container we just created. You can run a &lt;code&gt;docker ps&lt;/code&gt; to get the container id and then run &lt;code&gt;$ docker stop container_id&lt;/code&gt; but I'm just going to stop all containers like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;docker stop $(docker ps -a -q)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now create a &lt;code&gt;docker-compose.yml&lt;/code&gt; file in the root of your project and put the following inside:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;version: '3.1'

services:
  php:
    image: php:7.4-apache
    ports:
      - 80:80
    volumes:
      - ./src:/var/www/html/&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The top line just sets the version number of docker-compose we're using. Then we have the "services" which is the list of containers to setup. We'll be giving this container the name of "php" so other containers can connect via that name. The "image" will be php:7.4-apache  (even though our previous command line experiment used 7.2)&lt;/p&gt;

&lt;p&gt;Then just like in our command line trial we're setting up the PORT mapping from 80 on our local machine to 80 on the container. Finally we'll stuff the contents of our ./src folder into the containers &lt;code&gt;/var/www/html&lt;/code&gt; folder.  Now let's &lt;strong&gt;move our script into the ./src folder&lt;/strong&gt; on our local machine. My project structure now looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftruthseekers.io%2Fwp-content%2Fuploads%2F2020%2F06%2Fimage-22.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftruthseekers.io%2Fwp-content%2Fuploads%2F2020%2F06%2Fimage-22.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now run &lt;code&gt;docker-compose up -d&lt;/code&gt; from inside the project root and visit &lt;a rel="noreferrer noopener" href="http://localhost:80"&gt;localhost:80&lt;/a&gt; and see the script running n the browser. Because we're using volumes to stick our code in the container we should be able to change the script and have it update automatically. Give that a try.&lt;/p&gt;

&lt;p&gt;Now let's shut down our container with &lt;code&gt;docker-compose down&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The next step is to setup &lt;a rel="noreferrer noopener" href="https://hub.docker.com/_/mysql"&gt;MySQL and Adminer (a DB access tool)&lt;/a&gt;  Luckily their docs give us a docker-compose example so we don't have to think as much. We do need to modify the settings a tiny bit though because to connect PHP to MySQL we need to install a few missing pieces to our PHP environment. Here's what our &lt;code&gt;docker-compose.yml&lt;/code&gt; file should look like now:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# Use root/example user/password credentials
version: '3.1'

services:
  php:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 80:80
    volumes:
      - ./src:/var/www/html/

  db:
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Our PHP service looks different because to connect PHP to the database using mysqli we need to install some mysqli stuff. That means we need to use a Dockerfile to customize our php7.4-apache image. So now we're using "build" to use the contents of the current directory (the dot) and using our Dockerfile to create the image. (Dockerfile image code below)&lt;/p&gt;

&lt;p&gt;So now we've added a "db" service which is the mysql image. They use some weird command that has something to do with the password :-) and a restart policy. They also setup an environment variable which sets the root password to "example", so that's how we'll log in.&lt;/p&gt;

&lt;p&gt;Then adminer gets the adminer image and sets that port mapping to 8080:8080.  Just like in XAMPP how you go to localhost/phpmyadmin to get the database management tool, well... with this you go to localhost:8080 to get to the adminer db tool.&lt;/p&gt;

&lt;p&gt;Let's also setup Mysqli to work inside our PHP container. Here's my &lt;strong&gt;Dockerfile code:&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;FROM php:7.4-apache
RUN docker-php-ext-install mysqli&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I know that's a lot of code to process.... So let's take it line-by-line. The first line uses the php:7.4-apache image to build the container. The second line runs a command to install the mysqli extension inside the container. From here we have everything we need to have a super basic PHP development environment. So let's run &lt;code&gt;docker-compose up -d&lt;/code&gt; again.&lt;/p&gt;

&lt;p&gt;Now we should be able access Adminer and log in. I'll just use a few images to speed things up. Just note that the name of the "server" is "db" in our case based on the dockerfile. We could have named it "pie" or anything we wanted.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftruthseekers.io%2Fwp-content%2Fuploads%2F2020%2F06%2Fimage-23.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftruthseekers.io%2Fwp-content%2Fuploads%2F2020%2F06%2Fimage-23.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select "Create Database"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftruthseekers.io%2Fwp-content%2Fuploads%2F2020%2F06%2Fimage-25.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftruthseekers.io%2Fwp-content%2Fuploads%2F2020%2F06%2Fimage-25.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Name it and hit save. I named mine "company1"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftruthseekers.io%2Fwp-content%2Fuploads%2F2020%2F06%2Fimage-26.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftruthseekers.io%2Fwp-content%2Fuploads%2F2020%2F06%2Fimage-26.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then select "new item" to add a few items to your table.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftruthseekers.io%2Fwp-content%2Fuploads%2F2020%2F06%2Fimage-27.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftruthseekers.io%2Fwp-content%2Fuploads%2F2020%2F06%2Fimage-27.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we just need the PHP to connect to our database. This isn't a PHP tutorial so I won't explain it all, but it just connects to our database and runs some queries and prints them on the screen. The important part is the third line that connects MySQL to PHP. &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;?php

echo "Hello from the docker yooooo container";

$mysqli = new mysqli("db", "root", "example", "company1");

$sql = "INSERT INTO users (name, fav_color) VALUES('Lil Sneazy', 'Yellow')";
$result = $mysqli-&amp;gt;query($sql);
$sql = "INSERT INTO users (name, fav_color) VALUES('Nick Jonas', 'Brown')";
$result = $mysqli-&amp;gt;query($sql);
$sql = "INSERT INTO users (name, fav_color) VALUES('Maroon 5', 'Maroon')";
$result = $mysqli-&amp;gt;query($sql);
$sql = "INSERT INTO users (name, fav_color) VALUES('Tommy Baker', '043A2B')";
$result = $mysqli-&amp;gt;query($sql);


$sql = 'SELECT * FROM users';

if ($result = $mysqli-&amp;gt;query($sql)) {
    while ($data = $result-&amp;gt;fetch_object()) {
        $users[] = $data;
    }
}

foreach ($users as $user) {
    echo "&amp;lt;br&amp;gt;";
    echo $user-&amp;gt;name . " " . $user-&amp;gt;fav_color;
    echo "&amp;lt;br&amp;gt;";
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now here is the result of our code when we run it in the browser. :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftruthseekers.io%2Fwp-content%2Fuploads%2F2020%2F06%2Fimage-28.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftruthseekers.io%2Fwp-content%2Fuploads%2F2020%2F06%2Fimage-28.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;Persistent Mysql using Volumes: &lt;/h3&gt;

&lt;p&gt;You're probably not going to build your entire app in one sitting so we'll want to use volumes for persistent data like the stuff inside your database. &lt;strong&gt;Without a volume your data will be erased every time you stop the containers.&lt;/strong&gt; In order to do that you just need to add a few more lines to your code. The code from db: and down will look like this:  (The important lines are at the end of the "db" section where it says volumes, and the VERY end where it says "volumes"&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  db:
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example
    volumes:
      - mysql-data:/var/lib/mysql

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080

volumes:
  mysql-data:
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note the indentation. &lt;strong&gt;volumes will be at the same indentation level as "services"&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I won't go deep into volumes right now. (To be honest I'm no expert yet lol) but in this code we're setting up a volume on our system (managed by docker) called mysql-data. All our database tables and junk gets stored inside the "mysql-data".  Then we map that data to /var/lib/mysql on the container.&lt;/p&gt;

&lt;p&gt;So that's pretty much it y'all. If you want to get in some practice you should try to swap out MySQL for Postgres. Or Apache for Nginx, or try to install some other tools like Composer using the Dockerfile. Please let me know if the article helped or not. Would love some feedback so I can make these better. &lt;/p&gt;

&lt;h4&gt;&lt;a rel="noreferrer noopener" href="https://github.com/truthseekers/php-docker-simple"&gt;Here's the source code &lt;/a&gt;&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://truthseekers.io/latest-tutorials-signup/" rel="noopener noreferrer"&gt;Learn to code with our beginner friendly tutorials&lt;/a&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>php</category>
      <category>devops</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
