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/

Review: CakePHP Application Development

I have done a few projects using CakePHP the past couple of years. CakePHP has grown to become one of the more popular PHP web frameworks, think of CakePHP as Rails-inspired PHP framework.

CakePHP Application Development

If you’re interested in CakePHP, you may like to check out CakePHP Application Development by Packt Publishing. This book covers lots of beginner topics such as installation and configuration. It is a good book to get started on CakePHP, it has a step-by-step guide that can be useful for starters. The book targets CakePHP 1.2 however, the book is written before CakePHP 1.2 is released so it does not have updated screenshots in it.

Generally the book’s concept is correct. The explanations are written as if someone is talking to you. If you do not like that style of learning, best you avoid this title. CakePHP Application Development covers a creation of a sample app — Quickwall — at the end of the book. Unlike typical tutorials that teaches you how to create a blog with XX framework, this goes into more depth on how best to use the inbuilt features of CakePHP.

My major grip on this book is its numerous errors in code, and a couple of quite unforgiving ones too. The books could have been better edited. Some of the codes did not appear to run and you have to look around to check for syntax errors. It isn’t often, still it’s a bad impression. The codes in the book are badly indented too. This makes the codes hard to read. It’s a good book to learn, but can be better.

Find out more about CakePHP Application Development here, you can also have a look at the book’s Table of Contents here.

What I’ve been up to lately

I’ve been busy this couple of weeks hence the lack of updates. I have been working mainly on my tool of choice — CakePHP. I mainly do my work on OS X for PHP. Recently I got involved in working for some software that requires Microsoft SQL Server, PHP and IIS. The whole shift towards the other side slowed me down a lot. I found myself being confused over the tiniest thing like where’s my host file. Where’s the php.ini? How to configure this and that. The terms are seemingly different and watching IIS crash again and again due to me incorrect configurations frustrates me.

On the brighter note, when I working in Windows I actually realized how much I missed Windows Explorer. It’s probably the single most useful utility I miss when I switch to a MacBook.

CakePHP 1.2 and PHP 5.3 doesn’t play nice

I just upgraded all the software only to discover PHP got upgraded to 5.3. That’s fast, PHP 5.3 isn’t out too long ago and it’s in the Macosforge repository. Even the CakePHP update released on August 9 did not include PHP 5.3 compatibility.

Perhaps it’s time to update the CakePHP requirements and be indicative of the lack of support for PHP 5.3.

Now the library is throwing deprecated notices all around “Assigning the return value of new by reference is deprecated in…”. Also there is a PHP warning:

[code lang=”php”]PHP Warning: strtotime(): It is not safe to rely on the system’s timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘Asia/Singapore’ for ‘SGT/8.0/no DST’ instead in…[/code]

To stop the deprecated notices, I had to modify Cake’s core, not something I like to do.

I added the line “error_reporting (E_ALL & ~E_DEPRECATED);” at the top of /cake/libs/object.php. I also updated /cake/libs/configure.php by changing “error_reporting(E_ALL);” to “error_reporting (E_ALL & ~E_DEPRECATED);”.


This doesn’t solve the problem exactly, it just suppresses the deprecation notices so I can continue working. For a PHP 5.3 compatible CakePHP, you’ll need to use CakePHP 1.3 which currently isn’t stable. I’ll definitely be trying it soon but in the meantime I’ll just have to suppress error reporting.

Update: jdbartlett commented on a better way:

[code lang=”php”]if (defined(“E_DEPRECATED”)) error_reporting(E_ALL ^ E_DEPRECATED);[/code]

If you’re not doing any debugging, you can add the above code to the top of /app/webroot/index.php and suppress the error messages without editing the core. 🙂

Thanks jdbartlett! You saved me time. 🙂

NetBeans IDE 6.7 Milestone 3 released

NetBeans IDE 6.7 Milestone 3 is released. I have been using this for a few days. I haven’t noticed much difference actually. I use it for PHP. I still wish for more support on CakePHP.

The NetBeans team is pleased to announce the availability of NetBeans IDE 6.7 Milestone 3 (M3).

Highlights of the release include: 

  • Project Kenai Integration
    – Create Kenai projects from within the NetBeans IDE
    – Locate and open sources for Kenai projects in the IDE
    – Full integration with Bugzilla
  • Maven
    – Multi-tabbed artifact details viewer available
    – Graphical view of transitive dependencies available
  • PHP
    – Code coverage and Selenium support
  • Platform
    – Enhancements to Output WIndow, Update Center catalog and Search performance
  • Profiler
    – Export profiling data into CSV, HTML and XML file formats
  • C/C++
    – Easy host setup for remote development
  • GlassFish Integration
    – Derby support registers Derby associated with v3 Prelude instance
  • Integration with the Hudson Continuous Integration server

Read the complete list of NetBeans IDE 6.7 Milestone 3 features and enhancements. 

How to run XAMPP’s PHP CLI and CakePHP console

XAMPP is one of the easiest options to develop using PHP or PHP CLI. I use CakePHP for development and one of the features of CakePHP is to back the MVC. In this guide, we’ll see how to get started. This tutorial doesn’t teach you how to use CakePHP’s bake feature. This guide is specifically written for Windows Vista or Windows 7.

0. Objective

To run XAMPP’s PHP CLI, you first have to set up the environment variables for PHP CLI. Also introduce how to get started on CakePHP’s console.

1. Setting up environment variables

Continue reading “How to run XAMPP’s PHP CLI and CakePHP console”

Some suggestions for .gitignore

This is more of a personal note. You may find it useful too.

Here’s how to ignore files and folders using Git. You can create a file “.gitignore” and place in the files and folders that you wish to ignore (separated with a line break).

In the file: “./.gitignore”

Here’s a list of standard things to do a .gitignore. It ignores the thumbnail files generated by Mac OSX and Windows. (I’m on Windows Vista.) You can place this on the top folder of your Git project:

[code lang=”ini”]nbproject

“nbproject” is for NetBeans.

In the file: “./app/.gitignore”

Well, if you use CakePHP, you may want to add an additional .gitignore file in your CakePHP app directory:

[code lang=”ini”]tmp/**/*

I am open to suggestions what other files or folders are good to ignore but these are all I can recall. You can read more about gitignore at

Django 1.0 alpha released

Okay, Django 1.0 alpha has been released finally. I don’t have the time to test this out but I played around with some pre 1.0 alpha builds a couple of weeks back and that time the software was quite stable already.

Django 1.0 alpha released!

In accordance with the Django 1.0 release roadmap, tonight we’ve released the first “alpha” testing version of Django 1.0. This release includes all of the major features due for inclusion in the final Django 1.0, though some lower-priority items are still scheduled to be included before the 1.0 feature freeze, which will occur with the first beta release next month.

The next step on that path will be the first Django 1.0 beta release, currently scheduled for August 5. If you’d like to help out, please review our documentation for contributors and feel free to join in one of the development sprints scheduled for the run up to 1.0; the full schedule is available in the Django 1.0 release roadmap.

Now when would CakePHP 1.2 be released?