For the last two days, I have been stuck in how to run a locally Wordpress Store with Woocommerce.
I have tried to use the (g)old LAMP with NGINX, docker images, whatever until find the easiest way.
An online friend on WordPress slack named Leandro shares a link from official docs on Docker where they explain how to run a WordPress store with two simple images.
This tutorial will be upon this link. There is explained how to create a new docker-compose file to compose an image from MySQL and WordPress to have locally your store.
The link is here Quickstart: Compose and WordPress and before continuing check it and create the docker-compose file in a local folder in your machine.
Let's edit our
docker-compose.yml file to bring the content from containers to our local machine.
From this, we can edit the files locally and reproduce whatever we want on the local store.
For example, we can use this to create a new payment plugin.
- Open the
docker-compose.ymland replace for this code:
version: "3.9" services: db: image: mysql:5.7 volumes: - ./db_data:/var/lib/mysql restart: always environment: MYSQL_ROOT_PASSWORD: somewordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress wordpress: depends_on: - db image: wordpress:latest volumes: - ./wordpress:/var/www/html - ./plugins:/var/www/html/wp-content/plugins ports: - "8000:80" restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress WORDPRESS_DB_NAME: wordpress
Here we use volumes to make available locally the folders we want to have access to.
Look to the lines 17, 18, and 19. It is where we ask to transform the content of folders into volumes. Thanks for Fernando Almeida, a friend from React Brasil slack helped me with this.
Now, on the root folder as the same as the docker-compose file, run
docker-compose up -d to mount our containers and images.
Now, the folders
WordPress must be available locally and you can start your development work o/!!
Until here we just have a simple WordPress blog. My use case needs to have a woocommerce store.
To get it we need to complete the simple steps explained below
Let's install a theme to transform our website in a store. The default theme of WordPress is a blog site and is not what we want.
Dashboard > Appearance > Themes > Add new and search for "storefront".
Install the woo-commerce plugin similar to the last step:
Dashboard > Plugins > Add new and search for "woocommerce"
The repo is available here docker-wordpress