How to Sync Two Websites on the Same Server

9 Jun, 2010

network sharing iconQuestion: I have two separate websites that I want to have identical data on each site. How can I do this?

Answer: First of all, to sync files on two separate sites on the same server, you will need to have a user that has write permissions on both sites. If you are using a shared hosting account, and both sites are under your account, you probably already have this. For a VPS that has a unique user for each site, you will need to use the root user.

Next, you need to know the full path to the directories for both sites. For example, site one may be /home/user/www/html/siteone.com/html and site two may be /home/user/www/html/sitetwo.com/html. To sync both directories and keep them synced even when data changes, the best choice is rsync. Although rsync is normally used for remote syncing, it also works for local directories.

To sync the two directories, you would use this command:

rsync -avc /home/user/www/html/siteone.com/html/ /home/user/www/html/sitetwo.com/html/

If you want the sync to be performed periodically and automatically, you can create a script and then drop it into one of the cron directories, such as cron.daily. You can also setup a manual cron job in /etc/crontab. From now on, both sites will show identical information.

(0) Comment Categories : Software, Web servers
Tag: , , , , , ,

How to check and optimize MySQL databases automatically

17 Feb, 2010

MySQL table repair in phpMyAdmin
MySQL databases require regular maintenance, but usually the databases just need to be re-optimized and checked for errors. In such cases, having to go through each database on your server can be time consuming. Following these steps, you can setup a cron job that will automatically check and repair your databases.

1. Login to the server via SSH
2. Edit the crontab file found in /etc/crontab

# crontab -e

3. Enter the following line in the crontab file:

0 1 * * * mysqlcheck -Aao –auto-repair -u root -p[password] > /dev/null

This will check all databases on the server. If you do not have root access and only want to check your own website, you can edit your cron in your control panel or replace the “root” user with your MySQL username. Save the file, and cron will now start mysqlcheck at 1 am everyday to optimize and check all databases.

Source: My Digital Life
Photo: Flickr

(0) Comment Categories : Software, VPS & Dedicated, Web Hosting
Tag: , , , , ,

Linux server backup to Amazon S3

10 Feb, 2010

Amazon Web Services logo

Amazon S3 is a storage service provided by Amazon.com. It is part of Amazon’s cloud computing offering, and it used by all sorts of individuals and businesses. Although anyone with a Linux server can theoretically backup their server manually to S3 storage, it helps to have a tool to do it for you.

S3cmd is a command-line S3 client for Linux. It can be used with cron to create automated backups of your data.

“S3cmd is a command line tool for uploading, retrieving and managing data in Amazon S3. It is best suited for power users who don’t fear command line. It is also ideal for scripts, automated backups triggered from cron, etc.”

S3cmd is available for download from the project’s website in both source code packages and binaries for major Linux distributions. It is free and open source software released under the GNU General Public License.

Source: S3cmd

(0) Comment Categories : Web Hosting, Web Services
Tag: , , , , , ,

How to schedule a reboot on a Linux server

9 Feb, 2010

Tux, Linux mascotAutomating tasks in Linux is a pretty straightforward process, mainly because the tool used to do it comes with all Linux distributions. It is called Cron, as we mentioned in an earlier post. Cron allows you to automate all sorts of tasks, including reboots. But if you just need to reboot once at a certain time, “at” might suit you well.

Why would you want to schedule a reboot? Usually, you only need to reboot a Linux server after installing a kernel update. Since you can plan such an update ahead of time, the ideal time to reboot would be when most users are not accessing the server. That time, however, might be when you are asleep.

To use “at”, become root and type “at” followed by the time you want the server to reboot:

# at 4am tuesday

This will start the “at” prompt, where you need to type “reboot”.

at> reboot

Press CTRL+D to save your settings. Now your server will reboot at the specified time.

(0) Comment Categories : Software, VPS & Dedicated
Tag: , , , , , , ,

Monitor disk space on a dedicated server

28 Jan, 2010

Bash shell screen
Question: How can I configure a Unix server to tell me when the hard drive is getting full?

Answer: Unix, Linux, and Unix-like systems have a command called “df” that reports disk space information about the server’s file system. Entering the following command:

# df -P /

produces output like the following:

Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/mapper/VolGroup00-LogVol00 6983168 3824556 2798164 58% /

The next step involves configuring a shell script and setting up a cron job to periodically check the disk space and send a warning to notify you when the server’s file system is getting full. For a complete tutorial, see nixCraft.

Photo: Wikimedia Commons

(0) Comment Categories : VPS & Dedicated, Web Hosting
Tag: , , , , , ,

Getting rid of crontab emails

25 Nov, 2009

cron
Question: How do I stop crontab from sending me emails after a cron job finishes?

Answer: In Linux the default setting for crontab is to send an email to the owner after a cron job finishes. An easy way to change this is to reroute those emails into nothingness, which in Linux is a directory called /dev/null.

Just append a pipe to it at the end of your command like so:

/usr/bin/command >/dev/null 2>&1

That will do the trick. You can enter it from the command line or through a control panel, if it supports cron jobs.

Photo: Flickr

(0) Comment Categories : VPS & Dedicated, Web Hosting
Tag: , , , ,

What is a Cron Job?

10 Sep, 2009

Crontab
Question: What is a Cron Job?

Answer:

A cron job is a periodic script run using scheduling software called “cron”. Linux and other Unix-like operating systems use it. A shared web hosting provider may allow you to run local user cron jobs, and those settings are usually accessible through your web-based control panel. If not, you can ask your host to make an exception for you for something that you must run.

Cron jobs are good for recurring events, such as payment processing, data reports, etc. Many PHP and CGI applications that require recurring events to take place when you are not logged in, can rely on cron to execute them.

In most Linux distributions, you can find the cron configuration in /etc/crontab. Some distributions, including CentOS, also include cron.daily, cron.hourly, cron.weekly. These are folders configured to run the scripts found inside them at specific intervals. You will most likely have access to this only if you have a dedicated server. To add scripts to it, simply create a symbolic link from your script to the cron folder of your choice.

Photo: Flickr

(0) Comment Categories : VPS & Dedicated, Web Hosting, Web servers
Tag: , , , , ,