<?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: Zachary Alexander</title>
    <description>The latest articles on DEV Community by Zachary Alexander (@zalexander).</description>
    <link>https://dev.to/zalexander</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%2F691268%2F4e6d26de-30ea-49e8-bb97-92cd60e5ee65.jpg</url>
      <title>DEV Community: Zachary Alexander</title>
      <link>https://dev.to/zalexander</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zalexander"/>
    <language>en</language>
    <item>
      <title>How to dockerize the Nuxt3 Beta on AWS?</title>
      <dc:creator>Zachary Alexander</dc:creator>
      <pubDate>Mon, 28 Feb 2022 13:09:18 +0000</pubDate>
      <link>https://dev.to/zalexander/how-to-dockerize-the-nuxt3-beta-on-aws-2964</link>
      <guid>https://dev.to/zalexander/how-to-dockerize-the-nuxt3-beta-on-aws-2964</guid>
      <description>&lt;h1&gt;
  
  
  How to dockerize the Nuxt3 Beta on AWS?
&lt;/h1&gt;

&lt;p&gt;Innovation is rampant in the Nuxt3 ecosystem. Nothing is safe. Everything we know about enterprise-grade web application development is up for grabs. With advances like the Vite bundler and the Nitro server, you could make the case that the entire javascript world stands to benefit. We might as well start exploring this new opportunity space with some low-hanging fruit like a docker container.&lt;/p&gt;

&lt;p&gt;You could make the case that the docker container is the smallest component in modern web development. It is a building block used by more complex technologies like Amazon Elastic Container Service and Amazon Kubernetes Service. Just a heads up, real surprises will present themselves even at this level. For example, there is no dist directory created after the build. Nuxt3 uses a .output folder. Let's get started:&lt;/p&gt;

&lt;h2&gt;
  
  
  What are the Nuxt3 Prerequisites?
&lt;/h2&gt;

&lt;p&gt;You need access to the following:&lt;/p&gt;

&lt;p&gt;– AWS account&lt;/p&gt;

&lt;p&gt;– Node&lt;/p&gt;

&lt;p&gt;– Yarn&lt;/p&gt;

&lt;p&gt;– Git&lt;/p&gt;

&lt;p&gt;– Docker&lt;/p&gt;

&lt;p&gt;– Docker-compose&lt;/p&gt;

&lt;p&gt;– Visual Studio Code&lt;/p&gt;

&lt;h2&gt;
  
  
  How to install Nuxt3?
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx nuxi init &amp;lt;app-name&amp;gt;
&lt;span class="nb"&gt;cd&lt;/span&gt; &amp;lt;app-name&amp;gt;
yarn &lt;span class="nb"&gt;install
&lt;/span&gt;yarn build
code &lt;span class="nb"&gt;.&lt;/span&gt;
yarn dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: I like to run yarn build instead of yarn dev to build out all the directories for git. I run yarn dev to start the dev server.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to install Tailwindcss?
&lt;/h2&gt;

&lt;p&gt;Nuxt3 has caused many web developers to question everything, including how best to do style javascript code. A lot of Nuxt3/Vue developers are moving to Tailwindcss. You could make the case that tailwindcss is true to the single file component philosophy. On the other hand, the tailwindcss step is purely optional.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add tailwindcss
npx tailwind init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: the tailwind init commit will create the tailwind.config.js.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configure tailwind.config.js as such:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;module.exports &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  content: &lt;span class="o"&gt;[&lt;/span&gt;
    &lt;span class="s2"&gt;"./components/**/*.{js,vue,ts}"&lt;/span&gt;,
    &lt;span class="s2"&gt;"./layouts/**/*.vue"&lt;/span&gt;,
    &lt;span class="s2"&gt;"./pages/**/*.vue"&lt;/span&gt;,
    &lt;span class="s2"&gt;"./plugins/**/*.{js,ts}"&lt;/span&gt;,    
  &lt;span class="o"&gt;]&lt;/span&gt;,
  theme: &lt;span class="o"&gt;{&lt;/span&gt;
    extend: &lt;span class="o"&gt;{}&lt;/span&gt;,
  &lt;span class="o"&gt;}&lt;/span&gt;,
  plugins: &lt;span class="o"&gt;[]&lt;/span&gt;,
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create the tailwind.css file.
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; assets/css/ &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;touch &lt;/span&gt;assets/css/tailwind.css
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Configure the tailwind.css as such:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;@tailwind base&lt;span class="p"&gt;;&lt;/span&gt;
@tailwind components&lt;span class="p"&gt;;&lt;/span&gt;
@tailwind utilities&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Add the following to nuxt.config.ts:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;build: &lt;span class="o"&gt;{&lt;/span&gt;
        postcss: &lt;span class="o"&gt;{&lt;/span&gt;
          postcssOptions: &lt;span class="o"&gt;{&lt;/span&gt;
            plugins: &lt;span class="o"&gt;{&lt;/span&gt;
              tailwindcss: &lt;span class="o"&gt;{}&lt;/span&gt;,
              autoprefixer: &lt;span class="o"&gt;{}&lt;/span&gt;,
            &lt;span class="o"&gt;}&lt;/span&gt;,
          &lt;span class="o"&gt;}&lt;/span&gt;,
        &lt;span class="o"&gt;}&lt;/span&gt;,
      &lt;span class="o"&gt;}&lt;/span&gt;,
      css: &lt;span class="o"&gt;[&lt;/span&gt;
        &lt;span class="s2"&gt;"~/assets/css/tailwind.css"&lt;/span&gt;
  &lt;span class="o"&gt;]&lt;/span&gt;,
&lt;span class="o"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Remove app.vue and create /pages/index.vue. index.vue.
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;pages &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;touch &lt;/span&gt;pages/index.vue
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Add content with tailwind styling to index.vue.
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
  &amp;lt;div &lt;span class="nv"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"container mx-auto bg-gray-300 p-8"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &amp;lt;h1 &lt;span class="nv"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"font-bold text-gray-600 text-lg text-center"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;Hello, Tailwind 3!&amp;lt;/h1&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to create our first Nuxt3 container?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Create the Dockerfile
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Dockerfile&lt;/span&gt;
FROM node:16-alpine3.14

&lt;span class="c"&gt;# create destination directory&lt;/span&gt;
RUN &lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; /usr/src/nuxt-app
WORKDIR /usr/src/nuxt-app

&lt;span class="c"&gt;# update and install dependency&lt;/span&gt;
RUN apk update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apk upgrade
RUN apk add git

&lt;span class="c"&gt;# copy the app, note .dockerignore&lt;/span&gt;
COPY package.json &lt;span class="nb"&gt;.&lt;/span&gt;
RUN yarn &lt;span class="nb"&gt;install
&lt;/span&gt;COPY &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="nb"&gt;.&lt;/span&gt;
RUN yarn build

EXPOSE 3000

ENV &lt;span class="nv"&gt;NUXT_HOST&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0.0.0.0
ENV &lt;span class="nv"&gt;NUXT_PORT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3000

CMD &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"yarn"&lt;/span&gt;, &lt;span class="s2"&gt;"start"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Run the docker build command.
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build &lt;span class="nt"&gt;-t&lt;/span&gt; &amp;lt;application name&amp;gt; &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create the docker-compose.yml, then copy the Docterfile to nuxt3.dockerfile so that you can use docker-compose.
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;version: &lt;span class="s1"&gt;'3.9'&lt;/span&gt;

services:
  nuxt3:
    build:
      context: &lt;span class="nb"&gt;.&lt;/span&gt;
      dockerfile: nuxt3.dockerfile
   ports:
      - 3000:3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What is the .dockerignore file and why do we need it?
&lt;/h2&gt;

&lt;p&gt;The time it takes to build an image matters when you're working on a project. And the most time consuming part of this process is the node_modules. The best way to limit that process to include a .dockerignore like the described below.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Touch .dockerignore in the root directory and add the following configuration to the file.
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node_modules
Dockerfile
.git/
.gitignore
.dockerignore
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to add Nuxt3 docker image to AWS Elastic Container Registry
&lt;/h2&gt;

&lt;p&gt;The next stage takes us into the AWS Cloud and removes a lot of the undifferentiated heavy lifting. There are over 200 technology services that we can explore and eventually adopt to improve the scalability of our workflow. So, we will start with the simple docker container you created earlier.&lt;/p&gt;

&lt;h3&gt;
  
  
  Open the AWS Console and navigate to the AWS ECR console. Click the "Create Repository" button. Next, enter the name of the repository you want to create. I entered nuxt3-aws. Make sure the visibility setting is set to private.
&lt;/h3&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fav1a90jtv8hp9s6ps1le.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fav1a90jtv8hp9s6ps1le.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Edit the nuxt3.dockerfile and replace the FROM node entry with the following node URI.
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;account number&amp;gt;.dkr.ecr.&amp;lt;region name&amp;gt;.amazonaws.com/ecr-public/docker/library/node
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Replacing the Node entry will store the docker image in AWS ECR and result in a security enhancement. However, you will incur a cost if you exceed the Free Tier storage limits.&lt;/p&gt;

&lt;h3&gt;
  
  
  Click the Create Repository button at the bottom of the page.
&lt;/h3&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzg30b5ux9flesl4kwoqo.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzg30b5ux9flesl4kwoqo.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Click on the newly created repository. It will open the repository page and show you the view push commands button.
&lt;/h3&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftf83puoo90sxhlthm6xr.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftf83puoo90sxhlthm6xr.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Follow steps 1, 3, and 4. You can run the "docker-compose --build" instead of the docker build command on the command line.
&lt;/h3&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu63klqaxt1w3lwsaf0jm.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu63klqaxt1w3lwsaf0jm.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: You can find the correct container by issuing "docker image ls" from the command line. The image at the top of the screen should be the one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The nuxt3 opportunity space is vast. And nothing can be taken for granted. The journey will be uncomfortable and, at times, painful. With nuxt3 and AWS, we have to rethink how we have always done enterprise software development. The good news is some say that it reminds them of the early days of React. Hopefully, this article will entice you to take a walk on the wild side and check out what Nuxt3 has to offer.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>ecr</category>
      <category>nuxt3</category>
    </item>
    <item>
      <title>Next Gen Remote WordPress Development using Composer and Bedrock</title>
      <dc:creator>Zachary Alexander</dc:creator>
      <pubDate>Thu, 26 Aug 2021 20:19:55 +0000</pubDate>
      <link>https://dev.to/zalexander/next-gen-remote-wordpress-developent-using-composer-and-bedrock-l8i</link>
      <guid>https://dev.to/zalexander/next-gen-remote-wordpress-developent-using-composer-and-bedrock-l8i</guid>
      <description>&lt;p&gt;This post will explore the next generation of WordPress development, which centers around adding an application-level package manager and a modern WordPress tech stack. You could make the case that these are the two things that separate professionals from highly motivated enthusiasts.&lt;/p&gt;

&lt;p&gt;Composer for PHP is the package manager that we are using today. You probably understand the value of controlling your dependencies if you've used npm for javascript or gem for ruby on rails. Knowing exactly which dependency has changed can be invaluable when troubleshooting a problem.&lt;/p&gt;

&lt;p&gt;Bedrock upgrades the tech stack that WordPress comes with out of the box. It improves the directory structure by moving the wp-config.php file from the root directory into the config directory one level-up. It also replaces the standard password encryption with the more secure wp-password-bcrypt.&lt;/p&gt;

&lt;p&gt;A little documented feature of Bedrock is that it strictly enforces a separation between development and production environments. If you try to place a development environment into production, then your SEO will tank. The reason is that all of your content will be tagged with no-follow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;AWS Account (works with free Account)&lt;/li&gt;
&lt;li&gt;VSCode on the local machine&lt;/li&gt;
&lt;li&gt;SSH Client&lt;/li&gt;
&lt;li&gt;SSH Public and Private Key (with a passphrase)&lt;/li&gt;
&lt;li&gt;Some experience installing WordPress&lt;/li&gt;
&lt;li&gt;Some experience with docker-compose&lt;/li&gt;
&lt;li&gt;Some experience launching AWS EC2 Instances&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Launch AWS EC2
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Log in to the AWS Console&lt;/li&gt;
&lt;li&gt;Import the SSH Public Key as the EC2 key pair&lt;/li&gt;
&lt;li&gt;Provision an Amazon Linux 2 AMI&lt;/li&gt;
&lt;li&gt;Increase the storage to 30 GiB&lt;/li&gt;
&lt;li&gt;Choose the public key you imported in step 1.&lt;/li&gt;
&lt;li&gt;Review and Launch&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Setup AWS EC2 docker environment
&lt;/h2&gt;

&lt;p&gt;Run the SSH command from you local machine to log in into the remote EC2 Instance. You can find the address on the EC2 console. You should be prompted by SSH for a passcode once you connect with the site. Enter the following command once you're logged in to the EC2 Instance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;yum update &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;amazon-linux-extras &lt;span class="nb"&gt;install &lt;/span&gt;docker &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;service docker start
&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nt"&gt;-G&lt;/span&gt; docker ec2-user
&lt;span class="nb"&gt;exit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Setup WordPress docker project root
&lt;/h2&gt;

&lt;p&gt;All you need to do to create a new WordPress project is to create a new directory. Your projects shouldn't interfere with each other except for potential physical port conflicts. So feel free to use the following commands to develop multiple WordPress sites on the same EC2 Instance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip3 &lt;span class="nb"&gt;install &lt;/span&gt;docker-compose
&lt;span class="nb"&gt;mkdir &lt;/span&gt;wp-composer-remote-demo
&lt;span class="nb"&gt;cd &lt;/span&gt;wp-wordpress-remote
&lt;span class="nb"&gt;touch &lt;/span&gt;README.md
&lt;span class="nb"&gt;touch &lt;/span&gt;docker-compose.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Install Composer for PHP
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Composer prep
&lt;/h3&gt;

&lt;p&gt;Run the following command in prep for Composer being added to the system. The shared PHP will only be used to install and run Composer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;amazon-linux-extras &lt;span class="nb"&gt;enable &lt;/span&gt;php7.4
&lt;span class="nb"&gt;sudo &lt;/span&gt;yum clean metadata
&lt;span class="nb"&gt;sudo &lt;/span&gt;yum &lt;span class="nb"&gt;install &lt;/span&gt;php-cli php-pdo php-fpm php-json php-mysqlnd &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;yum &lt;span class="nt"&gt;-y&lt;/span&gt; &lt;span class="nb"&gt;install &lt;/span&gt;php-xml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: You can find instructions oh how to add Composer as a service. However, I think that it clutters up the docker-compose.yml file.&lt;/p&gt;

&lt;h3&gt;
  
  
  Follow Install Instructions on the Composer for PHP Website
&lt;/h3&gt;

&lt;p&gt;Open a brower window to &lt;a href="https://getcomposer.org/download/"&gt;Composer PHP Download&lt;/a&gt;. Composer PHP is regularly updated and the installation hash changes when it's updated. Per the maintainers request, we won't distribute the instructions here.&lt;/p&gt;

&lt;h3&gt;
  
  
  Set up the Bedrock directory structure
&lt;/h3&gt;

&lt;p&gt;Run the following comands to working directory for WordPress development. You could the case that this is where you start to create a more professional WordPress website. So, run the commands and brace yourself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer create-project roots/bedrock
&lt;span class="nb"&gt;cd &lt;/span&gt;bedrock
composer update
&lt;span class="nb"&gt;cd&lt;/span&gt; ..
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Composer uses the package.json to manage dependencies. So, if you want to update a package you make the change there, then run composer update. If the file is available from Packagist.org then it will install the file for you. &lt;a href="https://packagist.org/"&gt;Checkout Packagist.org&lt;/a&gt; for more complete instructions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configure the AWS-ClI
&lt;/h3&gt;

&lt;p&gt;Run "aws configure" is something I like to do in preparation for installing and configuring git. The reason is because you really want to use the credential.helper so that you won't have to enter the user name and password every time you want to do a git push. You'll have to answer the following questions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Answer the questions:
AWS Access Key ID &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="k"&gt;****************&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;:
AWS Secret Access Key &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="k"&gt;****************&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;:
Default region name &lt;span class="o"&gt;[&lt;/span&gt;us-east-2]:
Default output format &lt;span class="o"&gt;[&lt;/span&gt;json]:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Install Git
&lt;/h3&gt;

&lt;p&gt;It's best to set up git and .gitignore as early as possible when starting a new project. There are two directories that you will most likely want to ignore right away: ./bedrock and ./mysql. I like to start by copying the .gitignore in the bedrock directory. Eventually, you'll want to ignore the nginx/certs directory.&lt;/p&gt;

&lt;p&gt;Once again, you should check the internet or YouTube for examples and more detailed instructions. You can also ignore the git step all together however it is not best practice.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;yum &lt;span class="nb"&gt;install &lt;/span&gt;git &lt;span class="nt"&gt;-y&lt;/span&gt;
git init
git config &lt;span class="nt"&gt;--global&lt;/span&gt; credential.helper &lt;span class="s1"&gt;'!aws codecommit credential-helper $@'&lt;/span&gt;
git config &lt;span class="nt"&gt;--global&lt;/span&gt; credential.UseHttpPath &lt;span class="nb"&gt;true
touch&lt;/span&gt; .gitignore
git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"initial commit"&lt;/span&gt;
git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's switch to the terminal in VSCode and set up the docker-composer.yml to run NGNIX. You can look at my previous article on remote development with VSCode if you are unsure. Technically, you don't need the mysql service to run NGINX. However, it's nice to have all of the Docker containers run without complaining.&lt;/p&gt;

&lt;p&gt;Copy the following config in the docker-compose.yml file, then update the EC2 security group to permit HTTP traffic on port 80. Finally, run "docker-compose up". This will run all the docker containers. Do a "control-c" to stop or escape the docker-compose process.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-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.9'&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;nginx&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;nginx:stable-alpine&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="s"&gt;80:80&lt;/span&gt;
  &lt;span class="na"&gt;mysql&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.34&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_DATABASE&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;wp&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;wp&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;secret&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;secret&lt;/span&gt;
  &lt;span class="na"&gt;php&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;php:7.4-fpm-alpine&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create Self-Signed Cert
&lt;/h2&gt;

&lt;p&gt;Eventually, you may want to encrypt information in transit. So, we will give you the SSL encryption information now so you won't have to fuss with the NGINX server again.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use OpenSSL to create a self-signed cert and key
&lt;/h3&gt;

&lt;p&gt;Run the following command in the project root. You will create both a .crt file and a key file in the nginx/certs directory. Unfortunately, the site will show up as "Not Secure" even though you're using SSL. You can fix that in production.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; nginx/certs &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cd &lt;/span&gt;nginx/certs
openssl req &lt;span class="nt"&gt;-newkey&lt;/span&gt; rsa:4096 &lt;span class="nt"&gt;-x509&lt;/span&gt; &lt;span class="nt"&gt;-sha256&lt;/span&gt; &lt;span class="nt"&gt;-days&lt;/span&gt; 365 &lt;span class="nt"&gt;-nodes&lt;/span&gt; &lt;span class="nt"&gt;-out&lt;/span&gt; &amp;lt;Public DNS Address&amp;gt;.crt &lt;span class="nt"&gt;-keyout&lt;/span&gt; &amp;lt;Public DNS Address&amp;gt;.key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Configure Self-signed SSL Cert and key
&lt;/h3&gt;

&lt;p&gt;Next, we are going to set up the nginx.dockerfile and nginx/default.conf.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; &amp;lt;project root&amp;gt;
&lt;span class="nb"&gt;touch &lt;/span&gt;nginx.dockerfile
&lt;span class="nb"&gt;touch &lt;/span&gt;nginx/default.conf 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following configuration to the nginx.dockerfile. The configure changes will update the base container.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;FROM nginx:stable-alpine
ADD ./nginx/certs /etc/nginx/certs/self-signed
ADD ./nginx/default.conf /etc/nginx/conf.d/default.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following configuration to the nginx/default.conf file. The default.conf file changes the root director to /var/www/html/bedrock/web. And configures the Self-Signed SSL cert and key.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;upstream php &lt;span class="o"&gt;{&lt;/span&gt;
    server unix:/tmp/php-cgi.socket&lt;span class="p"&gt;;&lt;/span&gt;
    server php:9000&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

server &lt;span class="o"&gt;{&lt;/span&gt;
    listen 80&lt;span class="p"&gt;;&lt;/span&gt;
    listen &lt;span class="o"&gt;[&lt;/span&gt;::]:80&lt;span class="p"&gt;;&lt;/span&gt;
    server_name &amp;lt;Public DNS Address&amp;gt; &amp;lt;Public IPv4 Address&amp;gt;&lt;span class="p"&gt;;&lt;/span&gt;

    root /var/www/html/bedrock/web&lt;span class="p"&gt;;&lt;/span&gt;
    index index.html index.php&lt;span class="p"&gt;;&lt;/span&gt;
    location / &lt;span class="o"&gt;{&lt;/span&gt;
        try_files &lt;span class="nv"&gt;$uri&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt;/ /index.php&lt;span class="nv"&gt;$args&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      

    &lt;span class="o"&gt;}&lt;/span&gt;

    location ~ &lt;span class="se"&gt;\.&lt;/span&gt;php&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
        include fastcgi.conf&lt;span class="p"&gt;;&lt;/span&gt;
        fastcgi_intercept_errors on&lt;span class="p"&gt;;&lt;/span&gt;
        fastcgi_pass php&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
server &lt;span class="o"&gt;{&lt;/span&gt;
    listen 443 ssl&lt;span class="p"&gt;;&lt;/span&gt;
    listen &lt;span class="o"&gt;[&lt;/span&gt;::]:443&lt;span class="p"&gt;;&lt;/span&gt;
    server_name &amp;lt;Public DNS Address&amp;gt; &amp;lt;Public IPv4 Address&amp;gt;&lt;span class="p"&gt;;&lt;/span&gt;

    root /var/www/html/bedrock/web&lt;span class="p"&gt;;&lt;/span&gt;
    index index.html index.php&lt;span class="p"&gt;;&lt;/span&gt;
    location / &lt;span class="o"&gt;{&lt;/span&gt;
        try_files &lt;span class="nv"&gt;$uri&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt;/ /index.php&lt;span class="nv"&gt;$args&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      

    &lt;span class="o"&gt;}&lt;/span&gt;

    location ~ &lt;span class="se"&gt;\.&lt;/span&gt;php&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
        include fastcgi.conf&lt;span class="p"&gt;;&lt;/span&gt;
        fastcgi_intercept_errors on&lt;span class="p"&gt;;&lt;/span&gt;
        fastcgi_pass php&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    ssl_certificate /etc/nginx/certs/self-signed/&amp;lt;Public DNS Address&amp;gt;.crt&lt;span class="p"&gt;;&lt;/span&gt;
    ssl_certificate_key /etc/nginx/certs/self-signed/&amp;lt;Public DNS Address&amp;gt;.key&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we'll update the docker-compose.yml and the security group so that it will support SSL.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-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.9'&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;nginx&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;context&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;.&lt;/span&gt;
      &lt;span class="na"&gt;dockerfile&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx.dockerfile&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="s"&gt;80:80&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;443:443&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;./bedrock:/var/www/html/bedrock&lt;/span&gt;
  &lt;span class="na"&gt;mysql&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.34&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_DATABASE&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;wp&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;wp&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;secret&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;secret&lt;/span&gt;
  &lt;span class="na"&gt;php&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;php:7.4-fpm-alpine&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;./bedrock:/var/www/html/bedrock&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: You'll get an error because the PHP Service can't talk with MySql. However, you'll see that the server is using SSL.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's get WordPress working
&lt;/h2&gt;

&lt;p&gt;We are going to do a couple of things with the next set of changes. First, we are going to enable MySql support. We are going to add support for the wp-cli. Finally, we are going to pick a user to make updating the WordPress website easy.&lt;/p&gt;

&lt;p&gt;So, "touch php.dockerfile" and add the following configuration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
FROM php:7.4-fpm-alpine
RUN docker-php-ext-install mysqli pdo pdo_mysql &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; docker-php-ext-enable pdo_mysql
RUN curl &lt;span class="nt"&gt;-O&lt;/span&gt; https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
RUN &lt;span class="nb"&gt;chmod&lt;/span&gt; +x wp-cli.phar
RUN &lt;span class="nb"&gt;mv &lt;/span&gt;wp-cli.phar /usr/local/bin/wp
&lt;span class="c"&gt;# add docker user&lt;/span&gt;
ARG &lt;span class="nv"&gt;USER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;docker
ARG &lt;span class="nv"&gt;UID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1000
ARG &lt;span class="nv"&gt;GID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1000
&lt;span class="c"&gt;# Setup default user, when enter docker container&lt;/span&gt;
USER &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;UID&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;:&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GID&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
WORKDIR /var/www/html/bedrock
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update the docker-compose.yml file to build the PHP service.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;php&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;context&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;.&lt;/span&gt;
    &lt;span class="na"&gt;dockerfile&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;php.dockerfile&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;./bedrock:/var/www/html/bedrock&lt;/span&gt;
&lt;span class="na"&gt;wp&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;context&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;.&lt;/span&gt;
    &lt;span class="na"&gt;dockerfile&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;php.dockerfile&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;./bedrock:/var/www/html/bedrock&lt;/span&gt;
  &lt;span class="na"&gt;entrypoint&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;wp'&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;--allow-root'&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update the bedrock/.env file with environment varibles from the docker-compose.yml file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;DB_NAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'wp'&lt;/span&gt;
&lt;span class="nv"&gt;DB_USER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'wp'&lt;/span&gt;
&lt;span class="nv"&gt;DB_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'secret'&lt;/span&gt;

&lt;span class="c"&gt;# Optionally, you can use a data source name (DSN)&lt;/span&gt;
&lt;span class="c"&gt;# When using a DSN, you can remove the DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST variables&lt;/span&gt;
&lt;span class="c"&gt;# DATABASE_URL='mysql://database_user:database_password@database_host:database_port/database_name'&lt;/span&gt;

&lt;span class="c"&gt;# Optional database variables&lt;/span&gt;
&lt;span class="nv"&gt;DB_HOST&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'mysql'&lt;/span&gt;
&lt;span class="c"&gt;# DB_PREFIX='wp_'&lt;/span&gt;

&lt;span class="nv"&gt;WP_ENV&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'development'&lt;/span&gt;
&lt;span class="nv"&gt;WP_HOME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'https://&amp;lt;Public DNS Address&amp;gt;'&lt;/span&gt;
&lt;span class="nv"&gt;WP_SITEURL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;WP_HOME&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/wp"&lt;/span&gt;

&lt;span class="c"&gt;# Specify optional debug.log path&lt;/span&gt;
&lt;span class="c"&gt;# WP_DEBUG_LOG='/path/to/debug.log'&lt;/span&gt;

&lt;span class="c"&gt;# Generate your keys here: https://roots.io/salts.html&lt;/span&gt;
&lt;span class="nv"&gt;AUTH_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'generateme'&lt;/span&gt;
&lt;span class="nv"&gt;SECURE_AUTH_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'generateme'&lt;/span&gt;
&lt;span class="nv"&gt;LOGGED_IN_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'generateme'&lt;/span&gt;
&lt;span class="nv"&gt;NONCE_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'generateme'&lt;/span&gt;
&lt;span class="nv"&gt;AUTH_SALT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'generateme'&lt;/span&gt;
&lt;span class="nv"&gt;SECURE_AUTH_SALT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'generateme'&lt;/span&gt;
&lt;span class="nv"&gt;LOGGED_IN_SALT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'generateme'&lt;/span&gt;
&lt;span class="nv"&gt;NONCE_SALT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'generateme'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run "docker-compose up --build" and answer the install questions as you normally would for WordPress.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's make the MySql Database persistent
&lt;/h2&gt;

&lt;p&gt;The containers are destroyed everytime the docker-compose process is stopped. That means any information that is not written to disk for contained within the docker-container is also destroyed. So, we need to fix this so that data will persist beyound each cycling of docker-compose up or "cntl c".&lt;/p&gt;

&lt;h3&gt;
  
  
  Create mysql.dockerfile
&lt;/h3&gt;

&lt;p&gt;Do a "control-c" to bring down the containers. Run the following commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;mysql
&lt;span class="nb"&gt;touch &lt;/span&gt;mysql.dockerfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy the following configuration into the mysql.dockerfile&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;FROM mysql:5.7.34
&lt;span class="c"&gt;# add docker user&lt;/span&gt;
ARG &lt;span class="nv"&gt;USER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;docker
ARG &lt;span class="nv"&gt;UID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1000
ARG &lt;span class="nv"&gt;GID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1000
ENV &lt;span class="nv"&gt;MYSQL_DATABASE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;wp
ENV &lt;span class="nv"&gt;MYSQL_USER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;wp
ENV &lt;span class="nv"&gt;MYSQL_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;secret
ENV &lt;span class="nv"&gt;MYSQL_ROOT_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;secret
&lt;span class="c"&gt;# add docker user&lt;/span&gt;
&lt;span class="c"&gt;#USER ${UID}:${GID}&lt;/span&gt;
&lt;span class="c"&gt;#WORKDIR /var/lib/mysql&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update bedrock/config/environments/development.php by adding the following section. The development.php and staging.php, and eventually production.php are like the wp-config.php. The only difference is that every statement like "define" is preceded by "Config::" in the section.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cd"&gt;/** Set up'direct method for wordpress, auto update with ftp */&lt;/span&gt;
&lt;span class="nc"&gt;Config&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nb"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'FS_METHOD'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'direct'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update the docker-compose.yml to reflect the mysql.dockerfile build process.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;mysql&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;context&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;.&lt;/span&gt;
      &lt;span class="na"&gt;dockerfile&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;mysql.dockerfile&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;./mysql:/var/lib/mysql&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bring down the docker-compose with "control-c" and look at the mysql directory. It will show that it is owned by 999:ec2-user. Let's fix that. Uncomment the add docker user section.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo chown&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; ec2-user:ec2-user mysql
docker-compose up &lt;span class="nt"&gt;--build&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How to use the wp-cli functionality
&lt;/h3&gt;

&lt;p&gt;First, I like to create a bedrock/src folder. You can place commercial 3rd party themes and plugins in this folder. Next, you can start running wp-cli commands, including installing and updating commercial 3rd party themes and plugins.&lt;/p&gt;

&lt;p&gt;One of the reasons you would want to use the wp-cli is the file sizes of third-party commercial plugins and themes. You will have to fuss with the php.ini max_file_uploads parameter. Try the following set of commands just to get started:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker-compose up &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--build&lt;/span&gt;
docker-compose run &lt;span class="nt"&gt;--rm&lt;/span&gt; wp plugin list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congratulations, you're ready to start developing WordPress using VSCode on remote EC2 instances. It's been a long journey. And I want to thank you for finishing it with me. The good news is that you now have a git repository that you can use to create new baselines.&lt;/p&gt;

</description>
      <category>composer</category>
      <category>docker</category>
      <category>bedrock</category>
      <category>wordpress</category>
    </item>
    <item>
      <title>Remote WordPress Dev using VSCode and docker on AWS EC2</title>
      <dc:creator>Zachary Alexander</dc:creator>
      <pubDate>Mon, 23 Aug 2021 17:28:44 +0000</pubDate>
      <link>https://dev.to/aws-builders/remote-wordpress-dev-using-vscode-and-docker-on-aws-ec2-381m</link>
      <guid>https://dev.to/aws-builders/remote-wordpress-dev-using-vscode-and-docker-on-aws-ec2-381m</guid>
      <description>&lt;p&gt;There are a lot of reasons for developing on AWS EC2. You may want to delay the purchase of a new laptop. You may want to develop in the environment where you will eventually deploy your WordPress site. You may like being able to add additional resources as your project grows in scope and complexity.&lt;/p&gt;

&lt;p&gt;Likewise, there are a lot of reasons to develop your project on top of WordPress. You may want to take advantage of the existing plugins or themes.  You may be starting a re-platforming effort. You may want to containerize your current WordPress application. You may want to make it more scalable.&lt;/p&gt;

&lt;p&gt;There is generally only one reason to develop remotely using VSCode. It's what you've come to expect for your programming experience. Today, we are going to work through what it takes to set up a remote development environment using VSCode and standard AWS Linux 2 EC2 instance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;AWS Account (works with free Account)&lt;/li&gt;
&lt;li&gt;VSCode on the local machine&lt;/li&gt;
&lt;li&gt;SSH Client&lt;/li&gt;
&lt;li&gt;SSH Public and Private Key (with a passphrase)&lt;/li&gt;
&lt;li&gt;Some experience installing WordPress&lt;/li&gt;
&lt;li&gt;Some experience with docker-compose&lt;/li&gt;
&lt;li&gt;Some experience launching AWS EC2 Instances&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Launch AWS EC2
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Log in to the AWS Console&lt;/li&gt;
&lt;li&gt;Import the SSH Public Key as the EC2 key pair&lt;/li&gt;
&lt;li&gt;Provision an Amazon Linux 2 AMI&lt;/li&gt;
&lt;li&gt;Increase the storage to 30 GiB&lt;/li&gt;
&lt;li&gt;Choose the public key you imported in step 1.&lt;/li&gt;
&lt;li&gt;Review and Launch&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Setup AWS EC2 docker environment
&lt;/h2&gt;

&lt;p&gt;Run the SSH command to log in into the remote EC2 Instance. You can find the address on the EC2 console. You should be prompted by SSH for a passcode.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;yum update &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;amazon-linux-extras &lt;span class="nb"&gt;install &lt;/span&gt;docker &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;service docker start
&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nt"&gt;-G&lt;/span&gt; docker ec2-user
&lt;span class="nb"&gt;exit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Setup WordPress docker environment
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip3 &lt;span class="nb"&gt;install &lt;/span&gt;docker-compose
&lt;span class="nb"&gt;mkdir &lt;/span&gt;wp-wordpress-remote
&lt;span class="nb"&gt;cd &lt;/span&gt;wp-wordpress-remote
&lt;span class="nb"&gt;touch &lt;/span&gt;README.md
&lt;span class="nb"&gt;touch &lt;/span&gt;docker-compose.yml
wget https://wordpress.org/latest.tar.gz
&lt;span class="nb"&gt;tar&lt;/span&gt; &lt;span class="nt"&gt;-xzvf&lt;/span&gt; latest.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Configure the AWS-ClI
&lt;/h3&gt;

&lt;p&gt;Enter "aws configure" and answer the questions that following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Answer the questions:
AWS Access Key ID &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="k"&gt;****************&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;:
AWS Secret Access Key &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="k"&gt;****************&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;:
Default region name &lt;span class="o"&gt;[&lt;/span&gt;us-east-2]:
Default output format &lt;span class="o"&gt;[&lt;/span&gt;json]:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  VSCode Setup
&lt;/h3&gt;

&lt;p&gt;I'm going to add the steps needed to set up VSCode for remote development. However, I am not going to take a lot of time with it. Check the internet or YouTube for more detailed instructions.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install Remote Development VSCode Package&lt;/li&gt;
&lt;li&gt;Remote-SSH: Add NEW SSH HOST&lt;/li&gt;
&lt;li&gt;Enter SSH Command&lt;/li&gt;
&lt;li&gt;Select Configuration File Update&lt;/li&gt;
&lt;li&gt;Click the green box in the lower left-hand corner&lt;/li&gt;
&lt;li&gt;Select alias or the name you chose for the connection.&lt;/li&gt;
&lt;li&gt;Click on file explore, should read you are connected to remote host&lt;/li&gt;
&lt;li&gt;Install Docker Extension Pack for VSCode&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note: If you can't make the connection, make sure that the absolute path to the private key is defined properly in the SSH Config file that you selected.&lt;/p&gt;

&lt;h3&gt;
  
  
  Install Git
&lt;/h3&gt;

&lt;p&gt;It's best to setup git and .gitignore as early as possible when starting a new project. There are two directories that you will most likely want to ignore right away: ./wordpress and ./mysql. Once again, you should check the internet or YouTube for examples and more detailed instructions. You can also ignore the git step all together however it is not best practice.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;yum &lt;span class="nb"&gt;install &lt;/span&gt;git &lt;span class="nt"&gt;-y&lt;/span&gt;
git init
git config &lt;span class="nt"&gt;--global&lt;/span&gt; credential.helper &lt;span class="s1"&gt;'!aws codecommit credential-helper $@'&lt;/span&gt;
git config &lt;span class="nt"&gt;--global&lt;/span&gt; credential.UseHttpPath &lt;span class="nb"&gt;true
touch&lt;/span&gt; .gitignore
git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"initial commit"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Setup CodeCommit Repository
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Login to AWS CodeCommit Console&lt;/li&gt;
&lt;li&gt;Create a CodeCommit Repository&lt;/li&gt;
&lt;li&gt;Copy the clone URL need it later
Note: don't put anything into the repository from the console.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Push content into repo
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; main
git remote add origin &amp;lt;HTTPS Clone URL&amp;gt;
git push &lt;span class="nt"&gt;--set-upstream&lt;/span&gt; origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configure NGINX
&lt;/h2&gt;

&lt;p&gt;In this step, we are going to configure the NGINX web server. And update the security group for our EC2 Instance so that it is publically visible.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-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.9'&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;nginx&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;nginx:stable-alpine&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="s"&gt;80:80&lt;/span&gt;
  &lt;span class="na"&gt;mysql&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.34&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_DATABASE&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;wp&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;wp&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;secret&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;secret&lt;/span&gt;
  &lt;span class="na"&gt;php&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;php:7.4-fpm-alpine&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run "docker-compose up" to start the container processes. You can run "ctrl c" to bring down the containers once you've checked that you can get to the NGINX server on the EC2 instance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure WordPress
&lt;/h2&gt;

&lt;p&gt;Let's customize our php service so that it will recognize WordPress. Create the nginx directory in the project root directory. Change into that directory and touch the default.conf file. Add the following configuration to the default.conf&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;upstream php &lt;span class="o"&gt;{&lt;/span&gt;
    server unix:/tmp/php-cgi.socket&lt;span class="p"&gt;;&lt;/span&gt;
    server php:9000&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

server &lt;span class="o"&gt;{&lt;/span&gt;
    listen 80&lt;span class="p"&gt;;&lt;/span&gt;
    listen &lt;span class="o"&gt;[&lt;/span&gt;::]:80&lt;span class="p"&gt;;&lt;/span&gt;
    server_name &amp;lt;Public DNS address&amp;gt; &amp;lt;Public IPv4 address&amp;gt;&lt;span class="p"&gt;;&lt;/span&gt;

    root /var/www/html&lt;span class="p"&gt;;&lt;/span&gt;
    index index.html index.php&lt;span class="p"&gt;;&lt;/span&gt;
    location / &lt;span class="o"&gt;{&lt;/span&gt;
        try_files &lt;span class="nv"&gt;$uri&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt;/ /index.php&lt;span class="nv"&gt;$args&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      

    &lt;span class="o"&gt;}&lt;/span&gt;

    location ~ &lt;span class="se"&gt;\.&lt;/span&gt;php&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
        include fastcgi.conf&lt;span class="p"&gt;;&lt;/span&gt;
        fastcgi_intercept_errors on&lt;span class="p"&gt;;&lt;/span&gt;
        fastcgi_pass php&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the project root directory, touch php.dockerfile. Next, add the following configuration to the php.dockerfile file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;FROM php:7.4-fpm-alpine
RUN docker-php-ext-install mysqli pdo pdo_mysql &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; docker-php-ext-enable pdo_mysql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update the docker-compose.yml file with the following configuration. The configuration removes image in the php service and replaces it with the build section.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-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.9'&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;nginx&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;context&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;.&lt;/span&gt;
      &lt;span class="na"&gt;dockerfile&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx.dockerfile&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="s"&gt;80:80&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;./wordpress:/var/www/html&lt;/span&gt;
  &lt;span class="na"&gt;mysql&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.34&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_DATABASE&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;wp&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;wp&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;secret&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;secret&lt;/span&gt;    
  &lt;span class="na"&gt;php&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;context&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;.&lt;/span&gt;
      &lt;span class="na"&gt;dockerfile&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;php.dockerfile&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;./wordpress:/var/www/html&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run "docker-compose up --build" It will ask you to create the wp-config.php.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create the wp-config.php
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;touch wordpress/wp-config.php&lt;/li&gt;
&lt;li&gt;copy the contents of the infobox to wp-config.php&lt;/li&gt;
&lt;li&gt;add the following code to wp-config.php in front of the no editing after this.&lt;/li&gt;
&lt;li&gt;run "docker-compose up --build"
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cd"&gt;/** Set up'direct method for wordpress, auto update with ftp */&lt;/span&gt;
&lt;span class="nb"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'FS_METHOD'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'direct'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: You will fill out the WordPress configuration as you would normally. However. where it says database host enter "mysql".&lt;/p&gt;

&lt;h2&gt;
  
  
  Persist the mysql database
&lt;/h2&gt;

&lt;p&gt;Doing this will remove the need to redo the WordPress configuration everytime you bring the containers up and down. Touch the mysql.dockerfile file in the project root directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;FROM mysql:5.7.34&lt;/span&gt;
&lt;span class="c1"&gt;# add docker user&lt;/span&gt;
&lt;span class="s"&gt;ARG USER=docker&lt;/span&gt;
&lt;span class="s"&gt;ARG UID=1000&lt;/span&gt;
&lt;span class="s"&gt;ARG GID=1000&lt;/span&gt;
&lt;span class="s"&gt;ENV MYSQL_DATABASE=wp&lt;/span&gt;
&lt;span class="s"&gt;ENV MYSQL_USER=wp&lt;/span&gt;
&lt;span class="s"&gt;ENV MYSQL_PASSWORD=secret&lt;/span&gt;
&lt;span class="s"&gt;ENV MYSQL_ROOT_PASSWORD=secret&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remove the image and the build section to the mysql service.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;mysql&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;context&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;.&lt;/span&gt;
      &lt;span class="na"&gt;dockerfile&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;mysql.dockerfile&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;./mysql:/var/lib/mysql&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: You may to bring it up and down a couple of times to get the permissions right. When you bring down the containers check the mysql directory and make sure that it is owned by ec2-user:ec2-user. If not run "sudo chown -R ec2-user:ec2-user mysql" before runnning "docker-compose up --build".&lt;/p&gt;

&lt;h2&gt;
  
  
  Fix WordPress file  permissions
&lt;/h2&gt;

&lt;p&gt;You can add blog posts to your website at this point. However, you may not be able to add plugins or images. If that's the case, you need first to run the following set of commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ./wordpress
&lt;span class="nb"&gt;sudo &lt;/span&gt;g+w wp-content
&lt;span class="nb"&gt;cd &lt;/span&gt;wp-content
&lt;span class="nb"&gt;sudo &lt;/span&gt;g+w wp-themes
&lt;span class="nb"&gt;sudo &lt;/span&gt;g+w wp-plugins
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, you need to update the php.dockerfile with these changes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# add docker user&lt;/span&gt;
ARG &lt;span class="nv"&gt;USER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;docker
ARG &lt;span class="nv"&gt;UID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1000
ARG &lt;span class="nv"&gt;GID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1000
USER &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;UID&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;:&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GID&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
WORKDIR /home/&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;USER&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congratulations, you're ready to start developing WordPress using VSCode on remote EC2 instances.&lt;/p&gt;

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