How to Move From Development to Production in PHP

I remember a couple of years ago I spent many hours searching for how to move from development to production. I was so confused. I am an experienced developer, but I have always done it wrong. I knew I was wrong, but I didn’t care at the time (shame on me).

Let me clarify, I did care. I wanted so desperately to do have a development environment and to stop making stupid mistakes in production, I just didn’t have the know how. Everything I read seemed to talk over my head, and I just didn’t understand. It seemed like I needed to know what I didn’t know to do what I wanted to do that I didn’t know how to do.

So what have I learned? It’s more about workflow and processes than a single answer. More like, find a workflow and stick to it. In the end, the chosen workflow only matters if you use it and stick to it.

Because I am currently the only developer, I use a simple workflow that works for me. I am committing all day and when I have something that works, I want it in production as quickly as possible.

My Workflow:

  1. My development and production files are on the same machine.  I do this because I was used to working in production anyway, and I know that the environment is the exact same (Apache, mysql, memcache, all my tools)
  2. I use GIT for version control.  (This was a huge stumbling block for me, I had started/stopped version control SOOO many times over the past years.  It was hard for me to see the value as a sole developer with no “releases” to speak of.)
  3. I have a continuous integration server (phpUnderControl).
  4. I follow the Git-Flow model (very loosely)
    1. For daily work/small changes, I work directly on the develop branch. (THIS IS NOT A BEST PRACTICE)
    2. For extended large changes, I use feature branches (ALL WORK SHOULD PROBABLY BE DONE THIS WAY)
    3. When I am ready for something to go into production I have a “bumpVersion.php” script that automates most of it.

One of the biggest problems I had before this workflow was constantly saving a file and assuming everything worked.  Sometimes I had syntax errors that I didn’t catch right away.  With git hooks, I have it setup where I can not commit a file into the repo unless it passes php linting.  This is run with php -l filename, which just checks the file for syntax errors.   This has saved me many times since having this workflow.

My bumpVersion.php script:

This is a simple script that allows my git tags to be numerical (sequentially) and for my tags to be named in a consistent manner.  It will also handle some other tasks if necessary, such as compiling/minifying javascript and CSS.  This actually does quite a bit, by putting these assets into RackSpace CloudFiles and waiting to make sure they are available before continuing with the build.  This prevents any changes from going into production until all the assets are available.  In the end, it uses git flow release start/finish to create a release tag, this merges everything into the master branch.  The script then pushes the master branch into a bare repo.


phpUnderControl is constantly monitoring the bare repo for changes.  As soon as it detects some, it does a git pull, runs the unit tests, if successful it then publishes the build.  This really entails a simple call to another script that does a git pull from the bare repo into production.  (THIS MAY NOT BE A BEST PRACTICE).


Don’t be afraid when coming up with a workflow.


Trello – Project Collaboration and Management

I must say, I just learned about Trello and I really love it.  While it is great for teams, I have also found it very useful for individual organization as well.

Trello is like having virtual boards with post it notes.  The idea of the “post it” notes allows you to easily move them around to prioritize events.  You have different boards for different states.

As a personal organizational tool, if you know and understand the 80/20/FTF principal, you can have one board for 80’s, one for 20’s, one for FTF’s and one for completed tasks.  This will allow you to easily add a task and then you can move them between your lists as you see fit.  And you can have a list of completed tasks for historical purposes.

As a collaboration tool, you can easily assign different people to tasks.

It’s just a fantastic tool to use.



PunchTab Loyalty Program – Easy To Use – Easy To Scam :(

I started looking into a loyalty program called  It is super easy to install, but it is also super easy to game.  🙁

The fact that the points are generated through JavaScript, means it is super simple to open a javascript console, copy/paste in some code a you have free points.  I don’t know what the answer is, but they want you to have a catalog of “gifts” to give to visitors based on points.  Not a good idea, unless you happen to have money to burn.

Sorry PunchTab, you are a no go at this point in time.


How I Am Choosing Sections Of A Website To Optimize

I have an e-commerce system that is a complete PHP spaghetti mess.

I am running way Way WAY to many database queries. I want to share how I am tackling this mess.

I am using the mysql general log to store the queries that are being run to both a table and a file. At first I was using this to see what was run most often, and started caching those in memcache.

Today I decided, why don’t I find out what pages are causing the most queries, and optimize those, instead of individual queries. For example, my first test showed my product page took 110 queries.

1) I am executing this on every page when I initialize the DB.
2) I turn on the general log for a few minutes. set global general_log=1; wait…. set global general_log=0;
3) I am using this query to find out what threads are running the most queries.
SELECT general_log., count(*) as c from general_log where general_log.event_time like ‘2012-03-02%’ and argument like ‘SELECT%’ group by q order by c DESC limit 10
4) I can then use the thread_id to find out what it was doing. The @page from the gist above will be one of the first queries, so I know where to start analyzing.

I hope this helps someone else.


Rackspace Cloud Servers to the Rescue

Rackspace’s cloud server architecture has a fantastic API. I recently found a need for an automated script to have access to a server for less than an hour a day.

Within this script, I am easily able to see if there is a server ready for it already, if not, it creates a server out of an image that I have already created for this purpose, waits for the server to become active, and then it does its work.

I have a separate script that check periodically for servers running past their expired time and deletes them so that we don’t have to keep paying for them.

This will take a server from about $10/month to less than $0.50 / month.