Create diff patch from Composer /vendor to apply to Git repository

If you’ve accidentally made changes to a package in the /vendor directory of your project, you’ll need to apply these same changes to the Git repository that the package comes from (or fork it and patch it, etc.) before Composer overwrites the updates.

The easiest way to do this is to create a diff patch which you can then apply to the package repository. You need to make sure it’s relative to the package root for when you apply the patch.

cd vendor/PackageName/
git diff > changes.diff

Then go into the Git repository (or fork) of the package and apply the patch.

cd RepositoryName/
git apply --ignore-space-change --ignore-whitespace changes.diff

Late Static Binding namespace resolution in PHP

If you try to get the namespace of the child class that you are in using the __NAMESPACE__ keyword, you will have the same problem that you do using functions like get_class() in that you will get the namespace (or class) where the current method you are calling is defined.

$namespace = __NAMESPACE__;
$class = get_class();

You can use get_called_class() to resolve this for Late Static Binding with classes, but no such function exists for namespaces that I can find.

$class = get_called_class();

However you can work this out by using the fully-qualified class name, and deducing the namespace from that; if you get the Late Static Binding class name, then you can get the Late Static Binding namespace.

Capistrano website deployment with PHP Composer

Composer is great for handling PHP dependencies, and Capistrano is great for automated deployment, so wouldn’t it be great if you could use them together?

To do this, all you need to do is update your recipe with the following task, then add a hook to make it run when the recipe is used.

To add the hook, make sure that Composer is triggered after finalize_update (which means it will happen before symlink)

after "deploy:finalize_update", "deploy:composer_install"

Then for the task, the simplest solution is to call Composer from the CLI using the Ruby run command.

task :composer_install do
    run "php /var/www/composer.phar install --working-dir #{latest_release}"

This assumes that you have a composer.phar located outside of your repository; you can add it into your repository if you cannot place it anywhere else on the server.

If you need to download composer there are official instructions, or if you are having issues there is troubleshooting information available also.

Disable auto-correct for oh-my-zsh when using Chef Knife (or other commands)

oh-my-zsh is great, but certain commands it doesn’t like, for example the Knife CLI tool for Chef. Luckily it is possible to disable auto-correct as required.

sudo vim ~/.zshrc

To disable just auto-correction for Knife, add the following line somewhere in the configuration

nocorrect knife

To disable all auto-correct (which I prefer personally) add the following line somewhere in the configuration


Output CSV straight to browser using PHP

If you want a user to download a CSV, but do not want to have to generate it on the filesystem first, you can output the CSV directly to the browser by writing it to PHP’s output stream.

If you set the resource for the normal PHP CSV functions as the PHP output stream you can use output buffering to then save it into a string. You can then output this straight to the browser along with the appropriate CSV response headers.

Install Yahoo YUI compressor on Mac OS X, use in terminal

Since there are seemingly no simple guides on how to simply install the YUI compressor on Mac, or how to use it in the terminal (command line) as Yahoo’s instructions are useless, and most other guides show how to use it integrated into a website as an on-the-fly processor; if you’d prefer to compress your assets prior to deployment as opposed to on-the-fly then you’ll need to get YUI working in the terminal so you can use it in a bash script or something similar.

You could get the latest release from GitHub and then have no idea what to do… or just install it via Homebrew, which will fetch, build and install it for you

brew install yuicompressor

You should then be able to just run yuicompressor from the terminal, which will minify 1 or more files you pass as parameters and output them to ther screen. If you want to save these to a file, just pass the output to a file as you would normally

yuicompressor test.css > test.min.css
yuicompressor test.js > test.min.js

PHP Startup: Unable to load dynamic library ‘/usr/lib64/php/modules/’

For some reason (I think just on Red Hat/CentOS) you may end up with a bad reference in mcrypt.ini so “” as opposed to “”

To update this simply edit mcrypt.ini so that it points to the right extension (instead of what I’m assuming is placeholder text)

vim /etc/php.d/mcrypt.ini

You should see the following…

; Enable mcrypt extension module

Change this to…

; Enable mcrypt extension module

This might be the way the extension comes down from RPMForge I’m not sure

Concrete5 “Fatal error: Class ‘View’ not found”

Concrete5 may present you with the confusing error “Fatal error: Class ‘View’ not found”, which looks like a Loader issue but often it is not. When moving between different servers, the database permissions may not be quite right, which will cause this to happen.

If you check that the user that Concrete5 is using has access to the database and the correct credentials, then often this will solve the issue.

There are various reasons why Loader issues occur, but this is a quite common issue (and the error message isn’t very helpful!)

“Could not open configuration file /usr/local/zend/etc/sites.d/zend-default-vhost-80.conf”

If you’ve upgraded from an older version of Zend Server than 5.6 up to 6.0 you may have ended up with a patched httpd.conf that references a vhost configuration file that has not been created. If you try to start Apache you may see this message:

$ sudo apachectl start
httpd: Syntax error on line 428 of \
/usr/local/zend/apache2/conf/httpd.conf: \
Could not open configuration file \
/usr/local/zend/etc/sites.d/zend-default-vhost-80.conf: \
No such file or directory
-e /usr/sbin/apachectl start [FAILED]

This means your Apache configuration has been patched to references the virtual host files, without actually creating them. If you take a look in /usr/local/zend/apache2/conf/httpd.conf it may look like this:

NameVirtualHost *:80
<VirtualHost *:80>
Include "/usr/local/zend/etc/sites.d/zend-default-vhost-80.conf"
Include "/usr/local/zend/etc/sites.d/globals-*.conf"
Include "/usr/local/zend/etc/sites.d/vhost_*.conf"

One way to fix this is to simply copy them down from these Gists:

Newer posts
Older posts