Applying Patches

---------------- NEEDS TO BE EXPANDED/REVIEWED ----------------------

Applying patches, modifying files according to instructions in the patch file, is the domain of patch programs. There are many different programs with this functionality. some stand-alone (patch), some integrated in IDE's (Eclipse, XCode).

Warning: Patching is something that should never be done on your production site unless you have sufficient backup and testing performed. While patching itself is relatively easy, understanding the implications of a patch is not. Patching your system can lead to loss of data and/or site instabilities

This page only deals with some basic principles using the command line utility patch. Patch can be found on most UNIX systems and is included in the packages UnxUtils and Cygwin for use on Windows.

Provided that the patch was made relative to the ProjectPier root directory, navigate to the ProjectPier directory (using cd) and issue the command:

patch -p0 < path/file.patch

If the patch was not made relative to the ProjectPier root directory you can place the patch in the same directory as the file being patched and run the patch command without the -p option. To do so, cd to the directory and type:

patch < file.patch

Patch will usually auto-detect the format. You can also use the -u command line option to indicate a unified patch, and the -b option creates a backup copy of the file before modifying it. In case of problems, you can then easily restore the backup file.

You can also reverse the patch if you want to.

You will need shell/ssh access to your server. Your account needs to have the proper permissions, and you need to access it through the command line.

  • ftp the patch file to the same directory as the file that you want to patch.(or to the root ppier directory if more than one file)
  • issue the command:

    patch -b < file_name.patch

  • You're Done - Check the changes to the site.

The -b option creates a backup of the original file(s) that are modified by the patch command (they will have a .orig extension added). If anything goes wrong on the site, it's easy to restore the files to their original state.

More information:The Ten Minute Guide to diff and patch

Does anyone know a similiar site for doing this using a GUI (like Tortoise SVN)?

TortoiseSVN is just a matter of right clicking the root folder, choosing apply patch and choosing the file. Same thing for creating a patch, except you'll name a new file. You can also easily see it in the TortoiseSVN help.

-Ryan

I don't have shell access to my shared hosting account.
Is there any other way in which I can apply patches?
I want to apply this patch: http://www.projectpier.org/node/494
Thanks

Obba Web Solutions - Managing your online identity.
Web Design, Web Development, Web Hosting.
http://www.obba.co.uk

Generally speaking, when working with a shared hosting account, you would have your development files on your local computer, apply the patch, then upload the files to your shared hosting account for testing. Beware: patch files are for developers, not end users. You need to backup all the files on your shared hosting account as well as backup your database before you apply patches, that way you can restore to your previous configuration if the patch doesn't work for you.

Hi,

I looked through differnt instructions and guides on "patch and diff", however I still have a question:

Can I apply the patch on the server? (I do have SSH-Access)
After patching, do I have to run the setup-routine again?

Cheers
hein

Yes, you can apply it on the server directly assuming you have the patch command available, it depends on what type of server you have. Follow the instructions at the top of this page. It is highly recommended that you backup your complete file system before applying a patch. Also you need to be aware that most of the patches have not been tested so use them at your own risk. I'm not aware of any patches that require you to re-run the setup.