Jump to content


composer.json files for installing apps automatically

composer wordpress

  • Please log in to reply
2 replies to this topic

#1 entheologist

  • Members
  • PipPip
  • Member
  • 11 posts

Posted 07 August 2014 - 12:43 AM

I like to set up websites for people who don't have the know how to do it themselves, I mainly set them up wordpress sites cuz thats pretty easy for them to modify and maintain themselves. To save myself time, I decided to learn how to do it with Composer (what a brilliant tool that it). Can anyone who uses composer for this kinda thing, can you post your composer.json files here. Also, if anyone can show me a better way of doing things, it'd be much appreciated. Heres the one I made:

    "name": "acme/brilliant-wordpress-site",
    "description": "My brilliant WordPress site",
    "require": {
        "johnpbloch/wordpress": ">=3.8.0",
    "extra": {
	"installer-paths": {
		"mysite": ["johnpbloch/wordpress"],
		"mysite/wp-content/plugins/{$name}": ["type:wordpress-plugin"],
		"mysite/wp-content/themes/{$name}": ["type:wordpress-theme"]
    "autoload": {
        "psr-0": {
            "Acme": "src/"

I think I'm doing this in a silly way though. I read about these composer installer things on github, but I didn't figure out how to use them so instead I used the installer-paths key to make the autoloader put the files in the right place. Heres a composer.json file I found which is better cuz it uses a post installation script:

    "require": {
        "wordpress/core": "3.5.2",
        "wordpress/twentytwelve": "1.1",
        "wordpress/akismet": "2.5.7",
        "wordpress/google-sitemap-generator": "3.2.9",
        "wordpress/google-analytics-for-wordpress": "4.3.3",
        "wordpress/wordpress-importer": "0.6.1"
    "repositories": [
            "type": "composer",
            "url": "https://raw.github.com/wordpressoncomposer/composer-repository/master/"
            "type": "vcs",
            "url": "https://github.com/wordpressoncomposer/installer"
    "scripts": {
        "post-install-cmd": "Wordpress\\Composer\\InstallerTasks::wpConfig"
    "extra": {
        "wordpress_coredir": "wordpress/core",
        "wordpress_wp_contentdir": "wordpress/wp-content",
        "wordpress_wp_config": {
            "site_url": "http://localhost",
            "db_host": "localhost",
            "db_user": "root",
            "db_pass": "",
            "db_name": "wordpress"
    "minimum-stability": "dev"

I'm gonna start using these scripts once I figure out how to use them. Where are the scripts stored? I haven't a clue what this autoload thing is all about either, is it a tool for moving files into the appropriate directories? See how the first file gets wordpress from packagist, and the second one gets it from github. Is there a difference? If I was to add that post-install-cmd key to the first composer.json file, would it still work? In other words, do both repositories contain identical packages.

#2 gizmola

  • Administrators
  • Advanced Member
  • 4,610 posts
  • LocationLos Angeles, CA USA

Posted 07 August 2014 - 06:05 AM

Packagist is the default directory for packages, that composer reads. It's basically a way of redirecting composer to the location of the actual source. Mostly, people are putting the source for their projects in github, but that is not a requirement for composer to work. Unless over-ridden in the repositories section, composer is going to utilize packagist to figure out where the source for a package is located.

However, composer also supports the installation of packages that aren't in packagist and/or github. This is what the repositories section is for -- things that aren't in packagist or are meant to override a default.

Composer also builds the autoloader for the php application it is installing, so that the various libraries can be found and autoloaded. You can read more about the concept behind php autoloaders in the namespace era, by googling for PSR-0.

As for the composer event hooks like post-install-cmd, take a look at this article: http://www.sitepoint...mposer-scripts/

#3 trq

  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 08 August 2014 - 01:33 AM

The problem that you are having is that apps like wordpress weren't designed with composer in mind. So, they need special custom scripts.

A better solution would be for wordpress to catch up to the rest of the php world and start using composer. Of course, that isn't really likely because their entire application is not modular (nor oop), so it doesn't really fit the "package" mentality.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users