<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Prazol Rupakheti</title>
    <description>The latest articles on DEV Community by Prazol Rupakheti (@prazolrupakheti).</description>
    <link>https://dev.to/prazolrupakheti</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1082812%2F1e69c4d2-0d39-4821-a7f7-a8fd64de0965.jpg</url>
      <title>DEV Community: Prazol Rupakheti</title>
      <link>https://dev.to/prazolrupakheti</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/prazolrupakheti"/>
    <language>en</language>
    <item>
      <title>How to Set Up WordPress with Docker and WP-CLI?</title>
      <dc:creator>Prazol Rupakheti</dc:creator>
      <pubDate>Sun, 16 Mar 2025 14:18:16 +0000</pubDate>
      <link>https://dev.to/prazolrupakheti/how-to-set-up-wordpress-with-docker-and-wp-cli-4ghe</link>
      <guid>https://dev.to/prazolrupakheti/how-to-set-up-wordpress-with-docker-and-wp-cli-4ghe</guid>
      <description>&lt;h2&gt;
  
  
  Benefits of Dockerizing WordPress
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Portability&lt;/strong&gt;: Easily move your WordPress environment between machines.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consistency&lt;/strong&gt;: Avoid "it works on my machine" issues with standardized environments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Easy Deployment&lt;/strong&gt;: Quickly spin up and down environments without manual configuration.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability&lt;/strong&gt;: Easily add or remove services when needed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  WP-CLI Integration
&lt;/h2&gt;

&lt;p&gt;Manage WordPress efficiently with command-line tools for installing, updating, and configuring WordPress. Easily use WP-CLI in the server to automate tasks and streamline management.&lt;/p&gt;

&lt;h2&gt;
  
  
  Folder Structure
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;project/
│-- config/
│-- db/
│-- html/
│-- .gitignore
│-- docker-compose.yml
│-- Dockerfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Folder Descriptions
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;config/ – Contains configuration files like php.ini.&lt;/li&gt;
&lt;li&gt;db/ – Stores MySQL database files (empty folder).&lt;/li&gt;
&lt;li&gt;html/ – Contains WordPress files (download and rename WordPress folder as html).&lt;/li&gt;
&lt;li&gt;.gitignore – Specifies files and folders to ignore in Git.&lt;/li&gt;
&lt;li&gt;docker-compose.yml – Defines the Docker containers and their interactions.&lt;/li&gt;
&lt;li&gt;Dockerfile – Defines how to build the web server environment.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Configuration Files
&lt;/h2&gt;

&lt;p&gt;Example: config/php.ini&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;post_max_size = 128M
upload_max_filesize = 128M
serialize_precision = 6
memory_limit = 128M
max_execution_time = 300
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example: .gitignore&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configure docker-compose.yml file
&lt;/h2&gt;

&lt;p&gt;This file defines the services required for WordPress.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;services:
  webapp:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: your-project-name
    expose:
      - 80
    ports:
      - 1000:80
    depends_on:
      - database
    working_dir: /var/www/html
    volumes:
      - ./html:/var/www/html
      - ./config/php.ini:/etc/php/8.2/apache2/conf.d/99-local.ini
    environment:
      MYSQL_HOST: database
      MYSQL_USER: admin
      MYSQL_PASSWORD: admin

  database:
    container_name: MySQL-8
    restart: always
    image: mysql:8
    volumes:
      - ./db:/var/lib/mysql
    expose:
      - 3306
    environment:
      MYSQL_ROOT_PASSWORD: admin
      MYSQL_USER: admin
      MYSQL_PASSWORD: admin
      MYSQL_DATABASE: your-project-name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configure Dockerfile file
&lt;/h2&gt;

&lt;p&gt;This file defines the web server and PHP environment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM ubuntu:20.04
LABEL name="Prazol Rupakheti"
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update &amp;amp;&amp;amp; \
    apt-get install -y --no-install-recommends apt-utils &amp;amp;&amp;amp; \
    apt-get -y install wget zip unzip curl gnupg nano cron &amp;amp;&amp;amp; \
    apt-get install lsb-release ca-certificates apt-transport-https software-properties-common -y

# Install Node.js, PM2, and Apache with PHP 8
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - &amp;amp;&amp;amp; \
    apt-get install -y nodejs &amp;amp;&amp;amp; \
    npm install -g npm@latest pm2 sass

RUN add-apt-repository ppa:ondrej/php -y &amp;amp;&amp;amp; \
    apt-get -y install php8.2 apache2 libapache2-mod-php8.2 php8.2-cli php8.2-mysql php8.2-zip php8.2-gd \
      php8.2-mbstring php8.2-curl php8.2-xml php8.2-bcmath php8.2-imagick php8.2-intl mysql-client &amp;amp;&amp;amp; \
    a2enmod rewrite headers expires

# Install phpMyAdmin
RUN wget -q https://files.phpmyadmin.net/phpMyAdmin/5.2.1/phpMyAdmin-5.2.1-english.zip &amp;amp;&amp;amp; \
    unzip -q phpMyAdmin-5.2.1-english.zip &amp;amp;&amp;amp; \
    mv phpMyAdmin-5.2.1-english /opt/phpMyAdmin &amp;amp;&amp;amp; \
    rm phpMyAdmin-5.2.1-english.zip

# Install Composer
RUN wget -q https://getcomposer.org/download/latest-stable/composer.phar &amp;amp;&amp;amp; \
    chmod +x composer.phar &amp;amp;&amp;amp; \
    mv composer.phar /usr/local/bin/composer

# Install WP-CLI
RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar &amp;amp;&amp;amp; \
    chmod +x wp-cli.phar &amp;amp;&amp;amp; \
    mv wp-cli.phar /usr/local/bin/wp

# Set up Apache
COPY config/000-default.conf /etc/apache2/sites-available
COPY config/phpmyadmin.conf /etc/apache2/conf-enabled
COPY config/99-local.ini /etc/php/8.2/apache2/conf.d/

EXPOSE 80
CMD apachectl -D FOREGROUND
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  WordPress Configuration File html/wp-config.php
&lt;/h2&gt;

&lt;p&gt;Modify the wp-config.php file inside the html/ folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/** The name of the database for WordPress */
define('DB_NAME', 'your-project-name');

/** Database username */
define('DB_USER', 'admin');

/** Database password */
define('DB_PASSWORD', 'admin');

/** Database hostname */
define('DB_HOST', 'database');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Installing Docker
&lt;/h2&gt;

&lt;p&gt;Windows &amp;amp; macOS&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install Docker Desktop from &lt;a href="https://www.docker.com/products/docker-desktop/" rel="noopener noreferrer"&gt;Docker's official site&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Ensure Docker is running.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Linux&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run the following commands to install Docker:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt update
sudo apt install -y docker.io docker-compose
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Start and enable Docker:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl start docker
sudo systemctl enable docker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Running the Containers
&lt;/h2&gt;

&lt;p&gt;Once everything is set up, open a terminal in the project root and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker-compose up -d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The -d flag stands for detached mode, which means the containers will run in the background instead of keeping the terminal occupied. This allows you to continue using the terminal while the containers are running.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This will start the WordPress and MySQL containers in the background.&lt;/p&gt;

&lt;h2&gt;
  
  
  Verifying the Containers
&lt;/h2&gt;

&lt;p&gt;Check running containers with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker ps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If using Docker Desktop, you should see two running containers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Web Server (Apache + PHP)&lt;/li&gt;
&lt;li&gt;MySQL Database&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj95uig8jnu3uhg8rt9o7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj95uig8jnu3uhg8rt9o7.png" alt="Image description" width="800" height="99"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Using WP-CLI
&lt;/h2&gt;

&lt;p&gt;To access the WordPress CLI inside the container, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker exec -it your-project-name bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, check the installed WordPress version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wp core version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwupidkw2nsu88wrp96j7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwupidkw2nsu88wrp96j7.png" alt="Image description" width="800" height="166"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Accessing WordPress
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Open a browser and go to &lt;a href="http://localhost:1000" rel="noopener noreferrer"&gt;http://localhost:1000&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;For phpmyadmin go to &lt;a href="http://localhost:1000/phpmyadmin" rel="noopener noreferrer"&gt;http://localhost:1000/phpmyadmin&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Follow the WordPress setup wizard.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;You have successfully set up WordPress using Docker and WP-CLI. Now you can develop, test, and manage WordPress projects in a containerized environment, ensuring consistency across development and production systems.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Happy Coding&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>docker</category>
      <category>wpcli</category>
      <category>php</category>
    </item>
  </channel>
</rss>
