How to run PHP with Apache in El Capitan

I’m assuming you like to install PHP 5.6 with MySQL and want something more than MAMP. Good news is that Mac OS X El Capitan comes with Apache so you simply have to configure it.

To begin, you will need Homebrew, if you don’t already have that, install it here.

Installing MySQL and PHP 5.6

After which, install the following packages:

Updating Apache httpd configuration

Next you will need to edit your Apache configuration. Open /private/etc/apache2/httpd.conf for that.

Search for rewrite_module and php5_module.

You have to uncomment them and change them to the following:

Notice that php5_module is referencing the Homebrew version.

Starting the servers

Start MySQL this way:

Start Apache this way (you will need sudo):

Using VirtualHost

If you’re using VirtualHost, you will need to uncomment the following line in /private/etc/apache2/httpd.conf. Search and uncomment this:

Next is to take a look at your VirtualHost file here /private/etc/apache2/extra/httpd-vhosts.conf.

To do that, you will have to do:

This is a sample of my VirtualHost:

Things to note in the above is the directory permissions. It may be different in your use case so be sure to set them properly. My project is using CakePHP is has the DocumentRoot in /Users/kahwee/projects/mcs-portal/web/

How to specify xcode-select for Command Line Tools

This is more of a personal note. It happens when I am install Node.js 0.10.3. It seems like xcode-select is triggered by GYP. I get an error message like this:

I’m on a system that doesn’t have XCode installed fully and instead I just install the Command Line Tools provided by Apple.

To solve this issue, run:

[code lang=”bash”]sudo xcode-select -switch /Library/Developer/[/code]

Then you can now run:

[code lang=”bash”]./configure
sudo make install[/code]

Hope it helps!

Interesting discoveries #08

Less busy this month.

1. Discovering Dev Tools

Google Chrome has one of the best debugging and development tools for the web development. Learn more by trying out the tutorials here. It’s really well down.

2. The Stockdale Paradox

Haven’t heard of this paradox till my director made a brief mention of it. The paradox states that while you must have faith that you will prevail in the end you must also act in a manner where you are aware of the current situation. In times of trouble, it can seem like being in denial while confronting the reality of things.

3. Stephen Fry

This statement makes me feel like tearing:

The strange thing is, if you see me in the street and engage in conversation I will probably freeze into polite fear and smile inanely until I can get away to be on my lonely ownsome. Make of that what you will.
– See more at:

4. Optimism being just as dangerous as pessimism

There’s no difference between a pessimist who says, “Oh, it’s hopeless, so don’t bother doing anything,” and an optimist who says, “Don’t bother doing anything, it’s going to turn out fine anyway.” Either way, nothing happens. –- Yvon Chouinard

This could go real wrong either ways. The key is not to be too extreme in either ends. Know the types but don’t bother too much with the definition for you can’t categorically decide where a person fits.

5. Grunt.js

I’m using more of Grunt.js at work and there’s been a huge gain in productivity. These grunt processes are a little troublesome to set up but once they are there they made web development so much saner.

6. Our broken web development flow

And about sane web development, Kenneth Auchenberg articulated this situation well.

I can’t agree more to that, I’m using a combination of LiveReload, Sublime Text and Grunt’s JSHint plugin to make improve web development process. It is not perfect and there’s some resistance to introducing these workflow to my colleagues at first but they’re seeing the benefits gradually.

7. Shortcat app for Mac

Shortcat’s pretty cool. Get it here. I’ll leave you with a video to look at:

What is Shortcat? from chendo on Vimeo.

8. Dash app for Mac

I’ve been using Dash for Mac. It’s basically offline documentation. It’s great for people who are on the go. How many times do you need to check on something and the internet connection is just horrible or non-existent? This is a life saver for me. It’s a free app but the paid version removes the nag screens.

Dropbox 2.0 in Mac ejects itself

That’s a really nice touch. After installation of Dropbox 2.0 in Mac, it ejects the .dmg for you. I do the usual — you know — after install, eject the .dmg file. I’m pleasantly surprised I don’t have to do that. That’s a great experience you gave me as a user. Although in all good intentions, I wonder does that mean applications can eject my external hard disk should they choose to.

Still it’s a nice touch and I will remember it as that. And the new user interface for Dropbox is amazing too. Kudos there:

Dropbox 2.0

With the recent USD100m acquisition of Mailbox, I am excited to see what’s coming up next.

How to install PHP 5.4 into OS X Mountain Lion

To do so, we are going to get most of the stuff from Jose Gozalez’s formulae. You will need a copy of homebrew installed, you can read about how to install homebrew here.

Let’s start by setting up the dependencies in homebrew.

[code language=”bash”]brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php[/code]

Now php54 is available for install through:

[code language=”bash”]brew install php54 –with-mysql[/code]

To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php5_module /usr/local/Cellar/php54/5.4.5/libexec/apache2/

The php.ini file can be found in:

If pear complains about permissions, ‘Fix’ the default PEAR permissions and config:

[code language=”bash”] chmod -R ug+w /usr/local/Cellar/php54/5.4.5/lib/php
pear config-set php_ini /usr/local/etc/php/5.4/php.ini

After you enabled PHP in Apache, make sure you restart Apache too!

[code language=”bash”]sudo apachectl restart[/code]


If you get an error that looks like this:”

[code language=”bash”]configure: error: freetype.h not found.
Error: uncaught throw Failed executing: ./configure --prefix=/usr/local/Cellar/php54/5.4.5 --disable-debug --localstatedir=/usr/local/var --sysconfdir=/usr/local/etc/php/5.4 --with-config-file-path=/usr/local/etc/php/5.4 --with-config-file-scan-dir=/usr/local/etc/php/5.4/conf.d --with-iconv-dir=/usr --enable-dba --with-ndbm=/usr --enable-exif --enable-soap --enable-sqlite-utf8 --enable-wddx --enable-ftp --enable-sockets --enable-zip --enable-pcntl --enable-shmop --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-mbstring --enable-mbregex --enable-zend-signals --enable-dtrace --enable-bcmath --enable-calendar --with-zlib=/usr/local/Cellar/zlib/1.2.7 --with-bz2=/usr --with-ldap --with-ldap-sasl=/usr --with-xmlrpc --with-kerberos=/usr --with-libxml-dir=/usr/local/Cellar/libxml2/2.8.0 --with-xsl=/usr --with-curl=/usr --with-gd --enable-gd-native-ttf --with-freetype-dir=/usr/X11 --with-mcrypt=/usr/local/Cellar/mcrypt/2.5.8 --with-jpeg-dir=/usr/local/Cellar/jpeg/8d --with-png-dir=/usr/X11 --with-gettext=/usr/lo[/code]

It is because your freetype is not working right. It happened to me after I upgraded from Mac OS X Lion to Mac OS X Mountain Lion. To do safe, uninstall and install freetype back:

[code language="bash"]brew uninstall freetype
brew install freetype[/code]

Also if you get a permissions error, you might have to fix it:

[code language="bash"]➜ ~ brew install php54
==> Downloading
Already downloaded: /Library/Caches/Homebrew/php54-5.4.5
==> ./configure --prefix=/usr/local/Cellar/php54/5.4.5 --disable-debug --localstatedir=/usr/local/var --sysconfdir=/usr/local/etc/php/5.4 --with-config-file-path
==> make
==> make install
==> /usr/local/Cellar/php54/5.4.5/bin/pear config-set php_ini /usr/local/etc/php/5.4/php.ini
no write access to /Users/kahwee/.pearrc!
Error: uncaught throw
Failed executing: /usr/local/Cellar/php54/5.4.5/bin/pear config-set php_ini /usr/local/etc/php/5.4/php.ini'[/code]

I changed the owner from root to kahwee (my username):

[code language=”bash”]sudo chown kahwee /Users/kahwee/.pearrc[/code]

That’s all, hope it helps!

How to troubleshoot Mountain Lion’s Apache

After I install Mac OS X Mountain Lion, it seems like my Apache server can no longer start successfully:

[code lang=”bash”]bash-3.2# sudo tail /private/var/log/apache2/error_log
[Thu Aug 02 09:36:46 2012] [notice] caught SIGTERM, shutting down
[Thu Aug 02 09:37:57 2012] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
httpd: Could not reliably determine the server’s fully qualified domain name, using kahwee-mba.local for ServerName
[Thu Aug 02 09:37:57 2012] [notice] Digest: generating secret for digest authentication …
[Thu Aug 02 09:37:57 2012] [notice] Digest: done
[Thu Aug 02 09:37:57 2012] [notice] Apache/2.2.22 (Unix) DAV/2 mod_ssl/2.2.22 OpenSSL/0.9.8r configured — resuming normal operations
[Thu Aug 02 09:46:17 2012] [error] [client] File does not exist: /Library/WebServer/Documents/favicon.ico
[Thu Aug 02 09:54:19 2012] [error] [client] File does not exist: /Library/WebServer/Documents/r, referer:
[Thu Aug 02 09:54:19 2012] [error] [client] File does not exist: /Library/WebServer/Documents/favicon.ico
[Thu Aug 02 09:54:31 2012] [notice] caught SIGTERM, shutting down

To find out why, run apachectl -t:

[code lang=”bash”]
bash-3.2# sudo apachectl -t
httpd: Syntax error on line 106 of /private/etc/apache2/httpd.conf: Cannot load /usr/libexec/apache2/ into server: dlopen(/usr/libexec/apache2/, 10): Symbol not found: _dav_add_responsen Referenced from: /usr/libexec/apache2/mod_dav_fs.son Expected in: flat namespacen in /usr/libexec/apache2/

Seems like it is caused by my disabling of mod_dav. mod_dav_fs acts as a support module for mod_dav and provides access to resources located in the server’s file system.

So I go to line 106 of /private/etc/apache2/httpd.conf and I comment out that line too.

[code lang=”bash”]sudo nano /private/etc/apache2/httpd.conf[/code]

Try to run the syntax check of Apache configuration again:

[sourcecode language=”bash”]
bash-3.2# sudo apachectl -t
Syntax OK
bash-3.2# [/sourcecode]

That seems to be working, now we start Apache:

[code lang=”bash”]sudo apachectl start[/code]

Useful apachectl commands include:

  • apachectl start
  • apachectl stop
  • apachectl restart
  • apachectl -t

Hope it helps!

Mac users steered to pricier hotels

So if you’re a Mac user to get the more expensive hotels. Very smart. I am honored to be perceived as the more affluent.

On Orbitz, Mac Users Steered to Pricier Hotels

Orbitz Worldwide Inc. has found that people who use Apple Inc.’s Mac computers spend as much as 30% more a night on hotels, so the online travel agency is starting to show them different, and sometimes costlier, travel options than Windows visitors see.

The Orbitz effort, which is in its early stages, demonstrates how tracking people’s online activities can use even seemingly innocuous information—in this case, the fact that customers are visiting from a Mac—to start predicting their tastes and spending habits.

This is one site I will avoid shopping. Sorry, I’m a bloody cheapskate.

Lion takes long to connect to local server

Does your /etc/hosts file look like this?

[code lang=”bash”] gladlycode.local gladlycast.local babyessentials.local localhost[/code]

Every request I made to gladlyCode.local takes 5 seconds to resolve to my local Apache server. Something was wrong!

If it does and you’re on Mac OS X Lion, you should change your VirtualHost names to something else. It turns out that Mac OS X Lion no longer looks up /etc/hosts first when you try to lookup a .local domain since are technically reserved for Multicast DNS (MDNS), or Bonjour. Starting Lion, it will lookup through MDNS first, and after the 5 second timeout, it checks with /etc/hosts.

This is at a cost of developer productivity and I have to change all my .local domains to which is a domain name I own. I figured that if it is a domain name I own, it will never clash unknowingly. I changed ‘gladlycode.local’ into ‘’ and point it to now. Now testing gladlyCode no longer takes 5 seconds per request (ridiculous!).

Alternatively you can use another top level domain (TLD) instead of .local and the common ones such as .com.

How to setup PHP Pear in Mac OS X Lion

Here’s how to install PHP Pear in Mac OS X Lion 10.7 using the Apache/PHP install that comes with XCode.

Once you have PHP set up, you need to run the following installer:

[code lang=”php”]
kahwee-mba:Volumes kahwee$ sudo php /usr/lib/php/install-pear-nozlib.phar
[PEAR] Archive_Tar – installed: 1.3.7
[PEAR] Console_Getopt – installed: 1.3.0
[PEAR] Structures_Graph- installed: 1.0.4
[PEAR] XML_Util – installed: 1.2.1
[PEAR] PEAR – installed: 1.9.2
Wrote PEAR system config file at: /private/etc/pear.conf
You may want to add: /usr/lib/php/pear to your php.ini include_path

If your php.ini is in /etc/php.ini, open it using:

[code lang=”bash”]sudo nano /etc/php.ini[/code]

Should the file no exist, you may want to copy the configuration for /etc/php.ini.default over by doing the following:

[code lang=”bash”]sudo cp /etc/php.ini.default /etc/php.ini[/code]

Finally you will need to update the paths in your include_path in your php.ini:

[code lang=”php”]

; Paths and Directories ;

; UNIX: “/path1:/path2”
include_path = “.:/php/includes:/usr/lib/php/pear”

After this, you can install PHP Pear packages. This is used if you want to install Numbers_Words package:

[code lang=”bash”]sudo pear install channel://[/code]

Have fun.