Simple cPanel Backup Rotation Script

cPanel has a brilliant backup facility built in, however it only keeps 1 backup per backup type. So if you have daily backups enabled running every day of the week, your previous day’s backup will be lost – the same applies to weekly and monthly backups. This can be a bit of a nuisance if you need to restore a file deleted the day before a backup ran. So using a simple script that hooks into cPanel’s backup script, you can retain backups for any number of days, weeks or months and it will only consume a very minimal amount of space – as the script uses hard links. So only the files that have changed will actually take up disk space. Backup rotation script Create a new file /scripts/postcpbackup.sh and put the following in it. You can customise the types of backups to be rotated and the retention period. … Continue reading

Magento Product Price Is Zero with Catalogue Price Rule

We have come across a somewhat critical core code error in Magento versions less than 1.5 when using the “Fixed Amount discount”. Any SKU that the respective rule applies to results in the final sale price of the product being £0. This seems to only occur in certain scenarios, but is easily replicated on a Magento 1.4.2.0 clean demo store. The fix Rather than posting the full code for an extension based override, we’re just going to post the code snippet and the simpler PHP autoloader priority based fix using the ./app/code/local directory. Create ./app/code/local/Mage/CatalogRule/Helper/Data.php And paste the following code inside: class Mage_CatalogRule_Helper_Data extends Mage_Core_Helper_Abstract { public function calcPriceRule ($actionOperator, $ruleAmount, $price) { $priceRule = 0; switch ($actionOperator) { case ‘to_fixed’: $priceRule = $ruleAmount; break; case ‘to_percent’: $priceRule= $price * $ruleAmount / 100; break; case ‘by_fixed’: $priceRule = $price – $ruleAmount; break; case ‘by_percent’: $priceRule = $price * (1 – … Continue reading

Stop Magento Permissions Errors … Permanently

When working with customers not hosting with Sonassi Hosting, we continually run into the same permissions errors – along with the rest of the Magento using world. This isn’t an issue if PHP runs as the same user as your FTP/SSH user, but if they are different, all kinds of headaches ensue. Whenever granted root access to a server, we normally carry out the following, to rule out any future permissions headaches. Please bear in mind, this practice is secure for dedicated hosting but may present security issues with shared hosting if the Apache process isn’t chroot’ed per user. In our example, the user is sonassi and the group is apache Add the FTP/SSH user to the Apache group Most importantly, we need to make sure that the FTP/SSH user is part of the Apache group, in our example, its apache (but is also commonly www-data) usermod -a -G apache … Continue reading

Abandoned PHP fCGI Process Clean-up

We found a bug recently where PHP processes were being abandoned and left to continually consume memory and accumulate. This seems to be prevalent with Apache 2.2.x and mod_fcgid 2.3.5. Whilst we await an actual fix, we’ve wrote a quick script to help “clean up” these zombie processes to prevent the machine eventually swapping. This works for cPanel and any other server running mod_fcgid. It isn’t meant to be a permanent solution, but a means to help the issue temporarily. Firstly, create the following file, /scripts/phpcleanup.sh, then add the following line to your root crontab 5 2 * * * /scripts/phpcleanup.sh #!/bin/sh # PHP Cleanup script for abandoned PHP processes as a bug fix to issue in EasyApache, # See http://forums.cpanel.net/f189/lost-abandoned-php-processes-apache-2-2-17-mod_fcgid-2-3-5-suexec-180571.html # # Courtesy of www.SonassiHosting.com – The Magento Hosting experts phpbin=’/usr/bin/php’ membefore=`cat /proc/meminfo | grep Committed_AS | awk ‘{print $2}’` procsbefore=`ps ax | grep “$phpbin” | grep -v grep … Continue reading

A Poor Mans Staging/Live with WordPress and Rsync

Firstly, this isn’t meant to be a serious contender for ‘proper’ version control, Eg. Subversion or Git, or anything of the kind. But instead just a nice little way of managing a WordPress staging and live site, so that you can perform simple design tweaks/changes on a staging site and roll out those changes gracefully to the live site. We use it for tiny WordPress sites where version history is not required but we still want to separate CSS tweaks from the live site. Start by creating a new file sync.sh and paste the following into it, changing the highlighted lines as necessary, then chmod +x sync.sh and execute it. Support for W3 Total Cache – providing an option of flushing all caches (if necessary). WP Minify – automatically turning off CSS and JS minification on the staging site and flushing cache on live site The code #!/bin/sh LIVE_DBNAME=”" LIVE_DBUSER=”" … Continue reading