“the j stands for Joyless”
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.

25 July, 2010

Enabling compression with GoDaddy Shared Hosting

Compression of HTML, CSS and JavaScript is quite important for improving your site’s speed and should always be used.

Of you will find that all you need to do is add a line similar to the following to your .htaccess file:

AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml application/x-javascript text/javascript application/javascript
Source: StackOverflow

However, if you’re on a GoDaddy shared hosting account you may have realised that this doesn’t work. GoDaddy’s help page recommends that you paste this code in all your PHP pages:

<?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>

That’s fine, but from my understanding this will not cache your CSS or JavaScript. However, I found a solution here here, which involves some .htaccess trickery to compress all your CSS and JavaScript files automatically. Enjoy!