Giter Site home page Giter Site logo

wp-docker's Introduction

Overview

A simple opinionated PHP 7.4 Docker & Compose Environment for WordPress using Nginx, PHP-FPM, Redis, PHPMyAdmin, Composer, WP CLI and Bedrock.

Images Used

This project use the following ports :

Server Port
MySQL 3306
PHPMyAdmin 8081
Nginx 8080
Nginx SSL 3000
Redis 6379

PHP Extensions: date, libxml, openssl, pcre, sqlite3, zlib, ctype, curl, dom, fileinfo, filter, ftp, hash, iconv, json, mbstring, SPL, PDO, pdo_sqlite, session, posix, readline, Reflection, standard, SimpleXML, Phar, tokenizer, xml, xmlreader, xmlwriter, mysqlnd, cgi-fcgi, bcmath, exif, gd, imagick, mysqli, redis, sodium, zip

Install prerequisites

For now, this project has been mainly created for Unix (Linux/MacOS). Perhaps it could work on Windows.

All requisites should be available for your distribution. The most important are :

Installation

Step 0: Clone Repository

Clone this repository in your preferred location.

git clone https://github.com/tareq1988/wp-docker.git wordpress
cd wordpress

Step 1: Dependency Install

Copy the .env-example file to .env. It contains the NGINX hostname and MySQL database credentials. After filling that up, run:

make install
make install-plugins

Step 2: WordPress Configuration

The above command will install the dependencies in place. To complete the WordPress installation, you've to configure the /src/.env file for to Bedrock use. Copy the /src/.env.example to /src/.env file and change the MySQL table and username as configured on the root .env file.

Important: Set your DB_HOST to mariadb in the /src/.env file.

Site URL: The default WordPress site URL will be http://wordpress.local:8080 which is defined in the root .env file as the Nginx Host NGINX_HOST=wordpress.local. If you change this to something else, make sure you also change this value in /src/.env file, the WP_HOME configuration (WP_HOME=http://wordpress.local:8080). The port name has to be appended.

Application Salt: Generate the salt from the generator and replace it on /src/.env file.

Configure Host File: You've to configure your /etc/hosts file to point the site URL to 127.0.0.1. As we are using http://wordpress.local as our hostname, add this config in your /etc/hosts file.

sudo vi /etc/hosts

Add config:

127.0.0.1	wordpress.local

Now save and exit.

Step 3: Run

Now as all the configuration is done, run the docker instance.

make docker-start

This will simply run docker in detached mode with this command: docker-compose up -d

Go to http://wordpress.local:8080 in your browser and you should see the WordPress installation page.

WordPress Setup

We are using Bedrock as our WordPress starter kit.

When using make install command, the required dependencies will be installed automatically. With the command make install-plugins, the following plugins will be installed as a composer dependency:

Page Cache: By default, we will be using Nginx Fastcgi Cache and the Nginx Cache plugin will be the helper to clear the cache. In the plugin settings, you have to save the path to /var/run/nginx-cache as the clear path.

If you don't want to use fastcgi cache, edit the /conf/nginx/site.template.conf and comment or remove the line include global/wpfc-php.conf; and uncomment include global/php.conf; file.

Object Cache: We will be using Redis as our persistant object cache backend. The Redis Cache plugin will be used to conditionally clear out the redis cache storage. The command make install-plugins will automatically install the plugin and will put the object-cache.php in the required location (/web/app/object-cache.php).

In order to take the redis cache setup complete, you've to manually add this line define('WP_REDIS_HOST', 'redis'); in the /src/config/application.php file.

Directory Structure

├── Makefile
├── README.md
├── conf					# Nginx, PHP Configuration
│   ├── mysql
│   │   └── my.cnf
│   ├── nginx					
│   │   ├── global/
│   │   ├── nginx.conf
│   │   └── site.template.conf
│   └── php
│       └── php.ini
├── data					# Persistant data directory
│   ├── dumps/
│   ├── logs/
│   ├── mysql
│   │   └── mariadb
│   └── nginx-cache/
├── docker-compose.yml
└── src						# Application Code
    ├── CHANGELOG.md
    ├── CODE_OF_CONDUCT.md
    ├── LICENSE.md
    ├── README.md
    ├── composer.json
    ├── composer.lock
    ├── config
    │   ├── application.php			# Primary wp-config.php
    │   └── environments
    │       ├── development.php
    │       ├── production.php
    │       └── staging.php
    ├── vendor					# Composer dependencies
    │   ├── autoload.php
    │   ├── bin/
    │   ├── composer/
    │   ├── johnpbloch/
    │   ├── oscarotero/
    │   ├── roots/
    │   ├── squizlabs/
    │   └── vlucas/
    ├── web
    │   ├── app/				# WordPress content directory
    │   ├── index.php
    │   ├── wp/					# WordPress core
    │   └── wp-config.php
    └── wp-cli.yml

Use Makefile

When developing, you can use Makefile for doing the following operations :

Name Description
install Run docker build and install bedrock
install-plugins Install the required WP plugins
clean Clean directories for reset
docker-start Create and start containers
docker-stop Stop and clear all services
logs Follow log output
mysql-dump Create backup of whole database
mysql-restore Restore backup from whole database

Examples

Start the application :

make docker-start

Show help :

make help

wp-docker's People

Contributors

eagl3s1ght avatar tareq1988 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

wp-docker's Issues

mysql_connect missing

Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /var/www/html/web/wp/wp-includes/wp-db.php on line 1562

seems dockerfile isnt installing the php mysql functions correctly.
i had to run docker exec -it php docker-php-ext-install pdo_mysql and then docker restart php, and get fresh cache by adding ?a=a to url

Composer update uses php:latest

hi, I am trying to use this docker setup but someplugins require php7 and currently the make composer-up command uses php:latest.. which is php8. .

very strange...

checking for libzip... not found

I get this error, trying to install it on ubuntu 18.04:
checking for libzip... not found
configure: error: Please reinstall the libzip distribution
ERROR: Service 'php' failed to build: The command '/bin/sh -c buildDeps=" default-libmysqlclient-dev libbz2-dev libsasl2-dev " runtimeDeps=" curl git libfreetype6-dev libicu-dev libjpeg-dev libldap2-dev libpng-dev libpq-dev libxml2-dev " && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y $buildDeps $runtimeDeps && docker-php-ext-install bcmath bz2 calendar iconv intl mbstring mysqli opcache pdo_mysql soap zip && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && docker-php-ext-install gd && pecl install redis && docker-php-ext-enable redis.so && apt-get purge -y --auto-remove $buildDeps && rm -r /var/lib/apt/lists/*' returned a non-zero code: 1 Makefile:27: recipe for target 'install' failed make: *** [install] Error 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.