MAMP Tutorials

Amazing tutorials to setup Apache, PHP and MySQL on Mountain Lion

After installing Mountain Lion I discovered that Apple changed their settings for Apache. Here are some amazing tutorials I came across that will help you get your Mac Mountain Lion Apache PHP MySQL server up and running.

Installing Apache MySQL, PHP and setup Virtual Hosts

Installing and configuring Apache, MySQL, PHP and phpMyAdmin

Enabling .htaccess

Fixing httpd.conf for



The Scope Resolution Operator (::) explained

Double Colon object oriented programming

I remember when I first came across the mysterious double-colon (::), also known as the Scope Resolution Operator. I was experimenting with a php library I hadn’t written, but was asked to extend, and at the time I had no idea what classes were, how they worked, or how they helped.

To try and figure out what the double-colon did I remember I peppered Google search with questions like, “What is the :: ?” or “what does the :: symbol mean?”  Those searches proved useless. At the time php5 was still very new and most PHP coders were writing procedural code rather than object-oriented code.

Now that I use object-oriented design every day I thought I would explain what the double colon :: means, just in case there are any new PHP programmers, like I was, and are confused by the mysterious double colon.

When and how to use the double-colon:

You use the double-colon to access static methods from a class. To get the color of the bear, from the example class I wrote about here, you would write the following.

Code language: CSS (css)

I will break the above line of code into its three parts.

1. Bear – First you write the name of the class you are referring to. In this case Bear.

2. :: – Then you use the double-colon because the method is declared as static.

3. getColor(); Then you write the name of the function you are calling that exists within that class.

And that’s the basic use of the double-colon to call a method from within a class.

The double-colon is simply a way of referencing the class object and accessing the static methods (functions) and constants within that class. If you are new to this I just said a lot. I explain these things briefly here.


Increase PHP Script Execution Time Limit Using ini_set()

Today I had to set the PHP script execution time directly from within the php file. Here’s what I did.

Add the following code to your file. You can change the seconds to what you need. It is important to be careful using this on a live server. If you allow a script to run too long you could hog all your servers resources and bog the site way down. 5 minutes is a lifetime in server time and it might be longer than you need.

ini_set('max_execution_time', 300); //300 seconds = 5 minutes

MVC architecture explained briefly.

Inevitably every programmer is going to encounter MVC architecture. MVC or model-view-controller is a pattern used by applications that divides the application into 3 parts. At first glance MVC can look more complicated than it is. Let’s look at the three parts.

Model – The model handles the data and cares about where the data is coming from. Typically it involves connecting to a database, but it could collect data by reading a file. The model only knows that data is there, it does not know what the data is or what you are doing with it.

View – The view cares about how to display the data. It doesn’t care where the data comes from or what the data means only that it is to display it.

Controller – ┬áThe controller is the bridge between the Model and View it interprets the data and handles any calculations. It doesn’t care how the data is stored or how to display it. It does care what the data means.

The advantage of MVC is that you can change things in one part of the application without “breaking” the other parts. For example, you could change where the data comes from in the Model. Because the View and the Controller never knew where the data came from they are not effected by the change. Likewise, you could change how you want the data displayed in the View but neither the Model or the Controller is effected.

For example. Let say we are viewing Facebook. What you see is the view. When loading a FaceBook page the view tells the controller that it needs data, the controller gets the correct data from the Model and sends it back to the View. The View then displays that data. The Model and the Controller don’t care that the data is being displayed on a computer or on an iPhone application.

So it’s really not a very complicated architecture structure.