Archive for category Zend Framework

Pear not working with MAMP

When running the version of Pear that comes with MAP you may get the following:

Notice: unserialize(): Error at offset 267 of 1133 bytes in Config.php on line 1050
ERROR: The default config file is not a valid config file or is corrupted.

The solution is to delete the conf file, located here (path may vary slightly):
/Applications/MAMP/bin/php/php5.3.6/conf/pear.conf

That’s it.

     

No Comments

PHP Debugging in Chrome with ChromePHP

Easy PHP console logging in Chrome (similar to FirePHP in Firefox).

  1. Download the ChromePHP Extension (you will click this extension “on” when you want to use ChromePHP).
  2. Download the ChromePHP class itself and stick it in your path (example: /Applications/MAMP/bin/php5.3/lib/php/ChromePhp.php).
  3. (a most critical step that is not made clear in the ChromePHP install instructions) Create a place for ChromePHP to store log files: mkdir /Applications/MAMP/htdocs/chromephplogs
  4. Start logging:

    include 'ChromePhp.php';
    ChromePhp::useFile('/Applications/MAMP/htdocs/chromephplogs', '/chromephplogs');
    ChromePhp::log('hello world');
    ChromePhp::log($_SERVER);

    // using labels
    foreach ($_SERVER as $key => $value) {
    ChromePhp::log($key, $value);
    }

    // warnings and errors
    ChromePhp::warn('this is a warning');
    ChromePhp::error('this is an error');

Notice the use of ChromePhp::useFile() in the above code… this is critical as ChromePhp simply will not work correctly without it. useFile() accepts 2 arguments… here is the code itself:

/**
* this will allow you to specify a path on disk and a uri to access a static file that can store json
*
* this allows you to log data that is more than 4k
*
* @param string path to directory on disk to keep log files
* @param string url path to url to access the files
*/
public static function useFile($path, $url)
{
$logger = self::getInstance();
$logger->addSetting(self::LOG_PATH, rtrim($path, '/'));
$logger->addSetting(self::URL_PATH, rtrim($url, '/'));
}

     

1 Comment

OpenVPN Setup tips

To send all traffic over an established VPN connection:

sudo iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
sudo -s echo “1″ > /proc/sys/net/ipv4/ip_forward
sudo openvpn /etc/openvpn/server.conf

     

2 Comments

SSH Tunneling Tips: Now With More Awesome!

OK, that previous tip was pretty weak. Try this instead. Set up a SOCKS proxy and tunnel it through SSH!

Here’s how:

1. Open the SSH connection…
ssh -ND 8887 -p 22 rufus@83.27.411.896

2. Set your network to point to the proxy. On a Mac that would be…
a. Open Network Preferences…
b. Click Advanced…
c. Click Proxies…
d. Check the SOCKS Proxy box then in the SOCKS Proxy Server field enter localhost and the port you used (8887)
e. OK and Apply and you are done!

p.s. Bonus! You can enable gzip compression by setting the -C flag (ex. ssh -C -ND 8887 -p 22 rufus@83.27.411.896)

     

No Comments

SSH Tunneling Tips

To tunnel one, single website over SSH:
ssh -L 8887:google.com:80 -p 22 -l rufus -N 83.27.411.896

Explanation:

The first port, 8887, is the one on your local machine that you are going to point your proxy to….
… next comes the website you are visiting…
… next is the port of the service on the remote computer you will be accessing
Web: HTTP 80
Web over SSL: HTTPS 443
Outgoing email: SMTP 25
Incoming email: POP3 110
Incoming email: IMAP 143

… next comes the port your SSH is set to (default is 22)…
… next is the user you will log in as…
… next is the address of the ssh server you are accessing.

That’s it. But you only gain access to Google. Try to go outside of that and you will get sent back to Google.

     

No Comments

Mercurial – pushing changes to a remote site

OK, this was not straight forward but it was mainly because of paths and permissions issues.

My local repository is here: /Applications/MAMP/htdocs/aproj/

On the remote machine I need to get a copy of this so I issue the following:
sudo hg -v clone ssh://me@192.168.1.107//Applications/MAMP/htdocs/aproj/ /var/www/aproj/
This will clone the repository.

After making changes I try to push them from the local repo to the remote server using:
sudo hg push ssh://me@192.168.1.105//var/www/aproj/

but this will fail with the error:
remote: Not trusting file /var/www/aproj/.hg/hgrc from untrusted user root, group root
remote: Not trusting file /var/www/aproj/.hg/hgrc from untrusted user root, group root
remote: abort: could not lock repository /var/www/aproj/: Permission denied
abort: unexpected response: empty string

This stems from the local repo having different owner (and group?) from the remote.

I can, however, do a pull from the remote repo (note I am inside var/www/aproj/:
sudo hg pull

Then update to implement the pulled changes:
sudo hg update

and that gets things working for the time being.

One really weird thing I ran into. on the local machine I can issue a command to mercurial with no problem. For example:
hg info
However, doing that via ssh from the remote server failed with the message that ‘hg could not be found’. The path to hg was set correctly (as evidence by ‘echo $PATH’) but I still had to symlink hg from /usr/bin/ in order to get it to work (from the remote machine… it worked fine locally).

Update: how to fix the untrusted user error… in your .hgrc add:
[trusted]
users=*
groups=*

     

2 Comments

Enable Color in Mac OS X Terminal

Want to colorize your ls output in Terminal? Stick this in your ~/.bashrc or ~/.bash_profile files:

export CLICOLOR=1

While you are at it add this alias to include invisible files in ls:
alias ls='ls -la'

Oh! One more useful one… to reload your .bash_profile without quitting and restarting the shell:
source ~/.bash_profile

     

No Comments

The iTunes Window Extends Off Screen and I Can’t Resize It, Help!

So you thought you could click the little plus button at the window’s top left corner (the green one unless you use the alternate Mac color scheme) to resize and you discovered that that only opens a tiny control panel?

Here is the big secret… hold down the option key while clicking the button with the plus on it at top left. Done! I love easy.

     

No Comments

Wrap many lines of text in list item tags using RegEx

So I have an email with a huge list of names. They are displayed one per line. I want to wrap them in list item tags so I can stick them in an unordered list. Here is how to do it fast and painlessly…

First, here is what I start with (just imagine 1000 names, rather than 3):

Bob Smith, Acme Corp, CEO
Janet Johnson, Barton Inc, VP for Development and Shoe Sizes
Cat Sims, Transmo Inc, VP of Conference Room Chair Height Adjustments

Here is the regex I will find and replace with:
Find:

(.*)\r

Replace (pretend that last “\r” is right next to the list item closing tag:

  • \1
  • \r

    The find code looks for anything with a carriage return at the end and then grabs the bit in the parenthesis.
    The replace code wraps that bit in the parenthesis (signified by the \1), wraps it in list item tags and sticks a carriage return on the end.

    Now my list looks like:

  • Bob Smith, Acme Corp, CEO
  • Janet Johnson, Barton Inc, VP for Development and Shoe Sizes
  • Cat Sims, Transmo Inc, VP of Conference Room Chair Height Adjustments
  •      

    No Comments

    Basic secure file copying using SCP

    Securely copy a file from one computer to another (in this example on my local network):
    $ sudo scp stuart@192.168.1.100:Downloads/somefile.iso /home/stuart/downloads

    This will copy the file somefile.iso that is in my remote computer’s home dir’s Download directory ~/Downloads/ or put another way as the remote computer is a Mac /Users/stuart/Downloads/ over to the local computer’s dir at /home/stuart/downloads/

         

    No Comments