Giter Site home page Giter Site logo

wordpress-composer's Introduction

Composer Template for WordPress Projects

This project template should provide a kickstart for managing your site dependencies with Composer.

This project consist of:

  • WordPress core: johnpbloch/wordpress-core-installer
  • Repository https://wpackagist.org/ to install WordPress plugins and themes
  • composer/installers to set custom paths for plugins and themes
  • drupal-composer/preserve-paths to exclude paths for plugins and themes under version control
  • wodby.yml that runs composer install. You can remove it if you're not using Wodby

Current WordPress core: ~5.0

Paths

By default, wordpress core will be installed in ./web directory. Plugins and themes will be installed in ./web/wp-content/plugins and ./web/wp-content/themes. Point your Apache vhost or similar to this project's ./web directory.

Usage

First you need to install composer.

Note: The instructions below refer to the global composer installation. You might need to replace composer with php composer.phar (or similar) for your setup.

Start a new project:

composer create-project wodby/wordpress-composer some-dir --stability dev --no-interaction

The composer create-project command passes ownership of all files to the project that is created. You should create a new git repository, and commit all files not excluded by the .gitignore file.

How to install WordPress plugins and themes?

With composer require ... you can download new dependencies to your installation.

cd some-dir
composer require wpackagist-plugin/wp-cfm

How to manage my custom themes and plugins under version control?

  1. Exclude path to your plugin or theme from .gitignore. Example for theme under web/wp-content/themes/my-custom-theme/:
    !web/
    web/*
    !web/wp-content/
    web/wp-content/*
    !web/wp-content/themes/
    web/wp-content/themes/*
    !web/wp-content/themes/my-custom-theme/
    
  2. Add the same path to your composer.json under extra > preserve-paths:
    "preserve-paths": [
      "web/wp-content/themes/custom"
    ]
    
  3. Add your plugin/theme directory under version control
  4. Run composer install. Composer will install WordPress core and keep your custom theme

Deployment via Wodby

  1. Create a new project.
  2. Connect the repository to Wodby.
  3. Deploy new app, choose WordPress stack, on the 2nd step of the form choose connected repository and enter web as Codebase dir.

wordpress-composer's People

Contributors

csandanov avatar leymannx avatar mantis4444 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wordpress-composer's Issues

WordPress Core Update Overwrites Plugins Installed by Composer

Hi,

I have been attempting to update my WordPress sites on Wodby from 4.9.5 to 4.9.6, however each time I do this all of the packages (that is plugins) installed by composer are removed. I believe the reason this is occurring is that I've set my plugins to install within the web/wp-content/plugins directory which is within the WordPress core installation path web. When composer updates it sees that my plugins are up to date and then updates core which removes everything in the web directory and replaces it with the updated files, however this does not include the packages that were previously installed.

I have a workaround which is to add the entire web/wp-content/plugins directory into the preserve-paths array, however this means that whatever was originally in that directory will overwrite whatever was added by a core update. So far I haven't noticed any ill effects, however I'm going to keep testing to make sure of this.

To reproduce this issue you need the lock file generated by the 4.9.5 core update and the 4.9.6 core update. Initially run a clean install of WordPress 4.9.5, after this completes update the WordPress core package (johnpbloch/wordpress-core) to point to 4.9.6 and then replace the current composer.lock with the lock file created by 4.9.6. The reason for this is that I update my lock file locally and push this to my staging and prod environments so a composer update command is never run anywhere except on my own dev machine. Run a composer install again and you will see that any packages installed by composer will be missing.

My composer.json is as follows:

  "name": "noneyabeeswax",
  "description": "...",
  "type": "project",
  "license": "GPL-2.0+",
  "authors": [
    {
      "name": "Linus Torvalds",
      "role": "Web Developer"
    },
    {
      "name": "Richard Stallman",
      "role": "Lead Developer"
    }
  ],
  "repositories":[
    {
      "type":"composer",
      "url":"https://wpackagist.org"
    }
  ],
  "minimum-stability": "dev",
  "prefer-stable": true,
  "config": {
    "sort-packages": true
  },
  "require": {
    "composer/installers": "^1.2",
    "drupal-composer/preserve-paths": "0.1.*",
    "johnpbloch/wordpress-core-installer": "^1.0",
    "johnpbloch/wordpress-core": "4.9.5",
    "wpackagist-plugin/broken-link-checker": "1.11.5",
    "wpackagist-plugin/cloudflare": "3.3.2",
    "wpackagist-plugin/contact-form-7": "5.0.1",
    "wpackagist-plugin/disable-author-pages": "0.11",
    "wpackagist-plugin/google-analytics-for-wordpress": "7.0.6",
    "wpackagist-plugin/google-sitemap-generator": "4.0.9",
    "wpackagist-plugin/jquery-updater": "2.1.4",
    "wpackagist-plugin/redirection": "3.2.1",
    "wpackagist-plugin/user-role-editor": "4.42",
    "wpackagist-plugin/validated": "2.1.2",
    "wpackagist-plugin/wordpress-importer": "0.6.4",
    "wpackagist-plugin/wpautop-control": "1.6",
    "wpackagist-plugin/wp-mail-smtp": "1.2.5"
  },
  "extra": {
    "installer-paths": {
      "web/wp-content/plugins/{$name}/": ["type:wordpress-plugin"],
      "web/wp-content/themes/{$name}/": ["type:wordpress-theme"]
    },
    "preserve-paths": [
      "web/wp-config.php",
      "web/wp-content/uploads",
      "web/wp-content/themes/custom-theme",
      "web/wp-content/plugins/custom-plugin1",
      "web/wp-content/plugins/custom-plugin2",
    ],
    "wordpress-install-dir": "web"
  }
}

wordpress-composer + docker4wordpress with external libraries like PHP dotenv

Hello,

Could you please help me to solve one issue?

I would like to use these things together:

I'm using macOS.

I would like to use a PHP dotenv library for inserting my .env variables inside wp-config.php.

However when I set up docker4wordpress and then inside wordpress-composer project added "composer require vlucas/phpdotenv", it can't see it, because with docker volumes I'm syncing only web folder and vlucas/phpdotenv library is outside in the vendor folder.

So when I try to include it inside web/wp-config.php:

require_once(__DIR__ . '/../vendor/autoload.php');

(new \Dotenv\Dotenv(__DIR__.'/../'))->load();

WP can't find it, because it's looking inside the web folder in docker volume and any other vendor libraries are not syncing with docker volumes.

Question:

How can I use external libraries, not only custom plugins and themes to make them visible?

docker-sync.yml

version: "2"

syncs:
  docker-sync:
    src: './'
    sync_userid: '1000'
    sync_excludes: ['.gitignore', '.git/', '.idea/']
#  docker-sync-another-project:
#    src: '/absolute/path/to/project/codebase'
#    sync_userid: '1000'
#    sync_excludes: ['.gitignore', '.git/', '.idea/']

docker-compose.yml

version: "3"

services:
   mariadb:
    image: wodby/mariadb:$MARIADB_TAG
    container_name: "${PROJECT_NAME}_mariadb"
    stop_grace_period: 30s
    environment:
      MYSQL_ROOT_PASSWORD: $DB_ROOT_PASSWORD
      MYSQL_DATABASE: $DB_NAME
      MYSQL_USER: $DB_USER
      MYSQL_PASSWORD: $DB_PASSWORD
    volumes:
#      - ./mariadb-init:/docker-entrypoint-initdb.d # Place init .sql file(s) here.
      - ./db-data:/var/lib/mysql # I want to manage volumes manually.

   php:
    image: wodby/wordpress-php:$PHP_TAG
    container_name: "${PROJECT_NAME}_php"
    environment:
      PHP_SENDMAIL_PATH: /usr/sbin/sendmail -t -i -S mailhog:1025
      DB_HOST: $DB_HOST
      DB_USER: $DB_USER
      DB_PASSWORD: $DB_PASSWORD
      DB_NAME: $DB_NAME
## Read instructions at https://wodby.com/stacks/wordpress/docs/local/xdebug/
#      PHP_XDEBUG: 1
#      PHP_XDEBUG_DEFAULT_ENABLE: 1
#      PHP_XDEBUG_REMOTE_CONNECT_BACK: 0
#      PHP_IDE_CONFIG: serverName=my-ide
#      PHP_XDEBUG_REMOTE_HOST: 172.17.0.1 # Linux
#      PHP_XDEBUG_REMOTE_HOST: 10.254.254.254 # macOS
#      PHP_XDEBUG_REMOTE_HOST: 10.0.75.1 # Windows
    volumes:
#      - ./:/var/www/html
## For macOS users (https://wodby.com/stacks/wordpress/docs/local/docker-for-mac/)
      - ./web:/var/www/html:cached # User-guided caching
      - docker-sync:/var/www/html # Docker-sync
## For XHProf and Xdebug profiler traces
#      - files:/mnt/files

   nginx:
    image: wodby/nginx:$NGINX_TAG
    container_name: "${PROJECT_NAME}_nginx"
    depends_on:
      - php
    environment:
#      NGINX_PAGESPEED: "on"
      NGINX_STATIC_OPEN_FILE_CACHE: "off"
      NGINX_ERROR_LOG_LEVEL: debug
      NGINX_BACKEND_HOST: php
      NGINX_VHOST_PRESET: wordpress
    volumes:
#      - ./:/var/www/html
# Options for macOS users (https://wodby.com/stacks/wordpress/docs/local/docker-for-mac/)
      - ./web:/var/www/html:cached # User-guided caching
      - docker-sync:/var/www/html # Docker-sync
    labels:
      - 'traefik.backend=nginx'
      - 'traefik.port=80'
      - 'traefik.frontend.rule=Host:${PROJECT_BASE_URL}'

   mailhog:
    image: mailhog/mailhog
    container_name: "${PROJECT_NAME}_mailhog"
    labels:
      - 'traefik.backend=mailhog'
      - 'traefik.port=8025'
      - 'traefik.frontend.rule=Host:mailhog.${PROJECT_BASE_URL}'

#  postgres:
#    image: wodby/postgres:$POSTGRES_TAG
#    container_name: "${PROJECT_NAME}_postgres"
#    stop_grace_period: 30s
#    environment:
#      POSTGRES_PASSWORD: $DB_PASSWORD
#      POSTGRES_DB: $DB_NAME
#      POSTGRES_USER: $DB_USER
#    volumes:
#      - ./postgres-init:/docker-entrypoint-initdb.d # Place init file(s) here.
#      - /path/to/postgres/data/on/host:/var/lib/postgresql/data # I want to manage volumes manually.

#  apache:
#    image: wodby/apache:$APACHE_TAG
#    container_name: "${PROJECT_NAME}_apache"
#    depends_on:
#      - php
#    environment:
#      APACHE_LOG_LEVEL: debug
#      APACHE_BACKEND_HOST: php
#      APACHE_VHOST_PRESET: php
#    volumes:
#      - ./:/var/www/html
## For macOS users (https://wodby.com/stacks/wordpress/docs/local/docker-for-mac/)
##      - ./:/var/www/html:cached # User-guided caching
##      - docker-sync:/var/www/html # Docker-sync
#    labels:
#      - 'traefik.backend=apache'
#      - 'traefik.port=80'
#      - 'traefik.frontend.rule=Host:${PROJECT_BASE_URL}'

#  varnish:
#    image: wodby/varnish:$VARNISH_TAG
#    container_name: "${PROJECT_NAME}_varnish"
#    depends_on:
#      - nginx
#    environment:
#      VARNISH_SECRET: secret
#      VARNISH_BACKEND_HOST: nginx
#      VARNISH_BACKEND_PORT: 80
#      VARNISH_PURGE_KEY: key
#      VARNISH_CONFIG_PRESET: wordpress
#      VARNISH_PURGE_EXTERNAL_REQUEST_HEADER: X-Real-IP
#    labels:
#      - 'traefik.backend=varnish'
#      - 'traefik.port=6081'
#      - 'traefik.frontend.rule=Host:varnish.${PROJECT_BASE_URL}'

#  redis:
#    container_name: "${PROJECT_NAME}_redis"
#    image: wodby/redis:$REDIS_TAG

#  adminer:
#    container_name: "${PROJECT_NAME}_adminer"
#    image: wodby/adminer:$ADMINER_TAG
#    environment:
## For PostgreSQL:
##      ADMINER_DEFAULT_DB_DRIVER: pgsql
#      ADMINER_DEFAULT_DB_HOST: $DB_HOST
#      ADMINER_DEFAULT_DB_NAME: $DB_NAME
#    labels:
#      - 'traefik.backend=adminer'
#      - 'traefik.port=9000'
#      - 'traefik.frontend.rule=Host:adminer.${PROJECT_BASE_URL}'

#  webgrind:
#    image: wodby/webgrind:$WEBGRIND_TAG
#    container_name: "${PROJECT_NAME}_webgrind"
#    environment:
#      WEBGRIND_PROFILER_DIR: /mnt/files/xdebug/profiler
#    labels:
#      - 'traefik.backend=webgrind'
#      - 'traefik.port=8080'
#      - 'traefik.frontend.rule=Host:webgrind.${PROJECT_BASE_URL}'
#    volumes:
#      - files:/mnt/files

   pma:
    image: phpmyadmin/phpmyadmin
    container_name: "${PROJECT_NAME}_pma"
    environment:
      PMA_HOST: $DB_HOST
      PMA_USER: $DB_USER
      PMA_PASSWORD: $DB_PASSWORD
      PHP_UPLOAD_MAX_FILESIZE: 1G
      PHP_MAX_INPUT_VARS: 1G
    labels:
      - 'traefik.backend=pma'
      - 'traefik.port=80'
      - 'traefik.frontend.rule=Host:pma.${PROJECT_BASE_URL}'

#  athenapdf:
#    image: arachnysdocker/athenapdf-service:$ATHENAPDF_TAG
#    container_name: "${PROJECT_NAME}_athenapdf"
#    environment:
#      WEAVER_AUTH_KEY: weaver-auth-key
#      WEAVER_ATHENA_CMD: "athenapdf -S"
#      WEAVER_MAX_WORKERS: 10
#      WEAVER_MAX_CONVERSION_QUEUE: 50
#      WEAVER_WORKER_TIMEOUT: 90
#      WEAVER_CONVERSION_FALLBACK: "false"

#  blackfire:
#    image: blackfire/blackfire
#    container_name: "${PROJECT_NAME}_blackfire"
#    environment:
#      BLACKFIRE_SERVER_ID: XXXXX
#      BLACKFIRE_SERVER_TOKEN: YYYYY

#  solr:
#    image: wodby/solr:$SOLR_TAG
#    container_name: "${PROJECT_NAME}_solr"
#    environment:
#      SOLR_HEAP: 1024m
#    labels:
#      - 'traefik.backend=solr'
#      - 'traefik.port=8983'
#      - 'traefik.frontend.rule=Host:solr.${PROJECT_BASE_URL}'

#  elasticsearch:
#    image: wodby/elasticsearch:$ELASTICSEARCH_TAG
#    environment:
#      ES_JAVA_OPTS: "-Xms500m -Xmx500m"
#    ulimits:
#      memlock:
#        soft: -1
#        hard: -1

#  kibana:
#    image: wodby/kibana:$KIBANA_TAG
#    depends_on:
#      - elasticsearch
#    labels:
#      - 'traefik.backend=kibana'
#      - 'traefik.port=5601'
#      - 'traefik.frontend.rule=Host:kibana.php.docker.localhost'

#  node:
#    image: wodby/node:$NODE_TAG
#    container_name: "${PROJECT_NAME}_node"
#    working_dir: /app
#    labels:
#      - 'traefik.backend=node'
#      - 'traefik.port=3000'
#      - 'traefik.frontend.rule=Host:front.${PROJECT_BASE_URL}'
#    expose:
#      - "3000"
#    volumes:
#      - ./path/to/your/single-page-app:/app
#    command: sh -c 'npm install && npm run start'

#  memcached:
#    container_name: "${PROJECT_NAME}_memcached"
#    image: wodby/memcached:$MEMCACHED_TAG

#  opensmtpd:
#    container_name: "${PROJECT_NAME}_opensmtpd"
#    image: wodby/opensmtpd:$OPENSMTPD_TAG

#  rsyslog:
#    container_name: "${PROJECT_NAME}_rsyslog"
#    image: wodby/rsyslog:$RSYSLOG_TAG

#  xhprof:
#    image: wodby/xhprof:$XHPROF_TAG
#    restart: always
#    volumes:
#      - files:/mnt/files
#    labels:
#      - 'traefik.backend=xhprof'
#      - 'traefik.port=8080'
#      - 'traefik.frontend.rule=Host:xhprof.${PROJECT_BASE_URL}'

   portainer:
    image: portainer/portainer
    container_name: "${PROJECT_NAME}_portainer"
    command: --no-auth -H unix:///var/run/docker.sock
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    labels:
      - 'traefik.backend=portainer'
      - 'traefik.port=9000'
      - 'traefik.frontend.rule=Host:portainer.${PROJECT_BASE_URL}'

   traefik:
    image: traefik
    container_name: "${PROJECT_NAME}_traefik"
    command: -c /dev/null --web --docker --logLevel=INFO
    ports:
      - '8000:80'
#      - '8080:8080' # Dashboard
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

volumes:
## Docker-sync for macOS users
  docker-sync:
    external: true
## For Xdebug profiler
#  files:

composer.json

{
  "name": "wodby/wordpress-composer",
  "description": "Project template for WordPress projects with composer",
  "type": "project",
  "license": "GPL-2.0+",
  "authors": [
    {
      "name": "",
      "role": ""
    }
  ],
  "repositories":[
    {
      "type":"composer",
      "url":"https://wpackagist.org"
    }
  ],
  "minimum-stability": "dev",
  "prefer-stable": true,
  "config": {
    "sort-packages": true
  },
  "require": {
    "composer/installers": "^1.2",
    "drupal-composer/preserve-paths": "0.1.*",
    "johnpbloch/wordpress-core": "~4.9",
    "johnpbloch/wordpress-core-installer": "^1.0",
    "vlucas/phpdotenv": "^2.5"
  },
  "extra": {
    "installer-paths": {
      "web/wp-content/plugins/{$name}/": ["type:wordpress-plugin"],
      "web/wp-content/themes/{$name}/": ["type:wordpress-theme"]
    },
    "preserve-paths": [
      "web/wp-config.php",
      "web/wp-content/uploads"      
    ],
    "wordpress-install-dir": "web"
  }
}

Question: What is the intended method to use with docker4wordpress

Looking at the docker4wordpress stack, I see that the php image has composer and wp-cli already installed. However, if I bind mount just the web directory, composer will not have access to the composer.json. But if I were to mount the whole wordpress-composer project, then those files are in the web root and served by nginx, which is not ideal.

For local development on my mac, installing php and composer is simple enough. But I would also like to experiment with developing inside a virtual machine such as vagrant where I will not have php and composer available on the base system. For that use case I currently see two approaches but if there is another, please advise:

  1. Launch another php container that bind mounts to the wordpress-composer directory. Use this container to run composer install.
  2. Bind mount php container to /var/www and change web to html in wordpress-composer. Nginx container would be bind mounted to /var/www/html. Not sure how well that would work.

Thank you, and awesome work as always.

Stable Release?

After reviewing all the composer install projects for WordPress this is the most stable project that follows Composer best practices most closely that I've found. How do you feel about creating a release so we can run composer create-project without --stability dev?

What bugs or issues need fixing before we can create a release?

Improvements

As I already said I find this template by far the best Composer template for WordPress. It doesn't produce any overhead and keeps the WordPress file structure as original as possible. So, yeah I really like it and will definitely take this as my base from now on. And that's also the point where I'm wondering if you are open for any improvements.

Nothing dramatic. Just requiring wp-cli/wp-cli for example, or pre-configuring "bin-dir": "bin/" and maybe even add some initial ScriptHandler.php (although I'm not sure what it could do for now except copying the wp-config-sample.php). More or less all in direction of the https://github.com/drupal-composer/drupal-project template. (I'm also currently working on a drush-launcher equivalent for wp-cli and hope to get it released beginning next week).

I'm totally fine if you reject. It's just I'd prefer to contribute to this repo instead of forking it and start just another template (there are too much different WordPress templates out there already IMHO). And I also find that your template deserves more attention, and maybe these improvements can help :)

Composer create-project

Hey hey, so far this is my favorite WordPress Composer template due to its simplicity. Is there any reason this project didn't got published on https://packagist.org?

Would be really nice to simply be able to use composer create-project wodby/wordpress-composer my-directory to initiate a project instead of needing to clone this repo and then need to purge and re-initiate Git.

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.