Add Virtual Host to Xampp for

In C:\xampp\apache\conf\extra\httpd-vhosts.cnf file add new VirtualHost block

DocumentRoot "C:\xampp\htdocs\app_folder"

DocumentRoot "C:/xampp/htdocs"
ServerName localhost

Then restart apache

Open hosts file, in Windows it’s located in C:\Windows\System32\drivers\etc (make sure to show all files) and append

Save and close hosts file

You should be able to browse which loads the content from your disk

DateTime() is better than strtotime()

I’m using Windows 64 bit and PHP 5.6

strtotime() can’t go beyond 2038 year

$number_of_years = 2;
$start_date = '2037-12-31';
$end_date = strtotime('+' . $number_of_years . ' year', strtotime($start_date));
$end_date = strtotime('-1 day', $end_date);
echo 'strtotime() Result: '.date('Y-m-d', $end_date);

echo "<br/>";

$d = new DateTime($start_date);
$d->modify("+".$number_of_years." year");
$d->modify("-1 day");
echo 'DateTime() Result: '.$d->format('Y-m-d');


strtotime() Result: 1969-12-31
DateTime() Result: 2039-12-30

Usage of DateTime() is also easier.

Run Cron Job on Intervals

#Minutes Hours Day of Month Month Day of Week Command
#0 to 59 0 to 23 1 to 31 1 to 12 0(Sunday) to 6(Saturday) Shell Command
#run every 15 minutes
*/15 * * * * curl >/dev/null 2>&1

#run every 3 hours
0 */3 * * * curl >/dev/null 2>&1

#run every after 2 days at 1AM
0 1 */2 * * curl >/dev/null 2>&1

#run every after 2 months on day 1
0 0 1 */2 * curl >/dev/null 2>&1

#run every Tuesday,Thursday,Saturday at 1AM
0 1 * * 2,4,6 curl >/dev/null 2>&1

>/dev/null 2>&1 suppresses the output of curl

Doing Daily Remote Backup

Scenario 1

I have 2 remote servers, Server1 is live and Server2 is backup.
Server1 is already live and cron job is not running. I don’t want to install cron job in Server1 for some reasons.
Server2 has cron job running and is going to connect to Server1 and execute the backup script every 1 AM.

Open crontab in Server2
$ crontab -e
Press Insert button in the keyboard to edit.
#Minutes Hours Day of Month Month Day of Week Command
#0 to 59 0 to 23 1 to 31 1 to 12 0 to 6 Shell Command

Append the command to run
0 1 * * * ssh user@Server1 sh /mnt/extradisk/
Press ESC button to quit editing, type :wq! press Enter to save changes and quit editing.

Below is the script for
weekday=$(date +"weekday_%u")
mysqldump -u user -ppassword --all-databases | gzip > $file
scp -P 10022 $file user@Server2:~/folder-daily-backups/
tar -cpzf $domain -C / usr/share/glassfish3/glassfish/domains
scp -P 10022 $domain user@Server2:~/folder-daily-backups/

The above script dumps all mysql databases and zip them into a file.
It also backups glassfish files and zip them.
Both zips are copied from Server1 to Server2 for remote backup.

Scenario 2

Both servers have running cron job.

Server1 is going to execute it’s backup script every after 3 hours
0 */3 * * * sh ~/backups/ code below
hour=$(date +"hour_%H")
mysqldump -hipaddress -u user -ppassword database | gzip > $file

Server2 will get Server1’s backups every 1 AM
0 1 * * * scp -P 10022 user@Server1:~/backups/* ~/BACKUPS/project/

Note: Server1 has Server2’s public key in its authorized_keys, vice versa.

$ date --help
to see more date formats

Cleaning Malicious Scripts Injected in WordPress PHP files

Note: This only works if the scripts are injected to the first line of every PHP files.

First backup the files
$ tar -zcvf public_html.infected.tar.gz public_html

Then go inside public_html to execute the code there
$ cd public_html

Find all files with .php extention and execute the sed command.
sed will do an infile search and replace. -i will backup the file to be edited and add .infected suffix.
'1 s/.*/<?php/' does search in first line from .* (means all of first line) and replace with <?php

Note: There’s a possibility that the site may function, so be ready to fix it.
The problem I encountered with this is that few php files that only have html contents are having errors bec of <?php in the first line.
Check the server log for details errors.

Another error I encountered from wordpress pages is that <?php get_header();?> in the first line is replaced with <?php

Execute the cleanup code below
$ find . -type f -name "*.php" -exec sed -i.infected '1 s/.*/<?php/' {} \;

Check the command has no adverse effect on the site.
After checking the site is still working, delete infected files

$ find . -type f -name "*.infected" -delete