Setting Up WordPress in on RHEL8 in Containers

# Install podman and slirp4netns
[root@localhost ~]# dnf install podman slirp4netns

# Pull done the MySQL / MariaDB container image
[root@localhost ~]# podman pull registry.access.redhat.com/rhscl/mariadb-102-rhel7

# Pull down the http and PHP container image
[root@localhost ~]podman pull registry.access.redhat.com/rhscl/php-71-rhel7

# Check what user the MariaDB image is using
[root@localhost ~]# podman inspect registry.access.redhat.com/rhscl/mariadb-102-rhel7 | grep User
# It will probably return “User”: “27”

# Check what ports the MariaDB image uses
[root@localhost ~]# podman inspect registry.access.redhat.com/rhscl/mariadb-102-rhel7 | grep -A1 ExposedPorts
# It will probably return “3306/tcp”: {}

# Check what user the httpdphp image users
[root@localhost ~]# podman inspect registry.access.redhat.com/rhscl/php-71-rhel7 | grep User
# It will probably return “User”: “1001”

# Create and permission the folders needed by the MySQL / MariaDB container
[root@localhost ~]# mkdir -p /opt/var/lib/mysql/data
[root@localhost ~]# chown 27:27 /opt/var/lib/mysql/data

# Create and permission the folder needed by the HttpPHP container
[root@localhost ~]# mkdir -p /opt/app-root/src
[root@localhost ~]# chown 1001:1001 /opt/app-root/src

# Create the mariadb-service.service file
[root@localhost ~]# vi /etc/systemd/system/mariadb-service.service
See mariadb-service.service

# Create the httpdphp-service.service file
[root@localhost ~]# vi /etc/systemd/system/httpdphp-service.service
See httpdphp-service.service

# Register the new service files
[root@localhost ~]# systemctl daemon-reload

# Start and check the status of the mariadb services
[root@localhost ~]# systemctl start mariadb-service
[root@localhost ~]# systemctl status mariadb-service

# Check and check the status of the httpdphp services
[root@localhost ~]# systemctl start httpdphp-service
[root@localhost ~]# systemctl status httpdphp-service

# Check both containers are running
[root@localhost ~] podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b3019129edc5 registry.access.redhat.com/rhscl/mariadb-102-rhel7:latest run-mysqld 33 minutes ago Up 33 minutes ago 0.0.0.0:3306->3306/tcp mariadb-service
326f857751d3 registry.access.redhat.com/rhscl/php-71-rhel7:latest /bin/sh -c /usr/l... 40 minutes ago Up 40 minutes ago 0.0.0.0:8080->8080/tcp httpdphp-service

# NOTE: The Contain IDs will differ on your system, and on each restart of the container.

# Check that the proper ports are expoect on both containers
[root@localhost ~]# podman port -a
326f857751d3 8080/tcp -> 0.0.0.0:8080
b3019129edc5 3306/tcp -> 0.0.0.0:3306

# Check the httpdphp container has an IP Address
[root@localhost ~]# podman inspect -f "{{.NetworkSettings.IPAddress}}" 326f857751d3
10.88.0.3

# Check the mariadb container has an IP Address
[root@localhost ~]# podman inspect -f "{{.NetworkSettings.IPAddress}}" b3019129edc5
10.88.0.7

# NOTE: Because of the “–ip 10.88.0.7” in the mariadb-service.service file, this should return this IP Address

—— Both containers should now be running OK ——————

# Change into the /opt/app-root/src folder
[root@localhost ~]# cd /opt/app-root/src

# Get the latest wordpress
[root@localhost ~]# wget http://latest.wordpress.com/latest.tar.gz

# Expand the archive
[root@localhost ~]# tar zxvf latest.tar.gz

# Move the contents into the current folder
[root@localhost ~]# mv wordpress/* .

# Fix the permissions
[root@localhost ~]# chown -R * 1001:1001 /opt/app-root/src

# Update firewall on localhost
[root@localhost ~]# firewall-cmd --add-port=3036/tcp --permanent
success
[root@localhost ~]# firewall-cmd --add-port=8080/tcp --permanent
success

# Restart firewall
[root@localhost src]# systemctl restart firewalld

——- You should able to browse to the IP address of the host machine, using port 8080, and get the WordPress setup page.
——- On the WordPress setup page, you might have to setup like this :

Database : wordpress
Username : wordpress
Password : mysecret
Database Host : 10.88.0.7 <——- NOTE – the address of the MariaDB container
Table Preix : wp_

—————– Configure host firewall —————–

# Add the podman/container interface to the firewall trusted list

[root@localhost ~]# firewall-cmd --zone=trusted --add-interface=cni-podman0 --permanent

# You may also have to add the http service to the firewall


[root@localhost ~]# firewall-cmd --add-service=http --permanent
[root@localhost ~]# firewall-cmd --add-service=https --permanent