“the j stands for Jerguer”
about me | research blog | wordpress plugins | jQuery plugins

27 October, 2016

Fixing Apache, PHP and Homebrew after upgrading to macOS Sierra

Apache

As usual, the OSX/macOS update will delete your move your old config file.
I start with the new one and make the changes I want.
In /etc/apache2/httpd.conf, uncomment the following:

LoadModule rewrite_module libexec/apache2/mod_rewrite.so

And set AllowOverride All for <Directory "/Library/WebServer/Documents">

Homebrew

To avoid the PEAR/PECL nightmare from last time, I want to use the Mongo PHP driver from Homebrew.

First, update to XCode 8 from App Store (4GB+ download!)
Then do this to read and agree to the license:

xcode-select --install
sudo xcodebuild -license

Homebrew then gives me a warning about the permissions of /usr/local, which are fixed with this:

sudo chown -R $(whoami) /usr/local

BUT this is slightly desctructive. We need this for MySQL:

sudo chown -R _mysql:wheel /usr/local/mysql/data

Using Homebrew’s PHP and PHP-Mongo extension

We’re going to use Homebrew’s PHP rather than the system one.

brew install homebrew/php/php56 --with-apache

This apparently installed httpd24, but I want to use the system’s Apache, so:

brew unlink httpd24

Then tell the system Apache use the Homebrew PHP. In /etc/apache2/httpd.conf:

LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so

Some minor configuration for our Homebrew PHP.
In /usr/local/etc/php/5.6/php.ini:

date.timezone = "Europe/Stockholm"

Then we install the Mongo driver (note I want the old mongo, not the newer mongodb) with:

brew install homebrew/php/php56-mongo

Finally restart Apache:

sudo apachectl restart

21 November, 2015

Fixing Apache, PHP, Pear and Haskell Platform after upgrading to OSX El Capitan

Another OSX upgrade, another long list of things that need to be manually fixed afterwards. This time it was even worse than the Mavericks upgrade.

Enable mod_rewrite and PHP in Apache

Uncomment the following lines in /etc/apache2/httpd.conf:

LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php5_module libexec/apache2/libphp5.so

Also set AllowOverride All for <Directory "/Library/WebServer/Documents">.
Restart apache with:

sudo apachectl restart

PHP

I started with a fresh config file:

sudo cp -a /etc/php.ini.default /etc/php.ini

Then added timezone information:

date.timezone = "Europe/Stockholm"

Turn off SIP

  1. Reboot into recovery mode by pressing Command + R before the apple logo appears.
  2. Open up a terminal
  3. csrutil disable; reboot

Install PEAR & PECL Mongo driver

Install PEAR:

cd /usr/lib/php
sudo php install-pear-nozlib.phar

Then add this to php.ini:

include_path = ".:/usr/lib/php/pear"

Install XCode Command Line tools with:

xcode-select --install

Next I needed to install openssl through Homebrew. This took a few steps:

sudo chown -R $(whoami):admin /usr/local
sudo chown -R _mysql:wheel /usr/local/mysql/data
brew update
brew install openssl
brew link --force openssl

Before I could build the extension I also needed this (source):

cd /usr/local/lib
sudo ln -s ../../lib/libSystem.B.dylib libgcc_s.10.5.dylib

Finally I installed the PECL Mongo driver (legacy) with:

sudo pecl install mongo

Then enable in php.ini by adding:

extension=mongo.so

And of course restart Apache again.

Haskell platform

I needed to recreate symlinks to Haskell platform programs inside /usr/local/bin.
This Stack Overflow answer explains how I did that.

Edit: After doing the above, GHC worked but whenever I tried to install anything in cabal I would get the error /usr/bin/ar: permission denied. After a lot of messing about, I had to clear everything Haskell-related and start over:

rm -rf ~/.cabal
rm -rf ~/Library/Haskell
sudo /Library/Haskell/bin/uninstall-hs all --remove
brew uninstall ghc cabal-install

And remove /Users/john/.cabal/bin from my path.
Then I installed GHC 7.10.2 and cabal from Homebrew and that seemed to work:

brew install ghc cabal-install

And add /Users/john/.cabal/bin back to my path.

Turn on SIP

Finally I turned SIP back on:

  1. Reboot into recovery mode again
  2. Run the following in a terminal: csrutil enable; reboot

21 October, 2014

Fix Apache & PHP after upgrading to OSX Yosemite

After waiting all night for OSX Yosemite to install, I finally booted into the new version of the OS… to find that Apache and PHP were no longer configured. Great. I remember a similar thing from the Mavericks update, so here is a list of the steps I followed to get things working again. Your results may very, but this may at least help.

  1. First you need to sort out the Apache config file /etc/apache2/httpd.conf, which has been reset to some default. Your old config file will be in the same directory, with some suffi like ~previous or .pre-update. In my case, I re-un-commented these lines:
    LoadModule rewrite_module libexec/apache2/mod_rewrite.so
    LoadModule php5_module libexec/apache2/libphp5.so

    I also needed to change AllowOverride None to AllowOverride Any in the <Directory "/Library/WebServer/Documents"> section.

  2. Then turn on Apache:
    sudo apachectl restart
  3. PHP’s config file has also disappeared, but again your old ones will be in /etc/ with some suffixes as above. In my case I started fresh with:
    sudo cp -a /etc/php.ini.default /etc/php.ini

    The only thing I added was:

    date.timezone = "Europe/Stockholm"

    Restart Apache again.

  4. Now I need to install PEAR. Clear anything named pear in your home directory, then:
    cd /usr/lib/php
    sudo php install-pear-nozlib.phar

    Then add the path where PEAR installed to php.ini:

    include_path = ".:/usr/lib/php/pear"
  5. I wanted to install the Mongo PECL package, which apparently requires the Command Line Tools, so:
    xcode-select --install

    And then finally I can install it:

    sudo pecl install mongo

    Add the following line to /etc/php.ini:

    extension="mongo.so"

    Then restart Apache one more time.

6 November, 2010

Fuzzy string matching in MySQL using Levenshtein Distance stored function

Searching for fuzzy string matching methods will return various algorithms and various implementations of them.

I found this MySQL implementation of Levenshtein Distance to be adequate for my needs, and using this handy MySQL stored function makes it super as to use in queries without having to create temporary search-optimised tables or performing post-processing in another language (eg PHP).

Just install the functions in your database, and use like so:

SELECT * FROM users ORDER BY levenshtein_distance(users.name, 'john')

4 January, 2010

WordPress NextGEN Gallery – Thumbnail Generation PHP Memory Limit

The name says it all, if you use NextGen Gallery and have problems with GD thumnbnail generation, you might want to consider upping the PHP memory limit. You probably already suspected it, and it can be done by simply uncommenting one line of code.

Link here: Thumbnail Generation PHP Memory Limit NextGEN Gallery ยป Visser Labs.

19 November, 2009

Empty / blank page for large posts with WordPress

So I was having this problem where WordPress would display a blank editor for large posts when viewing visual mode. I could get it to work by using the HTML view and refreshing the page, but never in visual mode.

Anyway turns out to be the result of some modest PHP pcre regex defaults. Thankfully all it took was changing a few setting in PHP.ini. A bit thanks to the following blog post, which turned a nightmare of a bug to find into a quick and easy fix.

Sudden empty / blank page for large posts with WordPress | Under My Hat.