How can I apply code changes to my running website, if I have bug fixes or updates?
The simplest way I can think of is to set up the same site in a different directory for testing the changes, and then put my website offline for a period of time to update the files.
Is there a better way?
Creating a copy of the live site is certainly a good step, applying changes to the copy before applying the same to the live site.
A common production environment would include a further set of steps.
-
Run a local development copy
Have a copy of your website running on your development machine. This requires that you development machine is running a web server, database server and, if necessary, a mail server.
For PHP/Apache/MySQL environments, take a look at http://www.apachefriends.org/en/xampp.html.
You can safely develop, break, test and change a your local development environment
-
Source control
Use Subversion, Mercurial or Git to keep your code under source control. Ensure your local development environment is kept under source control. Ensure your live environments are under source control. Develop locally, test changes and commit the changes back.
-
Staging and live environments
Maintain more than one 'live' copy - the actual live public site and as close a replica as possible. Ensure both are under version control.
Once locally-tested changes have been tested, update your staging environment (usin your source control system) and test again. Once your staging site is stable, you can use your source control system to update your live site.
There will not generally be much of a need to take the real live site offline to apply updates, but be sure that you can safely do so if needed.