views:

1259

answers:

4

I would like to setup two environments for my new website written in PHP. One - to develop new versions and test them. And second production where my actual stable version of website will be available.

Website in PHP will consist of many PHP and other files (JS, images, and so on). So I think how to prepare this environment in best way to make it easy to do source control, fast copy website from development environment to production environment and to make development version available for people on the web so they will be able to see actual work progress and suggest changes or report bugs.

Could you please give me some advice where to go from this starting point? Are there books about this (from practical point of view?) or do you have experience or tips what to watch out and what is important to make this process easy and good for me and other people involved in developing new project?

+3  A: 

I prefer to have development occur on the developers local box if possible. If other developers are involved, you probably want to setup your version control such that both the database schema, javascript, css, and the php code can be checked out and setup on a developer's personal box pretty easily (assuming they have the correct LAMP/WAMP setup)

I've also seen it where people maintain a test website on a server where active development occurs. I would avoid this for active development, but use this for black-box testing of the latest checked in code (the latest build).

Once your test website checks out, then its a matter of exporting the code from your version control to the location the live website is. With svn, you can really just do an update of the live code with svn update specifying a revision or tag that indicates the current live version.

I would further recommend keeping some settings, like db access/username/pass, in a separate included file that is not version controlled. Keep this elsewhere, let developers plug in the access rights to their local database on their PC. On your server, plug in everything you need to access the database there. This should be really trivial code (defining a few variables) so not having it version controlled shouldn't be a big deal. If you like, you could version control a templated version, but I wouldn't put the real database info into version control.

Doug T.
+6  A: 

I work with a setup like this, so I can give you some tips on how to do this. I've been doing this for a while now, working out the kinks here and there, and feel like this is a setup I can honestly say is pretty darn productive.

Small note: I work on OSX, so the specific applications used might be a bit different from you if you're a linux/windows user.

I run a production 'server' on my Mac, using MAMP (www.mamp.info) to easily supply me with an Apache server with PHP and MySQL. You could use a similar tool such as XAMPP or install everything manually, it's really up to you.

Then I have my live servers, where my websites and customer websites are hosted. For each new website project (let's take abc.com as an example) I create a subdomain called staging.abc.com, on which I do my testing. It's always a good thing to test things on the exact same hard- and software before actually going live.

I use Subversion (or in short, SVN) for my versioning needs, with the added bonus that I can easily add 'hooks' to automatically update my online production server whenever I send my newly updated version to the SVN server. SVN also allows you to easily work with more than one person on the same project. For more information on SVN and how to use it, I suggest the great (and free) online book found here: http://svnbook.red-bean.com/

So in short: I work locally with MAMP providing me with a local 'working' server. After that, I test online on a staging.abc.com location to see if everything works well, and to possibly allow others to see the project (in case you want your client to see what's going on, for example), and after that I actually publish the project by putting it on the actual domain.

There are many more things that can be done to optimize your workflow, but this should get you started.

Hope this helps!

-Dave

Dave
+8  A: 

For starters use the following three:

  1. SVN - this will give you source control and allow you to track changes. You may want to get GUIs on top of this (Tortoise is a popular one) to ease the learning curve.

  2. RSYNC - this will allow you to streamline your syncing between local and remote site with a single command. RSYNC uses a diff engine to sync which means that incremental syncs happen in a matter of seconds. During intense programming, I will sometimes sync 4-5 times in one hour pushing out little changes real fast just because I can so easily.

  3. MySQLDump - This will allow you to import/export data from your production site. I usually do this once a week to get production data on my local servers which not only gives me a local backup but also lets me toy around with production data on a local test environment.

Those three alone will save you a lot of time in the long run and allow you to scale. Later on you can look into an automated build tools, unit testing frameworks, xml documentation framework and the like to build some serious products.

aleemb
Why rsync if you can checkout your current revision from SVN on the server?
christian studer
How do you keep track of database changes? I try to add changes as sql in a seperate dir /sql, but I sometimes forget to do that; which leaves me with a 'broken' commit.
bouke
@bouke - see five part series linked in this post http://www.codinghorror.com/blog/archives/001050.html
aleemb
@christian, rsync has differential sync (way faster/efficient), allows reverse sync, doesn't force check-in for sync, manageable include/exclude lists, doesn't sync .svn folder, not all sites sync entire source and usually have a build system. but mostly, it's faster and highly configurable.
aleemb
A: 

I was wondering if there was a way for PHP to automatically detect the environment it was in and configure things like DB connections, ini_set for errors etc.

The 2 ways I thought of were to recognise an HTTP header indication development and QA environments or to have custom properties in php.ini.

I do not see the http headers in $_SERVER and I do not see a PHP function to return them.

I have no idea if it is possible to add custom values to php.ini but I had a test and ini_get would not find it (I had restarted the web server).

EDIT

Sorry. I am a bad man. This is really another question rather an answer to this one or part of a discussion (which is where my head was at the time).

I have re-posted as a new question at http://stackoverflow.com/questions/1143770/can-i-configure-environment-specific-content

Feel free to ignore this one here.

Rob