Handling line commands to a CPanel site without SSH

OK heres my tip number one - it wont be unknown of course but I figured it may be useful to a few people out there. I will explain the situation:

1. You have a dirt cheap hosting solution that is using the quite acceptable cpanel solution.
2. The hosting company havent given you ssh access
3. You have some things you really need to do such as :
a. upload a whole website,
b. set permissions on certain folders
c. tar up the old website
d. remove the old website

hmmm but how? well the simple answer that it took me a while to figure out is “cron”
so what you do:
1. On your machine tar & gzip your site you wish to upload*:

cd folder/above_site;
tar czfv newsite.tgz public_html;

so when I type there “cd folder/above_site;” simply open cd to the folder one above where your website is served from. e.g. your home directory on a mac.
2. upload the file so ftp newsite.tgz to the root of your cpanel account - however you may do this.. (e.g. transmit/fetch/apple ftp)
3. Upload a little file named “time.php” to your cpanel machines webroot that contains the following text:

<?
echo date("H:i:s");
?>

4. go to http://yoursite.com/cpanel Now navigate to the “cron” settings. Enter this one-liner changing the bits as necessary (usually just change the “username” with the username of your account should suffice)

tar cvzf liveoldsite.tgz /home/username/public_html;
mv /home/username/public_html /home/username/oldpublic_html;
tar xvzf /home/username/newsite.tgz;

This will tar & zip your current site, then move your old public_html folder out of the way, next expand the tgz file that you created locally on your home machine.

Note: It needs to be a one-liner for cron unless you want to lots of little entries but that may go wrong as one task takes longer than another.

5. Once your really sure thats all ok we need to enter a time. Open up a web browser and go to http://yoursite.com/time.php see what comes up - now take that time and add a minute or so. Go back to the cron part of cpanel and add in that time and press the submit button.

6. sit back and wait. Any errors will be emailed to you (You need to make sure cpanel has your correct email address mind you! The place to add this is usually found on the homepage of your cpanel)

7. Lastly if everything has gone to plan you will want to create one more cron line to remove the old redundant site. Firstly download “liveoldsite.tgz” which is a copy of your site.. then add this to cron as in steps 5 & 6.

rm /home/username/liveoldsite.tgz; rm /home/username/newsite.tgz;
rm -rf /home/username/oldpublic_html;

Note this is a particularly dangerous step and should only be carried out once you are happy that your new site is working as it should!!

Don’t blame me if it all goes wrong! This tip is more of a tip to show how it is possible to do some time consuming ftp things using cron when you don’t have normal ssh access..

nice!

* Oh one last thing.. If your uploading stuff from a mac you might want to do get rid of those .DS_Store files .. Use the following to remove.

cd to/folder/site;
find . -type f -name .DS_Store -delete -print;

Blog comments powered by Disqus