Hack an apt-get style installer into Cygwin

As you’ll probably know, you can install a bunch of plugins into Cygwin, but only during installation. Do the following to make life easier for yourself.

After installation, copy the setup executable into the cygwin folder.

Create install-pkg.bat with the following contents:

setup-x86_64.exe --no-desktop --no-shortcuts --no-startmenu --quiet-mode --root "%cd%" --packages %*

Now you can cd into /cygdrive/c/cygwin64 and install a package like so:

$ ./install-pkg.bat wget 

Install your composer package somewhere outside vendor

And I don’t mean change the vendor folder name, that’s easy. I mean getting one package in a custom location, whereas the rest still go into vendor.

This will only work with packages that require composer/installers, so if it isn’t your own package and they don’t require that in, then you can stop reading.

Still here? Awesome. In your vendor package, you need to add the installer

composer require composer/installers

Now in your composer.json, change (or add) the type. The package we just required in is actually to help various CMS’es and frameworks, so you must supply a valid type. Thankfully, it doesn’t matter which we choose, as we override the install path anyway.

"type": "ppi-module",

Commit that, and then go to your main project. In the composer.json, add the following:

"extra": {
"installer-paths": {
"/some/custom/path": ["your/package"]
}
}

Now when you run composer install, you’ll see everything but your package in the vendor folder, and your custom package in its custom location! 😀

Installing Ansible

Ansible is a bit like puPHPet, in that it provisions Vagrant boxes etc. My latest project is using PPI Framework 2, and provisions with Ansible, so I had to get everything installed.

Essentially we just clone from the Github repo and install a few python things:

$ git clone git://github.com/ansible/ansible.git --recursive
$ cd ansible
$ source hacking/env-setup
$ sudo easy_install pip
$ sudo pip install paramiko PyYAML Jinja2 httplib2 six

And that should be you. Run ansible from the terminal in ay folder now and you should get all the available options etc. Have fun!

Installing Memcached on CentOS with PHP Memcache

So I pushed my changes to the production repository, only to discover that Memcache wasn’t installed on the server at work (a cPanel installation running over CentOS(6 i think)). Time to install it then!

in the terminal, get memcached installed. Nice n easy.

sudo yum install memcached

Then launch it!

memcached -d -u nobody -m 512 -p 11211 127.0.0.1

Then install memcache PHP extension. You do this in cPanels WHM. Search module installers in WHM

In Find a PHP Pecl, type memcache, and get it installed! You may or may not have to restart apache, but go to a phpinfo() and you should now see it running on your system!

See my previous post for how to use memcache in your PHP 🙂

Run Composer installed binaries globally

cd-ing into a directory then running ./command, or worse yet, php command.php, sucks!
As an example, I wanted to run the doctrine command from anywhere.
I already have composer installed globally, and no longer have to type php composer.phar, but I haven’t blogged it since it was pretty easy, but anyway here it is:

curl -sS https://getcomposer.org/installer | php
 sudo mv composer.phar /usr/local/bin/composer

Then you can just type composer from anywhere. If you already have composer you should run sudo composer self-update. Anyway on to our php binaries (Doctrine, PHPUnit, Behat, you name it). If it’s a fresh install of composer you should see when you type composer global install:

Composer could not find a composer.json file in /home/username/.composer

Now we know where we can create our composer.json. Go to the sites for the packages you would like and copy paste the require field info; Here is Doctrine’s:

{
    "require":
    {
       "doctrine/dbal": "2.3.4",
       "doctrine/orm": "2.3.5"
    }
}

Now run composer global install and it will install in /home/username/.composer/vendor. The bin folder is inside that. Lastly we need to have our bin path set in our PATH environment variable, so the system knows to check that folder for a binary matching the command’s name. edit ~/.bashrc (it could be .bash_profile or something similar). At the end, paste this in:

export PATH=$PATH:/home/username/.composer/vendor/bin

now exit the shell and open a new terminal up and log back in. you can now type doctrine into the command line and lo and behold, your composer executables are rocking!