Installing software, and other things casual webmasters should know

In this tutorial, I’m going to write about a num­ber of things that will be use­ful to you if you have your own web­site host­ing. This art­icle is geared for begin­ners, and requires no pre­requis­ites apart from some com­mon sense! Now, I host nointrigue​.com on a shared Linux server with Blue­host, which means that my web­site shares a phys­ical com­puter with a num­ber of other users. This setup is fairly com­mon, so I’ll be writ­ing with an assump­tion that this is the kind of arrange­ment that you have. I’ll cover some basic, but use­ful, shell com­mands to make your life easier, and explain how to install addi­tional soft­ware on your host.

Get­ting started

Typ­ic­ally, you will have FTP access to your shared host, but not all shared hosts allow shell access to your server. To fol­low this tutorial, you will need to have shell (SSH) access to your host (which, by the way, I am assum­ing is a Linux box, which is the usual case). Even if your host­ing pack­age has this fea­ture, you may have to file a sup­port request to enable it, as is the case with Blue­host (see the SSH link in cPanel). (Actu­ally, I lie. You can still do the installing soft­ware part, but it may prove far more dif­fi­cult — see below for details.)

To con­nect to your server, you will need an SSH cli­ent on your com­puter. If you are using Mac OS X or some ver­sion of Linux, you will prob­ably have OpenSSH installed already. If you are using Win­dows, you can either install Cyg­win (make sure you select the OpenSSH pack­age) or use PuTTY. If you don’t have a need for a Unix-​​like envir­on­ment on your Win­dows machine, and you just want SSH, the lat­ter is prob­ably a sim­pler choice.

  • If you are using OpenSSH, open up a com­mand prompt or ter­minal, and type ssh username@yourdomain.com filling in the user­name and your domain name as required.
  • If you are using PuTTY, run putty.exe, enter your host name and press Open.

For both, if you are promp­ted about stor­ing the server’s fin­ger­print, just type or click yes.

putty-main.png

You should now be presen­ted with a shell prompt, where you can type in com­mands (which you issue by press­ing Enter after typ­ing them in). It may seem like a regres­sion back to the 1980s days of MS-​​DOS, but it’s quite a con­veni­ent way of con­trolling a server that’s far away from you.

To avoid hav­ing to enter your pass­word every time, you can use an SSH agent.

putty-loggedin.png

Get­ting to know your shell commands

This is not inten­ded to be an exhaust­ive list of com­mands that you can type; instead, my aim is to write down a num­ber of com­mands that inex­per­i­enced users can just quote ver­batim to do what they need to do. Parts in ital­ics are to be replaced as appropriate.

  • cd directory: this is how you enter into a dir­ect­ory. Com­mands are always executed rel­at­ive to the cur­rent dir­ect­ory. ~ is your home dir­ect­ory. Just type cd to return to your home directory.
  • ls: dis­play the con­tents of the cur­rent dir­ect­ory. Type la -la to make it dis­play hid­den files and detailed inform­a­tion about your files.
  • mkdir directory: cre­ate a directory.
  • rmdir directory: remove a dir­ect­ory. The dir­ect­ory must be empty.
  • rm file: delete a file. Use rm * to delete all files in the cur­rent dir­ect­ory, or use rm -rf * to delete all files and sub­dir­ect­or­ies in the cur­rent dir­ect­ory (use with caution!).
  • cp oldname newname: copy a file.
  • mv oldname newname: move a file. This com­mand is also used to rename files, since the act of renam­ing is just the same as mov­ing. You can move a file up a dir­ect­ory by using mv file .., and a file into a sub­dir­ect­ory using mv file subdirectory.
  • pwd: dis­play the full path to the cur­rent directory.
  • less file: view a file. Use the arrow keys or page up and page down to move around the doc­u­ment. Press q to exit.
  • find -name wildcard: use this to search the cur­rent dir­ect­ory and its sub­dir­ect­or­ies for a file with a name that matches the wild­card expression.
  • ln -s linkname filename: a sym­bolic link is like a short­cut that allows a file to appear in two dif­fer­ent places — but both the exist­ing name and the new link name refer to the same file.

To find out more about these com­mands, type man command, and press q to exit. If some­thing screws up, press­ing Ctrl+C should kill whatever com­mand you’ve just issued.

Edit­ing on the go

Another activ­ity that I use SSH for quite a bit is edit­ing con­fig­ur­a­tion files dir­ect­ory on the server. That saves me hav­ing to down­load the file to my com­puter, mak­ing the changes, and then upload­ing it back up again. A good text-​​based editor is vim, and here are just a few com­mands to get you started.

  • To start vim with a file open, use vim file.
  • To move around, the arrow keys, home, end, page down and page up work as expected.
  • To go into edit­ing mode, press i, and then any keys that you press will be added to the doc­u­ment itself. To get out of this mode, press Esc.
  • When you’re not in edit­ing mode, you can issue com­mands to the editor. For example: :q to exit, :q! to exit without sav­ing changes, :w to save, :wq to save then exit.
  • That should be enough to edit a file, but if you want to know more, type :help and there are links to on-​​line tutorials.

vim.png

Installing soft­ware on your shared host

If your server is a shared host, you can be pretty sure that you can’t install or modify the soft­ware install­a­tion on the server on a global level. You can, how­ever, install addi­tional soft­ware just for your­self in your home dir­ect­ory (which you can def­in­itely write to!). If you don’t have SSH access to your server, you could try and recre­ate a sim­ilar envir­on­ment to that on your server, com­pile the pro­grams (using, per­haps, cross com­pil­a­tion), and then upload the res­ult­ing execut­ables like you would nor­mally — let me know if you can get that to work!

Why would you want to install addi­tional soft­ware? There are plenty of reas­ons for that. For example, you might want to run Ruby scripts, but your host hasn’t updated the soft­ware installed since the dark ages. Altern­at­ively, you might want to run soft­ware that isn’t typ­ical for a shared web server; for example, I have Sub­ver­sion (a ver­sion con­trol sys­tem) and Privoxy (a proxy server) installed. I also have a LaTeX install­a­tion so I can get maths ren­der­ing in MediaWiki.

  1. Cre­ate a dir­ect­ory for down­load­ing and com­pil­ing files: I call mine src, and it’s a sub­dir­ect­ory of my home dir­ect­ory ~. This is use­ful in case you make a mess; that way, you can use rm -rf * (see above) to oblit­er­ate everything in that dir­ect­ory and start again.
  2. Down­load the source files: you will need to down­load the source files, and cre­ate the execut­able (bin­ary file) your­self, instead of down­load­ing the com­piled execut­able. This will ensure that there are no prob­lems installing or using the pro­gram. Open source pro­jects will have the source code avail­able. To down­load some­thing to the cur­rent dir­ect­ory, use wget url.
  3. Unpack the source files: typ­ic­ally, the source file will have one of sev­eral exten­sions. If it ends in .tgz or .tar.gz, use tar -xzvf file. If it ends in .bz2, use tar -xjvf file. If it ends in .zip, use unzip file.
  4. Read the install­a­tion instruc­tions: there’s often a README or INSTALL file amongst the files that were unpacked. Read it using less (see above).
  5. Com­pile it: if there are install­a­tion instruc­tions, fol­low those. How­ever, if there’s a part where it asks you type in ./configure (which is almost always), then you should type ./configure --prefix=$HOME instead. This will make sure that your soft­ware is installed in your home dir­ect­ory. If there are no install­a­tion instruc­tions, a typ­ical sequence of com­mands is: ./configure --prefix=$HOME, make, make install.
  6. Test it out: your pro­gram will prob­ably have been installed into ~/bin ~/sbin, where ~ is your home dir­ect­ory. Now, you’ll notice that you can only type the name of the pro­gram when your cur­rent dir­ect­ory (which you change using cd) is the dir­ect­ory where that execut­able resides. In order for the shell to find your newly installed pro­gram, regard­less of what dir­ect­ory it resides in, you’ll need to add it to your PATH envir­on­ment vari­able. To do this, you need to add a line to the .bashrc file that resides in your home dir­ect­ory (cre­ate one if it doesn’t exist). For example, my line looks like this: export PATH=$PATH:~/bin:~/bin/tetex, and that means that I’ve added ~/bin and ~/bin/tetex to the loc­a­tions where the shell will search for pro­grams; note the use of the colon to sep­ar­ate paths.

That’s all for now folks! I hope the instruc­tions are clear, and that your days of being a web­mas­ter are more pro­duct­ive than before. If you want to learn more, Google is your friend.

Tags: , , , , , , , , , , ,

Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>