Archive

Archive for the ‘Computing’ Category

PHP IMAP support in Mac OS X Lion without recompiling PHP

November 24th, 2011

OK, so this was a lot harder than it should have been, and I had to use various tutorials to get it working, however I am pleased to say that I finally did get it all working without needing to completely recompile php. Here are the steps:

First, modified from http://blog.xeonxai.com/2009/12/03/160/:

  1. Download IMAP source code (now 2007f).
  2. Extract the tar.gz file (double click it in finder or tar xvzf imap-2007f.tar.gz in terminal)
  3. Then, modified from This Comment on the same xeonxai blog post, do the following to avoid the error:
    "configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information." when executing item 6 in this tutorial.
    cd ~/Downloads/imap-2007f
    make osx EXTRACFLAGS="arch i386 -arch X86_64 -g -Os -pipe -no-cpp-precomp"
    sudo cp c-client/*.h /usr/local/include/
    sudo cp c-client/*.c /usr/local/lib/
    sudo cp c-client/c-client.a /usr/local/lib/libc-client.a
  4. Then download php source. Make sure you get the right source (you can check your php version by the command in the terminal: php -r "phpinfo();" I think OS X Lion standard install is php 5.3.6 which you can download at http://es.php.net/get/php-5.3.6.tar.bz2/from/a/mirror
  5. Unpack php-5.3.6.tar.bz2 (double click it in finder or tar xvzf php-5.3.6.tar.bz2)
  6. In Terminal:
    cd ~/Downloads/php-5.3.6/ext/imap
    phpize
    ./configure --with-imap==/usr/local/imap-2007 --with-kerberos --with-imap-ssl
    make

    At the make command, things will fail. This is the message that I got…
    In file included from /Users/danspencer/Downloads/php-5.3.6/ext/imap/php_imap.c:44:
    /usr/include/php/ext/pcre/php_pcre.h:29:18: error: pcre.h: No such file or directory
    In file included from /Users/danspencer/Downloads/php-5.3.6/ext/imap/php_imap.c:44:
    /usr/include/php/ext/pcre/php_pcre.h:37: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    /usr/include/php/ext/pcre/php_pcre.h:38: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    /usr/include/php/ext/pcre/php_pcre.h:44: error: expected specifier-qualifier-list before ‘pcre’
    make: *** [php_imap.lo] Error 1

    Basically, pcre is not installed, so we need to install this first. See next step!
  7. Modified from http://blog.xavicolomer.com/2011/09/06/osx-lion-and-nginx-installation-tutorial/:
    • Download PCRE from the Sourceforge Project page: http://sourceforge.net/projects/pcre/files/pcre/8.20/pcre-8.20.tar.gz/download
    • Untar the file: tar xvzf pcre-8.20.tar.gz
    • cd to the directory: cd pcre-8.20
    • configure and make: .configure --prefix=/usr/local<br />make<br />sudo make install
    • Successful installation should look like the following in the last couple of lines:
      test -z "/usr/local/include" || ./install-sh -c -d "/usr/local/include"
      /usr/bin/install -c -m 644 pcre.h pcrecpparg.h pcre_stringpiece.h '/usr/local/include'
      test -z "/usr/local/lib/pkgconfig" || ./install-sh -c -d "/usr/local/lib/pkgconfig"
      /usr/bin/install -c -m 644 libpcre.pc libpcreposix.pc libpcrecpp.pc '/usr/local/lib/pkgconfig'
  8. Now you should be able to cd to the imap extension directory in php-5.3.6 source and compile the extension:
    cd ~/Downloads/php-5.3.6/ext/imap
    phpize
    ./configure --with-imap==/usr/local/imap-2007 --with-kerberos --with-imap-ssl
    make
    sudo cp modules/imap.so /usr/lib/php/extensions/no-debug-non-zts-20090626/
  9. Now edit php.ini (sudo vi /etc/php.ini) and add the imap extension in (I added mine around line 990, just under the commented out windows extensions. in vi, you will need to press i to insert text):
    ;IMAP Extension
    extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/imap.so

    After editing, save the file (in vi press esc to exit insert mode, then type “:x”).
  10. now restart apache, and we should be done! sudo apachectl graceful
  11. To test to see if we are up and running, we can do a couple of things…
    • php -r "phpinfo();"
      We should be able to find the following in the output (the modules are in alphabetical order):
      imap

      IMAP c-Client Version => 2007f
      SSL Support => enabled
      Kerberos Support => enabled

    • You can also check to see if the imap functions exist:
      php -r "if(function_exists('imap_open')) { echo 'imap_open exists!'; } else { echo 'imap_open does not exist'; }"
      You should get an output of “imap_open exists”
  12. So that’s it, hope it helps!

    Dan Spencer Computing, OS X , , , ,

Installing libmcrypt + php mcrypt on Mac OS X Lion

October 12th, 2011

Fixing mysql in OS X Lion upgrade

July 20th, 2011

After upgrading to OS X Lion today, MySQL seemed to stop working. In fact, mysql was still running, however there were 2 problems:

  1. php not connecting to mysql server
  2. mysql no longer in path (terminal commands “mysql -u root -p” doesn’t work)

I found the solution for (1) at: http://birdchan.com/home/2011/07/20/osx-lion-mysql-sock-path/
Here is what it says:

  1. shut down your Web Sharing
  2. cp /etc/php.ini.default /etc/php.ini (for some reasons my old php.ini got renamed to php.ini.default…)
  3. modify /etc/php.ini, change /var/mysql/mysql.sock to /tmp/mysql.sock
  4. enable Web Sharing

Or it looks like the file that you want to reinstate is “php.ini-5.2-previous” (had all of my old settings). If you follow the 4 steps above, you will also need to set the timezone in line 998 on you newly created php.ini: “date.timezone = Europe/London”.

To add the mysql into your path just create a file called mysql in /etc/paths.d :
sudo touch /etc/paths.d/mysql
Then add “/usr/local/mysql/bin” to the file using a text editor e.g.
sudo vi /etc/paths.d/mysql

Then I had to reboot.

Dan Spencer Computing, OS X

Apache 2 deflate for file compression

July 4th, 2011

Whilst reading a very good article from the techies at Yahoo, I found out that it would be a good idea to compress certain files on my Apache2 server to reduce the amount of data passed to the browser over the internet.

I found a pretty good article from How2forge at http://www.howtoforge.com/apache2_mod_deflate

I also modified the log output to include a timestamp to distinguish easily between different requests:
DeflateFilterNote Input input_info
DeflateFilterNote Output output_info
DeflateFilterNote Ratio ratio_info
LogFormat '"%t %r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
CustomLog /private/var/log/apache2/deflate_log deflate

The %t in the LogFormat line adds the timestamp.

Note the path to the CustomLog as I am on a Mac.

Dan Spencer Computing

Number of lines in multiple files

July 1st, 2011

The other day I wanted to find out how many lines of code I had written for a particular project. A quick web search through up a useful bit of code in the terminal.
Navigate to the directory that you wish to search and then:
find . -name "*.php" -exec wc -l '{}' \; | awk '{ sum += $1 } END { print sum }'
It will search all files in the directory and sub-directories beneath it.

Dan Spencer Computing

Gmail smtp in codeigniter on WAMP

March 22nd, 2011

I was having real issues getting gmail smtp working on WAMP, using the great php framework Codeigniter. I followed many guides, but kept getting erred when calling the email->send() method. Eventually I worked it out! So here are my steps: Read more…

Dan Spencer Codeigniter, Computing

Installation of Redmine on Ubuntu 10.10

March 12th, 2011

I wanted to install Redmine as a project management / Issue tracker tool on my VPS. The guide that I used was: http://www.redmine.org/projects/redmine/wiki/HowTo_Install_Redmine_in_Ubuntu (using the Passenger install) Read more…

Dan Spencer Computing, Ubuntu

Installation of ftp server on Ubuntu 10.10

March 12th, 2011

This was pretty straight forward, the best instructions were on the Ubuntu website…
https://help.ubuntu.com/10.10/serverguide/C/ftp-server.html

Dan Spencer Computing, Ubuntu

Installation and Setup Subversion Server on Ubuntu 10.10

March 12th, 2011

I wanted my VPS to host Subversion repositories for the projects that I am working on. I followed a number of guides to get the setup that I wanted. the sites are listed directly below for reference: Read more…

Dan Spencer Computing, Ubuntu

Setting up GD library in Ubuntu 10.10

February 24th, 2011

So it turns out that the php5-gd package that ships with ubuntu 10.10 server is not the most up to date version (2.0). After migrating the server over to my new VPS, I couldn’t get my portfolio images working which use gd to do some reflection. After loads of searching online, i found the solution to the problem!
Read more…

Dan Spencer Computing, Ubuntu