Git Product home page Git Product logo

dusty's Introduction

Dusty: A WordPress Composer Starter Repo

PHP Version Support

Dusty is an example WordPress starter repo based around Composer and Docker. It allows you to create WordPress repos without the need to store core WordPress files in your Git repository. This makes for far easier deployments and cleaner code. It also allows you to load in non-WordPress packages such as PHPDotEnv via Composer.

Setup

To make use of Dusty you will need to install both Composer and Docker locally. Composer is a PHP package manager linked to Packagist and Docker is a containerisation platform that allows you to easily generate development and production environments.

Installation

Installation assumes you are working in a Linux or a Linux like environment.

Install using Composer:

composer create-project --no-dev --no-interaction --ignore-platform-reqs rbdwllr/dusty [project-name]

Build Docker:

docker-compose build
docker-compose up -d

Create .env file with WordPress salts:

docker-compose exec web composer make-environment

Once these steps have been completed go to localhost:8080 to use WordPress and finish off the installation process.

Package and Plugin Management

By default Composer can pull in packages from Packagist, and this is great if you wish to extend WordPress with more general PHP libraries and frameworks. This though does not help you easily manage plugins and themes. Dusty though integrates with a package manager called WPackagist which is the WordPress equivalent of Packagist for plugins and themes.

You can add your plugins and themes to your composer.json file in exactly the same way as you add PHP packages. They will also be placed in the relevant WordPress directories, rather than the vendor folder.

// Example composer.json config, using WPackagist.
"repositories":[
    {
        "type":"composer",
        "url":"https://wpackagist.org"
    }
],
"require": {
    "wpackagist-plugin/wordpress-seo": "^11.0",
    "wpackagist-plugin/advanced-custom-fields": "^5.0",
    "wpackagist-theme/twentynineteen": "^1.0",
},
"extra": {
    "installer-paths": {
        "public/wp-content/mu-plugins/{$name}": ["type:wordpress-muplugin"],
        "public/wp-content/plugins/{$name}": ["type:wordpress-plugin"],
        "public/wp-content/themes/{$name}": ["type:wordpress-theme"]
    },
    "wordpress-install-dir": "public/wordpress"
}

Use Private Repos

Sometimes you'll wish to keep some of your code private but still pull it in via Composer. For instance you may have a WordPress theme that contains branded material and custom code.

You can do this by adding a Version Control System repository to your Composer config:

"repositories":[
    {
        "type":"composer",
        "url":"https://wpackagist.org"
    },
    {
        "type": "vcs",
        "url":  "[email protected]:vendor/repo-name.git"
    }
],

Note: Your theme will require a composer.json file with config which defines it as a WordPress theme. You will need a similar setup if you are creating a private plugin, but you will set the type as "type": "wordpress-plugin".

// Example composer.json for a WordPress theme.
{
    "name": "vendor/theme",
    "description": "My cool theme.",
    "type": "wordpress-theme",
    "license": "proprietary",
    "require": {}
}

Repository SSH Keys

Usually if you are using a VCS repository, such as GitHub, it will be private and you will need to allow Composer to authenticate with the repository. The easiest way to do this is via SSH keys.

To give Docker access to these SSH keys you will need to copy them into the web container and amend the user privileges:

# Copy your local private key into the root/.ssh folder of the web container.
docker cp ~/.ssh/id_rsa wordpress_web:/root/.ssh

# Amend the privileges of the .ssh folder to 600 in the web container.
docker-compose exec web chmod 600 -R /root/.ssh

Once this is done you can run composer install with no interaction docker-compose exec web composer install --no-dev --no-interaction.

Note: The keys will be stored in a separate Docker volume so will persist even if you delete the container.

Managing MySQL

On occasions you will need to interact with MySQL (MariaDB) directly and you can do this via a SQL GUI tool such as SequelPro or HeidiSQL. But you may also wish to interact with the database via the CLI which can be done easily via docker-compose.

# Access MySQL Database.
docker-compose exec data mysql

You may also wish to import data into the database via the CLI too, Dusty makes this easy. When you create Dusty via docker-compose a directory called data is created both locally and in the container. You can then drop SQL files into the local data directory and they will be available to the container. Then you can access the container and import the files.

docker-compose exec data bash

cd /var/www/html/data

mysql wordpress < example.sql

You can also dump data back out to the local data directory in a similar way.

docker-compose exec data bash

cd /var/www/html/data

mysqldump wordpress > my-dump.sql

Useful Resources

Cat Tax

This is Dusty, AKA Princess Dustle-Puff, Ruler of All Things Soft and Scratchable, I named this repo after her. She is sat in my code chair, I think she's trying to help...

dusty's People

Contributors

robdwaller avatar

Stargazers

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

Watchers

 avatar

dusty's Issues

Abstract Env Functionality to Package

DotEnv returns everything as a string.

  • We need a package to convert to booleans, null and integers.
  • Also needs to load dot env and the required fields.
  • Should come with some default fields baked in.
  • Should be able to add and remove required fields.
  • Possibly even completely overwrite them.

Debugging Themes or Plugins

I can't quite figure out how to setup the Dockerfile or anything so that I can Debug Themes or Plugins I am creating.
Can you share your setup for this?

make-environment makes docker not restart

After running make-environment, you get spaces in the .env file. So docker commands stop working until you manually remove the spaces. .env expects key=value instead of key = value

Error shown after trying to docker-compose down from a fresh installation
ERROR: In file ./.env: environment variable name 'AUTH_KEY ' may not contains whitespace.

Issues to fix for 0.2

  • MySQL DB needs its own volume.
  • There needs to be some level of https / SSL support.
  • Documentation needs to be added on WPackagist
  • ImageMagick or GD need to be installed and enabled for WordPress support.

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.