Use Homebrew PHP with Mac OS X built-in Apache

To use the version of PHP you installed with Homebrew, you will need to change the PHP extension that Apache is loading. If you are using the built-in version of Apache this will use the built-in version of PHP even after you have installed PHP with brew.

brew install php56

You need to edit the Apache config file /etc/apache2/httpd.conf and search for libphp5.so

vim /etc/apache2/httpd.conf

Then change this to point to the new brew PHP extension

#LoadModule php5_module libexec/apache2/libphp5.so
LoadModule php5_module [new-extension]

The location of the new brew PHP extension will differ depending on your setup, but you will be able to find it using brew

brew info php56

Use CORS for REST API via XDomain proxy in IE8, IE9 for JavaScript/Angular

Because Internet Explorer 8 and 9 don’t support CORS properly (no custom headers such as an API key, only GET/POST, etc.) you may have problems using a modern REST API. However Jaime Pillora came up with a great solution called XDomain which acts as a pure JavaScript proxy for your API calls to get around CORS. This will only work if you have control over both the API you’re consuming and the JavaScript application.

Put this page in the web root of your API…

All you need to do to get this setup is to make sure you include it before any other JavaScript (such as Angular or jQuery) that will use IE’s XDomainRequest, as it will act as a drop-in replacement for it.

Your application would then look something like this…

Using BrowserStack or Modern.ie with the (limited) IE developer tools you will either see some debug messages from XDomain, or if you see “Access Denied” it will be because XDomain can’t connect to your proxy page (check the http/https protocols match and that the page is accessible on your API from where your JavaScript application is hosted)

Using strings in SQL select clause in CodeIgniter DB helper

If you need to use literal strings in your select clause (such as a date format) using the CodeIgniter DB helper, you will need to pass false as the second parameter

$this->db->select(
    'DATE_FORMAT(date, "%Y-%m-%d") as something_date', 
    false
);

Quick way to enable MySQL General Query Log without restarting

If you want to quickly enable the MySQL General Query Log without restarting MySQL Server, you can run these couple queries to start outputting all queries to a file located on disk

You can then run a command like “tail -f /var/log/mysql/all.log” to see the queries appear as your application runs. Note never enable this on anything other than a development environment, and make sure to turn it off once you are finished debugging or the disk will fill up

How to solve file exceeds GitHub’s file size limit of 100 MB

You may encounter a problem with GitHub if you are using it as a new remote (or a pull request for a different remote) whereby a file in the history is over 100MB. This means that although your working copy doesn’t have the file, it was there at some point in time

remote: error: File dump.sql is 221.82 MB; this exceeds GitHub's file size limit of 100 MB

Therefore you will need to find out where in the history the file exists, and rewrite history so that it doesn’t. Thus you will need to git rebase and remove them.

First find out which commits the file exists in

git log --all -- dump.sql

Then check which files were touched in each of those commits (for each commit)

git show --name-only xxxx

This gets slightly complicated if the commits contain other modified files, otherwise you may need something like David Underhill’s script

Then if you rebase from the commit before the one you need to remove. An easy way to do this is to use an interactive rebase

git log
git rebase --i xxxx

You may end up with commits that deleted the file later, which are now empty so would effectively not be required. You can keep them as part of the history using

git commit --allow-empty
git rebase --continue

You should then have a copy of your repository with that file no longer present. As mentioned this is simple way to do it, but if you need to untangle a file from larger commits you may need the script linked above

Example of how to use Symfony Config component standalone

Whilst there is some good documentation on the Symfony Config component there isn’t an obvious example to get you started. Here is a simple way (there is much more you can do) to get started using the component as a standalone, without Symfony for example.

Selenium Server on your desktop controlled by Virtual Machine/remote server via SSH tunnel

If you are running your development environment on a virtual machine (whether by Vagrant, a custom local Virtual Machine or a server elsewhere in vSphere or in the cloud) you may want to run Selenium tests on your code, but have no way to do it as your development environment is headless. On the other hand, you have Selenium Server on your desktop/workstation, but it does not have the software installed to run your application.

You can create a reverse SSH tunnel from your development environment to your desktop/workstation, so that your tests execute on your development environment, but Selenium runs on your desktop/workstation.

To get this to work, first download Selenium Server and make sure Selenium Server is running on your desktop (this assumes on the standard port 4444) via something like this

java -jar selenium-server-standalone-2.40.0.jar

Then create a reverse SSH tunnel to your development environment (hostname)

ssh -R 4444:localhost:4444 hostname -l username

This will route any traffic on port 4444 on your development environment back to your desktop, which is this case is to Selenium Server. If this is working, if you still have the terminal open where you ran Selenium Server you should see some output when the commands are being triggered

Delete directories only and not files in a directory on Linux

If you need to delete all the directories only and not files in a directory in Linux, you can do it with the “rm -r */” command

Icinga Web, Could not send command. Check if your webserver’s user has correct permissions for writing to the command pipe.

If you are getting this error when trying to perform actions on services or hosts in Icinga Web, most forum posts point to the configuration being correct, etc.

Firstly make sure that the command pipe referenced in access.xml points to a valid place, and has icinga-cmd:icinga ownership

vim /usr/local/icinga-web/app/modules/Api/config/access.xml
<!-- allowed to be written to -->
  <write>
    <files>
      <resource name="icinga_pipe">/var/spool/icinga/cmd/icinga.cmd</resource>
    </files>
  </write>
ls -l /var/spool/icinga/cmd/

Note: This example is from CentOS, your path(s) may vary

Then, which is much more likely the reason it does not work, is make sure you have not got SELinux preventing Apache from executing commands through the command pipe

Easiest way to test this is to temporarily change SELinux to permissive mode and try the action in Icinga Web again

setenforce Permissive

Note: Leaving SELinux in permissive mode is not recommended, please add a rule as necessary

Newer posts
Older posts