We Don’t Know Deployment: A 4-Step Remedy

Someone emailed me recently, having read my book and wanting some advice. Here’s a snippet of his email:


So here’s my problem.
We dont know deployment. We work from same copy on one test server through ftp and then upload live on FTP.

We have some small projects and some big collaborative projects.

We host all these projects on our local shared computer which we call test server.
All guys take code from it and return it there. We show our work to clients on that machine and then upload that work to live ftp.

Do you think this is a good scenario or do we make this machine a dev server and introduce a staging server for some projects as well?

I wrote him a reply with some suggestions (and my consulting rate) attached, and we had a little email exchange about some improvements that could fit in with the existing setup, both of the hardware and of the team skills. Then I started to think … he probably isn’t the only person who is wondering if there’s a better way. So here’s my advice, now with pictures! Continue reading

Apache Config: .htaccess or Virtual Hosts?

How to set apache configuration for your web projects? Some settings have to be in the main apache config or in a virtual host, but for many others you have two good choices; either use an .htaccess file, or place the setting in the vhost (virtual host) configuration. Which one you choose depends largely on your project setup, let’s look at each in turn:

The .htaccess File

The biggest item in favour of an .htaccess file is that it belongs in your webroot, and can be checked in to your version control tool as part of your project. Particularly if your project is going to be installed by multiple people on multiple platforms, this can be a very easy way to get development copies of code set up very quickly and for it to be easy for developers to see what should be in their .htaccess files.

With version control, you can also send new .htaccess configuration through by updating your copy of the file – but whether this is a strength or a weakness is up to you to judge! If everyone needs different path settings, for example, and is constantly overwriting your .htaccess file, that’s not a particularly excellent setup! Previously I’ve distributed a sample .htaccess file with a different file name, and added .htaccess itself to the ignore list of the version control tool.

The Virtual Host

Putting settings in the virtual host allows an easy way to configure the environment on a per-server basis, and not to accidentally deploy an incorrect setup. You could still distribute a sample vhost setup for people to use as their basis, exactly as you could for .htaccess.

The biggest reason for using the virtual host, especially on a production server, is that using .htaccess incurs a performance penalty. When you use .htaccess, apache looks in the current directory for an .htaccess file to use. It also searches in the parent directory … and that parent directory’s parent directory … and so on, up to the root of the file system. Imagine doing that on every request to a system under load!

Which To Choose?

It completely depends. At one end of the system, the open source project that will be set up on a relatively large number of systems by potentially inexperienced people – you’d probably choose .htaccess. For a large-scale, live platform deployment, use the apache settings themselves (a virtual host for a server which runs multiple sites – apache’s own settings for a server which only hosts a single site). Where are you on the scale and which will you choose?

Adding Custom Headers to Every Request with Chrome

I’m working on an API which uses OAuth2, but it also has an HTML output handler so I actually do quite a lot of my development in the browser for read-only stuff (I wrote an earlier article about output handlers including the HTML output handler). I fell across an extension for Chrome called ModHeader (WTF kind of URL is that, google?) which does this trick for me!

Once I have the access token, I add the Authorization header using ModHeader and it sends it on all requests to this API, so I can still use my HTML output handler and be logged in. It’s useful for sending custom headers of all kinds for different tools, so I thought I’d mention it!

Book Review: MongoDB and PHP

Despite having been toying with MongoDB and PHP for quite a while, I’ve only just picked up and read the “MongoDB and PHP” by Steve Francia, published by O’Reilly (disclaimer: I’ve collaborated with Steve on a few articles and he sent me a copy of the book to read)

Continue reading

SQL JOINing a Table to Itself

Getting two sets of information from one table in a select statement often leads people to write subselects, but it really doesn’t matter that this is the same table twice, we can just give it a new alias and treat it as if it were a different table. This is one of those techniques where, once you’ve seen it, it’s really obvious, but until that point it can be very confusing. I explained this to someone else recently, so I thought I’d capture it here in case it’s helpful to anyone else.

Consider that tried-and-tested example: employees and managers. Here’s the staff table from the database (today’s imaginary data isn’t particularly imaginative, sorry):

mysql> select * from staff;
+----+------------+-----------+------------+
| id | first_name | last_name | manager_id |
+----+------------+-----------+------------+
|  1 | Hattie     | Hopkins   |          4 |
|  2 | Henry      | Hopkins   |          4 |
|  3 | Harry      | Hopkins   |          5 |
|  4 | Helen      | Hopkins   |       NULL |
|  5 | Heidi      | Hopkins   |          4 |
|  6 | Hazel      | Hopkins   |          1 |
+----+------------+-----------+------------+
6 rows in set (0.00 sec)

Continue reading

5 Things To Do With A Training Budget of Zero

Training budgets are never generous enough to give us everything we think we need to keep our skill sets improving, however many people will be lucky enough to get something. If your training budget totals precisely zero pounds (or euros, or dollars, or whatever your local currency is), what do you do? Sulk until they give you something more? Or make the most of what you have? Continue reading

Generating Callgraph with XHGUI

I had a frustrating bug the other day with a new XHGUI install, I am working on creating a VM for my new PHP tools course I am teaching in March and I wanted to pre-install and part-install a bunch of things so that I can show some great tools in a limited amount of time. My XHGUI wasn’t quite right though; it couldn’t generate the callgraph for me. Instead, it said:

failed to shell execute cmd=" "" -Tpng"

Continue reading

Thoughts on Running an Open Source Project

I spoke in the unconference at PHPUK last week, on running an open source project. I thought I would collect together my thoughts into one place before I lose the scratty piece of paper I wrote them down on. I’m not sure I’m the right person to be giving advice exactly, but these are the things that, having been project lead on joind.in for a while, I think are important.
Continue reading