Docker Install Wordpress

2/12/2022by admin

Requirements:

  • Ubuntu 20.04 LTS Installed
    • Can be Desktop or Server version, does not matter
  • Basic understanding of Linux and Linux commands

Install Docker

Install WordPress using docker compose. You can automatically deploy a local docker wordpress site in 5 minutes using the following commands. Two options are available: make command and docker-compose standard commands. Nov 07, 2019 Docker is a great containerization tool to experiment with WordPress. Its minimal environment helps you maintain the efficiency of your system resources. In this tutorial, you’ve learned how to install Docker on Linux, macOS, and Windows.

The first thing we will need is, obviously, Docker. Docker is an opensource platform used for building, deploying and managing ‘containers’. Containers are isolated, virtualized processed that do not have access or visibility into other parts of the system, this makes it ideal for application services that do not require access to the whole system. Unlike Virtual Machines, containers do not need to carry the whole Operating System, only the relevant processes and dependencies necessary for it to perform its tasks.

Step 1 – Install Docker

To make sure that the Docker version you are downloading for your system is the latest version you should install Docker from the official Docker repo. Just add a new package source, add the official Docker GPG key and install the package.

Update your existing list of packages by issuing this command to your terminal instance:

Then you should install some packages that allow apt to use packages over HTTPS

Docker-compose

As I said earlier, we must add the official Docker GPG key before we can install the package:

Next up, you got to add the docker repository to your APT sources:

Make sure that you update your package database with the Docker packages from the repo you just added:

Next, make sure that you are about to install from the Docker repo you just added:

You will see a lot of text outputted to your screen, however, the most important part is at the top. You text should look something like this:

If the above snippet corresponds with your terminal output: Well done! You can now install Docker!

To install Docker, just use apt:

If this finished successfully, congratulations! You just installed Docker. To check that everything is running well, use the following command to check the service status:

If your installation was successful it should look something like below. Look for the ‘Active: active (running) line. If your terminal shows something else, you might have to retrace your steps to find the error.

Also, be sure to install Docker Compose, as that is what we will be using to start running our containers:

Step 2 – Execute Docker Without Sudo

By default the docker rommand can only be ran by the root user, or a user in the docker group. Meaning, the docker command can not be ran without prefixing it with ‘sudo’ first. There is a way to go around this, by adding your own username to the docker group.

You can run the command ‘groups {username}’ to check which groups your user belong to. After a default installation you will not be included in the ‘docker’ group, so you have to do that manually.

First off, remember to change {username} to your own, personal, username. {username} is not a valid parameter for this command.

Then, you can just log in and out of your account to apply the settings. Once you have logged back in, check that you are added to the docker group:

If your terminal output looks something like this, you’ve done everything correctly! Your user is now in the docker group, and ready to move on to the next step.

Step 3 – Setting up the Web Server Environment

First off, you need to create the appropriate folders to place your WordPress installation in. The placement of your project directory does not matter, but try to place it somewhere you can easily find it again if need be.

Wordpress

Next up, enter the directory using the ‘cd’ command, and create a new directory inside your current directory to store your nginx configuration files.

Then, you can create your nginx.conf file inside the nginx-conf folder. Choose whatever text editor you are the most comfortable with, personally, I use nano.

Congratulations! You have now created your nginx configuration file, and you can start filling in the relevant configurations to suit your installation of nginx.

IMPORTANT! Replace the parameters [yourdomain.com] & www.[yourdomain.com] with your domain, if you don’t have any you can use example.com, you will however not be able to access the site via a domain, but rather an IP. For this exercise, a domain is NOT mandatory.

Step 4 – Environment Variables

Back in your ‘~/wordpress/’ folder that you created at the beginning of step 3, create a ‘.env’ file. ‘Dot-files’ are treated as ‘hidden’ files, they can still be shown by issuing a command such as ‘ls -a’, however. Putting sensitive information in a separate ‘Dot-file’ is considered good practice, as ‘Dot-files’ are excluded from Git, for example. Putting this information inside your main project files is not good practice, and can lead to security leaks.

Creating a ‘Dot-file’ is exactly the same as creating any other file.

Change everything inside the square brackets ( ‘[ ]’ ) to whatever you would like, but remember that these parameters are the login for your WordPress databases, so try to remember them and use appropriate password security.

Step 5 – Docker Compose!

Finally we have everything ready and can start configuring Docker Compose. Your ‘docker-compose.yml’ file will contain the definitions for each service that is found in your setup. A service in compose is a running container, and these definitions specify how these containers will run.

First, create your ‘docker-compose.yml’ file in your ~/wordpress/ directory!

Now, add the database configuration to your newly created file:

There is no guarantee that all the settings will be identical on your setup, so if anything does not work try to double check your settings to see if they are correct.

Docker-php-ext-install Wordpress

Then, below your database definition, add a new definition. This time, for the WordPress application:

Finally, add your webserver service configuration to the same file as the WordPress and database configurations.

Docker Install Wordpress Plugins

The last thing you need to add to the file is your volume and network definitions. This tells Docker where to look for the specified services.

Docker

Docker Install Wordpress Free

In the end, your ‘docker-compose.yml’ file should look like this:

Step 6 – Running Docker Compose

If everything went well in the configuration part of this tutorial, you should now be good to run your configuration.

In Docker Compose, run the ‘docker-compose up -d’ command to start your containers.

A whole lot of different output will be displayed to your terminal. Be sure to check for error messages! If everything went fine, you can run a new command to check the status of your services:

If everything went fine, your output should look like this:

Docker Install Wordpress

Just ignore the ‘certbot’ line in my script, as that is not relevant for this tutorial – only if you want SSL encryption on your website, which we will not need. Just check that ‘db’, ‘webserver’ and ‘wordpress’ is ‘Up’. If all the services are ‘Up’… Congratulations! You’ve done everything correct so far. If they have a different status, you may have to go through the tutorial again to find where you made the error.

If you do see anything other than ‘Up’ in your statuses, you can always check the log files to see where it all went wrong. You can check log files by issuing the following command:

Just replace [service] with whatever service you want to check, for example, checking the ‘wordpress’ service would be:

And so on. If nothing went wrong, you do not have to check logs unless you are particularly interested.

Step 7 – All Done!

If you did not get any error messages by now, you should be good to go! Go to your web browser and type in the IP of the machine/VM you installed WordPress on, and the result should look something like below:

You are now ready to start configuring WordPress in your web browser!

If you have any issues, I would suggest taking a look at the guides linked below as well, as they have their own explanations and walkthroughs for the same final result.

This guide was made by the help of various DigitalOcean How To’s which I compiled into one coherent guide for educational use, this guide is non-commercial and only meant for educational purposes only.

Comments are closed.