Docker and WordPress

Docker and WordPress

It’s time to build on our Docker knowledge. WordPress is a powerful web platform that a large part of the internet is built on. This site is built on WordPress. Whenever I am working on a site for a friend, I will build myself WordPress and then create their site there in my test environment. When I get it the way I want it, I move it and destroy the original. The best way to destroy the original is to wipe it from existence. This is where Docker and WordPress are friends.

Docker and WordPress

This method will allow you to have multiple WordPress sites with your docker image. The reason we want to be able to do this is because this allows us to test between site actions and more. It’s one of those amazing little tools that saves so much time. Before that, we want to do some basic things to get everything setup. The first thing is the networking. We want to build a network in docker for our WordPress sites. We do this outside of the compose because making if/then statements in a compose is a mess. This also allows you to have multiple networks and so on and so forth. We do this with the command “Docker Network Create”. Of course, you want to be using the docker user or sudo user.

docker network create dockerwp

Docker Compose File

Now we have our docker network built, we need to build our compose file. Inside the folder you keep all of your dockers, I Suggest making a new folder called wordpress and moving into that folder. Then create a docker-compose file using the nano command.

mkdir wordpress
cd wordpress
nano docker-compose.yml

Next you will want to copy and past the docker compose below into it.

version: "3.8"

services:
  sitename-db:
    image: mysql:latest
    volumes:
      - ./sitename_db/data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: AmazingPasswordOfAwesomeness
      MYSQL_DATABASE: sitename_wp_db
      MYSQL_USER: sitename_wp_user
      MYSQL_PASSWORD: AnotherAmazingPassword

  sitename-wp:
    image: wordpress:latest
    depends_on:
      - site1-db
    volumes:
      - ./sitename_wp/wp-content:/var/www/html/wp-content
      - ./sitename_wp/uploads.ini:/user/local/etc/php/conf.d/uploads.ini
      # Add other files or folders that you want to override here e.g. stylesheets
    ports:
      - "8880:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: sitename-db:3306
      WORDPRESS_DB_NAME: sitename_wp_db
      WORDPRESS_DB_USER: sitename_wp_user
      WORDPRESS_DB_PASSWORD: AnotherAmazingPassword

networks:
	dockerwp:
	  name: dockerwp
	  external: true

From there, you can run the command “docker compose up -d” to create the wordpress page with the default settings. I don’t suggest it, but you can. How can you use this docker compose? Firstly, replace wherever you see “sitename” with the sites name you want. If you want more than one, you can copy the db and wordpress sections over and over again. Each time replacing the site name with something different. Make sure to change those amazing passwords.

How does this compose work?

This docker compose works by creating individual worlds for each site. The word sitename allows you to rename everything the way you want. So if you wanted therandomadmin_com-db, that can happen. if you want therandomadmin_org-db that can happen to. Each one can have it’s own name. This is what splits them apart. The network they share allows them to talk with each other and back out again. Uploads.ini allows the sites to have their own custom upload counts. I will go over that in just a minute. Just imagine them as little cups with two unique coins. As long as they are named the same they can talk to each other. If you wanted to, you can take it a step farther and make a new network for each compose. However, that can get messy quick trying to herd all of those networks into one place.

Next steps

The volumes part of the compose services creates folders. Each folder is important because it holds the content for that container. Notice in the wordpress volumes. You will see a ./sitename_wp/uploads.ini. This is very important as it controls how much data can be uploaded. Each site has it’s own. Thus, you can use the command below to create a simple file in each container. To activate those files, restart the container.

printf "file_uploads = On\nmemory_limit = 64M\nupload_max_filesize = 64M\npost_max_size = 64M\nmax_execution_time = 600" > ~/uploads.ini

This command will create the ini file that tells the system how much you can upload. I have it set to 64 megabtyes, but you can set it to whatever you want. By default, the size limitation is 2mb. Which is extremely small for now day images.

Finally, you can use the nginx reverse proxy system to assign the ssl to each site as you see fit. I personally don’t do this as I don’t expose the site to the outside world, but you can do so. The instructions were covered in the previous blog about ladder. Believe it or not, that’s it. The next few steps would be to go to the site’s ip or hostname whichever you choose and set up your wordpress like normal.

What can we learn as a person today?

Recently I went to a Tech networking event where I met multiple new and unique people. I enjoyed every minute of talking about tech with each of them. While talking to them, I learned of new ways to use my dormant skills. Things like body language, mental health knowledge, and even down to my cooking was improved. We talked about things like IT, AI, and the color of the sky in some cases. It was a pleasure. Later I was the one helping others on a local discord server. We talked about the day and things we needed.

What spoke to me while working on this blog post was each WordPress has it’s own container and it’s own world, but the network is the same. This allows the WordPress installs to talk with each other and share items easliy. That’s the same way we are as humans. We are all unique in our own ways. I can be someone who enjoys reading a good white paper about mind bind while someone else can enjoy reading a good book at how pepsi cola is made. We are all different. What we have in common is our networks.

Without our networks, we can’t go far. Imagine the WordPress hosted on it’s own network, but that network can’t leave your lab. Would it be useful to the outside world? How about this site? What if I locked it down so only 1 other IP address could read it. This blog wouldn’t be helpful to you. This is how our networking is. If we lock down ourselves to only one group of people, we can’t grow and they can’t grow. This is often times how cults are made. They lock themselves down to only themselves and whoever they can recruit.

Think about it

As you go throughout your week this week, think about your networks. If you go to church, that’s a network, if you go to school, that’s a network. How about your discord friends? That’s a network as well. Each place has it’s own network, even if that place is temporary like a store. What can you bring to those networks, and what can you learn from those networks?

WordPress for Free

WordPress for Free

Today’s post is a formula that you can use to get a decent server and install WordPress on it. This is the setup for this site, and it works like magic. This is a self-hosted WordPress for free.

Oracle Always Free Teir

Oracle offers an always free tier for servers. This is an arm server and it does wonders. 8 Cores and 24 gb of ram with up to 200 GB of storage. This thing is a beast for a free server. For more information, you can visit their site: https://docs.oracle.com/en/learn/cloud_free_tier/index.html

When you create your compute, make sure you stay within the always free unless you are willing to pay for more. Also, select the Ubuntu server as this is the easiest way to build your server.

Make sure to download your SSL cert or you will not be able to later.

LAMP stack

The next phase for your Free WordPress site is building out a lamp stack. Lamp means Linux, Apache, Mysql, and PHP. With this stack, you can run almost any site. I’m going to refer you to digital oceans for this part, as they have an amazing tutorial for just this. https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-22-04.

Quick Catch

The Oracle always free tier users iptables. Here is a good forum post on how to disable iptables. https://serverfault.com/questions/129086/how-to-start-stop-iptables-on-ubuntu.

Another Quick catch is you must open the ports in the firewall of your compute on the main page. Once you do this, then you are free to do more.

WordPress For Free

Now it’s time to install WordPress for Free. Digital Oceans offers a free tutorial for this process as well. I suggest reading over it. https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-on-ubuntu-22-04-with-a-lamp-stack. Once you have your website installed, it’s all about the setup from here. You have the basic setup. Now it’s time to work on logos, placement, content, SEO, and more. This is a learning curve within itself.

I suggest getting a udmey account and searching for the SEO beginner to hero courses as these will change how you build out your site. I always suggest a few plugins for beginners.

  • Loginizer – This plugin prevents people from brute forcing into your site.
  • W3 Total Cache – This plugin keeps your site moving quickly and you can set it to do some crazy stuff.
  • Health Check and Troubleshooting – This will help keep you up to date. This includes things like PHP upgrades and such.
  • WP Statistics – this one is very simple, it gives you a visit and visitor lists. This way you can see your returning traffic vs new traffic.
  • Yoast SEO – SEO allows your site to be found. Yoast makes, making sites easier. It helps with blog posts and more. I personally can’t write without it. The readability helped me see some of my language issues.
  • Shortcodes Ultimate – The paid version of this is amazing, the free is amazing as well. I am able to do quotes and more with the free version. Which is why I use it.

Other Reading