Black Cat Blog

Thoughts, Stories, and Ideas

Running WordPress With Podman

I am a fan of using Podman over Docker to run software and platforms whenever possible because Podman is fully open source and it features rootless operation. Being able to run containers rootless is a good security measure. I wrote this little piece to document what I’ve done to make WordPress work with Podman 5.0 and higher. I run Arch Linux on my desktop at home and needed a development environment that I can use to create themes and layout websites. Without further ado, here’s how to get WordPress going with Podman. On systems that are running SELINUX, remember to add a :Z after the -v file path, e.g. -v ./database:/var/lib/mysql:Z

  1. Set up your environment. The first thing I did was to create the directories for the database and the WordPress install to live in. In my case, I created directories named wordpress and database.
  2. Create a new pod for WordPress and MySQL to reside in by typing podman create pod --name wordpress --network=pasta:-T,8080 --publish 8080:80 --publish 3306:3306
  3. Create and start the container for MySQL by typing podman run -d --name mysql --pod wordpress -e MYSQL_ROOT_PASSWORD=<your-password-here> -e MYSQL_USER=wordpress -e MYSQL_PASSWORD=<your-password-here> -e MYSQL_DATABASE=wordpress -v ./database:/var/lib/mysql mysql:latest
  4. Create and start the container for WordPress by typing podman run -d --name wp --pod wordpress -e WORDPRESS_DB_HOST=mysql -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=<your-password-here> -e WORDPRESS_DB=wordpress -v ./wordpress:/var/www/html wordpress:latest
  5. If all goes well you should be able to browse to http://localhost:8080. Once you do this, you will be able to complete your WordPress setup and start working.
  6. Finally, we need to do three more things to ensure that your development environment will start up on reboot. Create the directory .config/systemd/user and run podman generate systemd --new --files --name wordpress inside of the directory
  7. Type loginctl enable-linger. Then type systemctl --user daemon-reload.
  8. Now it is just a matter of enabling the wordpress pod on start-up by typing systemctl --user enable pod-wordpress.service.

There is not much to getting this working. On some setups you may need to enable port 8080 on the firewall if you are unable to browse to the WordPress installer on part 5. Happy developing!