Playing with Debian

Wednesday, 12th March 2008 at 10:36pm

Backup your databases... now

Just like I predicted, I had my first mess up. On the bright side though, it wasn't because of Debian. It was because I wrote a script and replaced all the entries with a blank line... That's not important though, what is important is that I should have backed up, which I didn't. (I had to go through my entries in Google Reader - thank God for them archiving feeds and not getting them live - and copy and paste them back.)

Anyway, backing up your MySQL databases is easy actually. There's a page about it on the MySQL documentation. I chose the mysqldump option.

From PuTTY (you don't need to be in MySQL, mysqldump is part of the mysql-client package, but executable by itself) I did this:

mysqldump -A -u root -p > /home/shamess/backedup-files/20080312.mysql

The -A means "all databases", if you only want one database you can append the database name at the end (and miss out this switch). If you only want one table, put the table name at the end of that too.

The next switch is me giving the MySQL username. I decided to use root, since it has access to all the databases. The "-p" is saying that I'm going to use a password. I didn't put my password after it, because you can leave it out and it'll prompt you for it after you press enter (thanks Marc for that).

Then there's something new for us to get excited about. The greater than symbol (>) means "write whatever output to this file". I did that because I couldn't find the switch to do it for mysqldump, but I'm sure there is one (comment if you find it).

On a side note: if you look through the site and notice an entry is out of place, or the subject has nothing to do with the post (meaning I've pasted the wrong post) then please comment!

1 comments

Wednesday, 12th March 2008 at 10:04pm

Some stuff that has changed

First, I thought I'd let you all know that we've switched to a new URL. The Trinity URL took too long for me to keep typing, so we're now over at www.debiantips.com. There's not much you need to do; the RSS feed and everything will stay the same. If you book marked any links, don't worry, they'll all redirect.

But, because I changed the URL to the RSS feed for Feedburner, it reloaded all the RSS items, so sorry if you have to mark them all as read again!

To be a little on topic; I've just added www.debiantips.com to the ServerAlias for the old site, so it's exactly the same.

0 comments

Tuesday, 11th March 2008 at 07:24pm

Keep your inactive PuTTY session alive

A lot of people are getting here by searching for things like "putty inactivity", so I thought I'd answer your question for you. You'll kick yourself at how easy it is.

After a period of time, PuTTY likes to kick your connection when you're not doing anything. It's mostly so that if you're away from the computer, someone else won't come and start playing with your box.

Start PuTTY, go to the 'connection' tab, and change the 'keepalive' value to something like 120. Don't go much lower than that, or your server might get sick of null packets.

Whilst you're in your options, you may want to increase the security of your connection so no one steals access to your server. If you have PuTTY open a lot, you might be interested in being able to send it to the system tray, instead of having it open in a new window.

1 comments

Sunday, 9th March 2008 at 04:36pm

Extracting archived files from the command line

As an example yesterday, I told you how to download the WordPress installation stuff. So, I might as well tell you how to untar (or, unzip?) it! It's simple really.

Go to the directory you want to unzip it to...

cd /var/www/wordpress/

And then unzip it...

tar xfz /home/shamess/downloads/latest.tar.gz

Here's what those options do...

x

Tells tar to extract it, rather than archive something

f

Tells tar that you're giving it an archived file

z

Tells tar that it's also a gunzipped (.gz) file.

Some people like to add v too, which shows you a list of the files as it unzips them.

3 comments

Saturday, 8th March 2008 at 12:55am

Download something from the net, straight to your server

If you're looking to download something from the internet, there's no need to download it to your local machine first, then upload it (which is what I would have done before I found out about this). You can use wget. If I wanted to get WordPress, I'd do the following command:

wget http://wordpress.org/latest.tar.gz

That will download WordPress to your current folder. If you want it somewhere else, you can use the -P switch, like so.

wget -P "/home/shamess/downloads/" http://wordpress.org/latest.tar.gz

You can also log into an FTP server, or any HTTP directories that need authentication, using --user and –password. Which is what I should have done when I was transferring files from my old server to this one.

0 comments

Thursday, 6th March 2008 at 12:50am

Send PuTTY to the system tray in Windows

Instead of getting PuTTY from the place I linked to before, you should get it from here: PuTTY Tray. It's exactly the same as the PuTTY you know and love, but it comes with added features like reconnecting when you come out of stand by, and being able to send PuTTY to the tray when you're not using it.

0 comments

Monday, 3rd March 2008 at 10:48pm

Speed up your CLI with aliases

There are a lot of switches to a lot of commands and sometimes they're just too long to remember, or you're just too lazy to type them. In cases like this, you can use aliases. They're basically shorthand for commands you use a lot.

For instance, to log onto MySQL I have to use the command:

mysql --user=dangermouse --password=letmeinplox

It gets a little boring typing that over and over again. Also, PuTTY doesn't hide the password as you're typing it which can be a little dangerous. An alias fixes both of those problems. Just do:

alias my_mysql='mysql --user=dangermouse --password=letmeinplox'

"alias" is the command, "my_mysql" is the new alias/command I'm creating, and the rest is what I want it to be. So, now I can type "my_mysql" and it'll log me into my MySQL server.

If you pick a name for your alias that already exists, the original one will just got overridden.

Unfortunately, you'll have to create this alias every time you log onto your server. You can fix that by adding it to your .bashrc file, which is in your home directory, (so, mine is /home/shamess/.bashrc). That file should already have a few aliases in it, so take a look around it for examples.

2 comments

Saturday, 1st March 2008 at 12:30am

Name-based virtual host from your VPS, thanks to Apache

My situation: I was running www.allroundnews.co.uk fine on my shared host server, SH5 (thanks BEA Solutions ^^). Then I decided to switch to my VPS, Trinity, to run this blog. This blog is run from Trinity, but the rest of *.allroundnews.co.uk is still run from SH5. I realised that I was using up valuable space and bandwidth on SH5, when I had tonnes of both on Trinity. That's when I decided to run a virtual host for both of them. Here's how.

First, we have to fix the default Apache2 configuration, which isn't quite ready for vhosts yet. As root, edit the file /etc/apache2/sites-availiable/default. At the moment, mine and yours, if you haven't edited, looks like this, (well, I've changed the ServerAdmin, but that's about it.) We need to add the server name directive. That's just the URL that you want this vhost to be found at. I just had to add:

ServerName trinity.allroundnews.co.uk

That's fixed that. Since I'm running Trinity from a subdomain, that's all I need to add, but if you're expecting users to be able to use the www. prefix for your website, then you'll need to add a ServerAlias. If you're website is debianisawesome.com, you'd have something like the following:

ServerName debianisawesome.com

ServerAlias www.debianisawesome.com

Now that's fixed, we need to set up another VirtualHost for us to be using. In it, you need at least the ServerName and DocumentRoot directives. Remember, the ServerName is the URL Apache is "listening" for. The DocumentRoot is where it gets its files from. Try make this different from your default one, else it'll just get confusing. Here's what I've added to mine:

<VirtualHost *>

        ServerName www.allroundnews.co.uk

        ServerAlias allroundnews.co.uk *.allroundnews.co.uk

        DocumentRoot /var/www-allroundnews/

</VirtualHost>

I went ahead and created /www-allroundnews/ too, and gave myself permissions.

My new config file can be found here.

All you need to do now is copy all your files from one server to your VPS. I did that by getting them all from SH5 using FTP, then uploading them all to Trinity using WinSCP. Any better way than that; comment, please!

Then, remember to point your old DNS records to your server, and you're good to go.

5 comments

Tuesday, 26th February 2008 at 09:58pm

DNS servers are hard...

Tonight's post was going to be about setting up your own DNS server, using bind. Instead, tonight's post will be about how impossible it is, and that you should stick with your domain registrar. They'll usually handle your DNS for you anyway, for free.

As always, installing bind was easy. Setting it up was a bitch though.

I wanted to run the Shamess Productions home page from this server, as a secondary nameserver. Thankfully, I know my DNS host personally so I could talk to him about finding his hashkey for RNDC, but even then it was confusing. I'd imagine it to be almost imposible to get that from GoDaddy or someone.

And even with that, I still had no idea why I wasn't synchronising.

Honestly, there's better things you can do with your server's resources than run a DNS server.

I will cover this in detail some time later though, so stay tuned. (If I get inundated with comments ask how to do this, I'll do more research and get it up faster.)

In the meantime, stick with the DNS server of whoever you registered your domain. Just ask them to point an A record for your domain to the IP address of your server.

1 comments

Tuesday, 26th February 2008 at 12:05am

Using nano with switches to make it a better experience

I haven't really mentioned anything about nano, except for the short paragraph I wrote about it in that command quick sheet I wrote, which is odd since it's the default editor for Debian; you'd think I'd wanna learn how to use it effectively.

nano is actually really quite easy for a fairly basic piece of software. You can just type normally from in the app, and it'll be stored as text. The most common functions are in the two bars at the bottom of your window. In case you didn't know, the caret (^) means "press control key and...", so ^C would be control and C.

Why they can't use Windows terminology though, is beyond me.

What nano says

What it means

WriteOut

Save

Read File

Open

Cut text

Cut the entire line

Uncut text

Paste the line

You can see a lot of other commands by doing ^G for the help.

There's also a few cool things that you can do when starting nano, with switches.

Switch

Affect

-A

Makes the home key act like it does in Notepad++, where the cursor jumps to the first non-whitespace character, instead of right at the beginning of the line. This is helpful if you're indenting a lot.

-B

Once you've saved the file you're editing, it'll first back up the original file and it'll suffix it with a tilde; so apache.conf would become apache.conf~, and your edited one will replace the original.

-C backupdirectory

Use this with -B, if you don't want the file saved in the same directory.

-S

By default, when you go down to the bottom of a file it'll act like you've just pressed page down and show you all new stuff. With this option, you'll just go down line by line.

-W

Working command line is sometimes annoying. If you get the end of a sentence at the end of the line, the full stop will drop to the next line, since it's not the same word. It'll be treated properly with this switch though.

-i

Another Notepad++ like behaviour. If you're already indented, and drop to the next line, you stay indented.

You can see the command manual at the official nano site.

1 comments

Sunday, 24th February 2008 at 07:21pm

Managing your users on Debian

We added a user before to use for ourselves, but I never really went into how to change your password or delete a user, or a lot of other things you can do.

To change your full username, use chfn -f newusername. You can change the other information you added too, just do a manual lookup to get them (man chfn).

You can change your password by using the passwd command. You'll have to put your old password in first, unless you're root, and then your new one.

You can also delete a user, using deluser usertodelete. Obviously, don't go deleting your own user.

1 comments

Friday, 22nd February 2008 at 12:31am

Making your default mail server work (Exim4)

If you're using mail functions on PHP after just installing it, you won't get any error message, even though the mail won't get sent yet. Don't worry, we'll fix that now.

Debian comes with Exim4 which is a mail server with a bunch of features. By default it's set to only send emails locally (to other users on your system). If you tried to send any emails to external users at the moment, you'll see something like "** www-data@debian R=nonlocal: Mailing to remote domains not supported" in your error logs.

We just need to reconfigure your Exim4 options, which you can do by typing the command "dpkg-reconfigure exim4-config".  Then you'll get a screen, which you'll have to answer a few options. A lot of them are easy but they can be a bit off putting.

I don't think there's much reason to split configuration files (comment if I'm wrong). Your system mail name should be your URL, including the subdomain if that's where you've pointed your VPS. For instance, mine is "trinity.allroundnews.co.uk", so all email addresses will be 'user@trinity.allroundnews.co.uk'. Let the 'listener daemon' listen to all IPs, by just leaving it blank. Say no to 'Dial-on-Demand'. The 'Root and postmaster mail recipient' is basically the user that you want mail to 'root@trinity.allroundnews.co.uk' to be redirected to (since you shouldn't stay logged in as root). So for me, that's just 'shamess'.

If you've tried to send any mail so far, you'll want to remove it from the queue (sorry if it was important). Do that by getting up the mail queue (using the mailq command). Then you can remove mail by using the command Exim -Mrm <message id>. You can put as many message ID's in the list as you like, space separated. The message ID is the weird string that looks something like ’1JOJBI-0000ag-IH'. Yup, you have to type that.

I'll talk about actually reading mail later, but at least now you can send mail with PHP!

1 comments

Monday, 18th February 2008 at 03:21pm

Installing PHP and MySQL, and then getting them working

Now we have our web server set up and you can upload your files and things securely, we need to make sure all your PHP files are being complied properly.  You'll probably be using MySQL too, so let's do that at the same time.

Start up PuTTY and connect. Installing PHP is shockingly simple. Type apt-get install php5, you'll have to be logged in as root. PHP4 is about to have its last security updates, so there's no point in getting that now. After that, I don't actually remember having to do anything other than restart Apache (/etc/init.d/apache2/ restart).

There's an article on AboutDebian about some web server stuff. That gives a few more steps in installing PHP, but I don't remember having to do those. That could be because they're using Sarge (I'm using Etch) and PHP4 (we're installing PHP5).

Now to install MySQL. This is simple too, just use apt-get again, but this time you're looking for mysql-server. If you have to, tell it to start at boot up, so that it runs automatically without you having to start it manually.

Then you'll need to install the php5-mysql package to make them work together. Then we need to let PHP know to load that module, to do that we need to edit the php.ini file. You can do that by typing (if you have the same set up):

nano /etc/php5/apache2/php.ini

Then, do a search for:

;extension mysql.so

And simply uncomment that line. Save it, and then restart Apache and everything should be up and running. Go and make a phpinfo() file and it should list MySQL as a module.

0 comments

Saturday, 16th February 2008 at 01:27am

URL structures for AyTwo blogs (like this one)

Note: At the moment, FCKEditior that I use as my rich text editor seems to like to rewrite the URLs I give it however it wants to. As a result, the /blog/ part of the URL is missed off a couple links so instead of going to http://trinity.allroundnews.co.uk/blog/2008/02/13/Debian-cheat-sheet/  you end up going to http://trinity.allroundnews.co.uk/2008/02/13/Debian-cheat-sheet/ which obviously isn't this blog. Fortunately though, I don't have any /2008/ directories (or any others for that fact), so I've set up a rewrite rule to fix it for the moment. That doesn't mean much to you guys though, since you won't see a difference.

I wanted to come and let you know about the various URL structures you can have with this blog (and indeed any other blog that happens to be running AyTwo successfully – which is none at the moment).

First is the standard URL which is /blog/; that gets you to the landing page for this blog. On it you'll see all the most recent posts that have been made, just like you'd expect.

The next type of URL you'll be using a lot is that which goes to an individual post, like this: /blog/2008/02/15/Use-WinSCP-for-file-transfer-not-FTP/. Obviously, it's made up of the title of the post, in a URL safe fashion, along with the date that it was posted in a /YYYY/MM/DD format.

You can also just get rid of the post title, and you'll see all the post that happened on the 15th February, 2008. Get rid of the day and you'll see all the posts that occurred in that month. And the same with the year, shockingly.

A different format of URL is the way we look at tags. The date mode and tags mode can't be mixed up yet, so don't try it. Bad things will happen, in the same way as bad things happen to you if you google Google and break the internet. The tags format is simple: /blog/tags;Windows-applications/. Just the word tags; followed by the tags you like. (I decided to use semi-colon because Windows machines break if you use a colon.) You can comma separate (no space though) different tags if you like. For instance, if you want to see all the entries about commands and terminology, you'd use the URL like this: /blog/tags;Commands,Terminology/.

Last for the moment, is the skip URL. Add /skip;10/ to any URL if you want to skip the first ten entries. This can be used with the other URL formats.

0 comments

Friday, 15th February 2008 at 04:10pm

Use WinSCP for file transfer; not FTP

Now we've set up our Apache server and fixed the permissions so you can edit the files in there, but if you're like me you'll have already been working on your own local server and you'll have lots of files you want to upload.

If you can understand how to use the SCP command, then well done you deserve  a medal. I, on the other hand, really couldn't find the energy to read that without my mind wandering. Instead, I went and asked what the best package for an FTP server was. On #debian I was greeted with moans and growls. Upon enquiring about the odds sounds being emitted, I found out that FTP was a stupid idea.

It sends everything in plain text, including passwords and stuff so it's really actually quite dangerous for business as serious as the internet. Instead, they directed me to WinSCP. I just downloaded the bland "installation package".

Go with the "Norton Commander" view if you've ever used an FTP client and you should feel right at home. It's essentially exactly the same thing, except it's more secure.

Remember to log in as your user, you already have access to your /var/www/ directory, so you should be fine. For now, just use your password and leave private key blank, I'll talk more about that later. I also switched the File protocol to SCP. If you like, you can save what you've entered, so it will be there as default.

0 comments

Read some previous entries