Ubuntu Server Setup – Top 5 things to do on the First Day

You’ve just unwrapped your new Ubuntu server running on Ubuntu 12.04 LTS and now it’s time to roll up your sleeves and get started. What should you do first? Here’s a checklist of the top things I do for each new Ubuntu server that I install.

Let’s approach it from two ways:
– You’re working with a managed network provider like Rackspace, etc… or
– You’re doing it yourself on AWS as a new EC2 instance (Similar to managed, with some caveats).

You have your server credentials and have logged on to your server with a SSH connection. You are staring at your command prompt and are ready to begin…
1. Check your server to make sure you got what you wanted

Are the drives partitioned right? Do you have any space on /var to work?

df -h

What release are you running? The current (as of 2/13) latest LTS version of Ubuntu is 12.04.x

lsb_release -a

2. Update your copy of distribution files.

sudo apt-get update

This will make sure that as we get started installing new software, we’ll have the latest and greatest of everything.

3. Install The LAMP stack ([Linux], Apache, MySQL, PHP) We’ll want to throw in phpmyadmin here as well. In case you aren’t familiar, phpmyadmin is great for setting up database permissions and general DB management from within a browser-based GUI.

sudo apt-get install lamp-server^ phpmyadmin

Answer Yes to the prompts as it installs each of the requested programs in the LAMP stack. You’ll need to pick out a password for MySQL and then confirm it. Later you’ll be asked for a password for phpmyadmin. Use the same password, it will make things easier for later. (You can always change your password later from within MySQL or PhpMyAdmin.

4. Install htop
htop is essentially “top” on steroids. It gives you a good visual picture of your server’s load and what processes are running. It’s sort of like the baby monitor of servers.

sudo apt-get install htop

5. Setup a test web page
You’ve installed apache, so you can test that everything is set correctly. Go to your default web root directory /var/www (this can be changed later, and we’ll show you how to do that in our next blog in this series)

cd /var/www

Now, edit the file index.html and put in some text that identifies it as your new server.

sudo vi /var/www/index.html

(or .php, or .htm depending on your configuration)

Now start or reload apache to make sure everything is running right.

sudo service apache2 reload

After you’ve saved the file, you can go to a browser window and type in your server ip address. You should see your temporary index page that you just created/edited.

Next…
Configuring Apache, setting up cron jobs, rsync to synchronize with multiple servers, setting up MySQL database connectivity, and more…
Check out our other blog posts on these topics.

Ubuntu Server AWS EC2 ELB Apache Log Fix

If you’ve launched AWS EC2 server instances behind a load balancer, then you’ve probably noticed that your Apache logs are showing the internal ip address of the load balancer for all entries.

I’ve seen a few blogs that explain that the reason for this is that the ELB load balancer is configured as a reverse proxy and the actual ip address of the origin is masked.  Aside from the cosmetics of seeing thousands of log entries all with the same ip address, this is actually bad for SEO as your sitemaps will also be showing all your visitors coming from one ip address.  Also, if you are using geoip the country filter won’t work as it will be looking at all visitors as coming from Amazon’s region that your EC2 instances are located.

Here’s the fix:
Very simple actually.  It worked for me on Ubuntu 12.04 LTS and I assume it will work on any Linux configuration.  Instead of logging the Host (which in our case is the internal ip), we want to log the X-Forwarded_for which is the origin ip for the entry.
Open your apache configuration file for edit.  On Ubuntu it’s at /etc/apache2/apache2.conf    You can also use locate to find it on your instance if it’s not on Ubuntu.  locate apache2.conf

sudo vi /etc/apache2/apache2.conf

Next within configuration file look for the section with LogFormat   There should be several lines beginning with LogFormat.  The top three should be for vhost_combined, combined, and common.   In all three lines where you see %h  (which is echoing to the apache log the host) change that to %{X-Forwarded-For}i

Before

LogFormat “%v:%p %h %l %u %t \”%r\” %>s %O \”%{Referer}i\” \”%{User-Agent}i\”” vhost_combined
LogFormat “%h %l %u %t \”%r\” %>s %O \”%{Referer}i\” \”%{User-Agent}i\”” combined
LogFormat “%h %l %u %t \”%r\” %>s %O” common

After

LogFormat “%v:%p %{X-Forwarded-For}i %l %u %t \”%r\” %>s %O \”%{Referer}i\” \”%{User-Agent}i\”” vhost_combined
LogFormat “%{X-Forwarded-For}i %l %u %t \”%r\” %>s %O \”%{Referer}i\” \”%{User-Agent}i\”” combined
LogFormat “%{X-Forwarded-For}i %l %u %t \”%r\” %>s %O” common

Then remember to reload apache

sudo service apache2 reload

Note of Caution: It’s relatively easy for someone to spoof the header and change the X-Forwarded-For to whatever address they want. That would mask from you their actual ip. Therefore, this solution is not intended for applications that have security implications.

Another tip. Within your web application if you are using the ip for any purpose, like Maxmind’s geoip, you’ll need to echo the X-Forwarded-For instead of the Remote host as well. e.g. $ip=$_SERVER[‘HTTP_X_FORWARDED_FOR’];

Let us know if you have any suggestions on how to improve this method.

Ubuntu Server – How to Sync Files Between Multiple Web Servers

Another installment in our How to Set up an Ubuntu Server Series:

Synchronizing multiple servers – You have more than one web server in your host configuration. What’s the easiest way to synch files among the multiple web servers?
Solution – rsync does the trick efficiently and easily.

This tutorial assumes you are comfortable on the linux command line.

Steps to Set up rsync for multiple servers synchronization:

Step One

First make sure rsync is installed on each server that you’ll be working with.  By typing rsync from a command prompt, you should get the rsync response asking you for parameters.  If rsync isn’t found, then install it.

sudo apt-get install rsync

Step Two

Test synchronizing files.  From a command prompt on your 2nd server, type in an rsync command to retrieve files from the 1st server.  Let’s assume you have a directory /var/www/ set up on both servers and you wish to synchronize the files from the first server to the 2nd. The first server acts as the master.  Any new files or changes to existing files on the master will overwrite existing files on the 2nd server.  Type in from the command prompt on server 2

sudo rsync -ra user@FirstServerIP:/var/www/ /var/www/

The first server in this example sends all the files in /var/www/ along with the (-r) recursive subdirectories. You can also sync only specific files, etc…
If this works, you are ready to move on to step 3. If not, check your connectivity with the FirstServer. Generally, if you can ssh to another server, you should be able to rsync with it as well. AWS EC2 Users If you are using AWS Amazon’s ec2 servers, which require a passkey, the rsync command will look like this:

rsync -rave “ssh -i /home/ubuntu/.ssh/passkey.pem” ubuntu@EC2ServerIP:/var/www/ /var/www/

Note that for AWS EC2, you will first need to copy your passkey over to your .ssh directory

Step Three

Next, let’s set this up to synchronize all the time automatically. We accomplish this with a cron job. Here again, we’re assuming you are familiar with how to set up and edit crons. From your root user (sudo su) edit your crontab

crontab -e

Then, add a line to the crontab that tells it to run the rsync command every minute (or any frequency that suits you).

* * * * * rsync -ar FirstServerIP:/var/www/* /var/www/

Test your configuration!  Go to your first server and make a change or add a file to the synchronized directory. Then go back to the 2nd server and see if the file is there. You can replicate this process to as many servers as you need, but keep in mind that frequency of sync and amount of data passing on your internal network can get costly and cause a hit on performance.

I hope this little tutorial was helpful.  Please drop me a note if you have any questions or comments.

 

How Much Bandwidth Used in a 128k Radio Stream

How Many Megabytes in a 128k Music Stream?

How much bandwidth is consumed on your internet connection when you listen to online radio, or watch music videos and clips on Youtube?

Let’s start with the most popular stream rate for online radio and internet radio stations. 128kbps means 128 kilobits per second.

So how do we translate that into bandwidth on my internet connection?
Continue reading “How Much Bandwidth Used in a 128k Radio Stream”

Ubuntu How to Change Color Linux Directory Listings

Here’s another change I automatically make when installing a new Linux Ubuntu Server.
I’m using Bash prompt, and that’s the standard prompt for all Debian (Ubuntu, Mint, etc…) installations, so the chances are that you are using Bash too.

Problem:
The standard default color scheme for Linux directory listings (when you type in ls at the linux prompt) is hard to read. If you’re using putty on a Windows machine to connect to a linux server, the color scheme is dreadful. The deep blue is simply illegible for me.
Continue reading “Ubuntu How to Change Color Linux Directory Listings”

WordPress How to Setup Automatic Backup Entire Blog

If you run a WordPress blog on a Linux server, let me show you how to very easily set up an automatic backup.
You can set the frequency of the backups and the saved files of the entire blog/website will be added to a directory of your choice.
Continue reading “WordPress How to Setup Automatic Backup Entire Blog”

How to Get USA Proxy Using Your AWS Server – Three Easy Steps

If you have an AWS Amazon Web Services Linux Web Server, you are in luck.  Creating a full USA Proxy Server has never been easier.

Here’s a quick guide that will show you how to set up a proxy server using your existing AWS server.

We’ll show you in just a few easy and completely free steps how to create a winproxy tunnel. Your local PC will take the IP address of your AWS server.
Continue reading “How to Get USA Proxy Using Your AWS Server – Three Easy Steps”

How to Make Streamripper Save UTF8 Filenames

I’m assuming you came here because you are already using Streamripper on the command line.
This fix is for those who rip streams with filenames that are not the basic character set (Not English).

If you are seeing ripped file names that look like this øòåú çï – áùãä éøå÷.mp3 then here is the solution:

On the linux command line, use the following directive:
Continue reading “How to Make Streamripper Save UTF8 Filenames”

Ubuntu Server – Configure and Run Multiple Websites on One Server

Here’s a simple tutorial to get many websites running on one ubuntu server
Let’s say you have root access to your own server and want to run many websites on it. If you have Ubuntu Server running with Apache, I will show you in a few easy steps how to configure and run as many websites on your server as the load can handle.

Follow these simple instructions and your additional websites will up and running immediately.

Pre-Install Checks
1. You should have Ubuntu Server 8.04 (or later) running.  You can check your Ubuntu server version by typing this in a terminal prompt   cat  /etc/lsb-release
You should see:
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=8.04
DISTRIB_CODENAME=hardy
DISTRIB_DESCRIPTION=”Ubuntu 8.04.1″

2. You should have apache2 running. The easiest way to check is from your terminal prompt type
cd /etc/apache2
if you are now in the /etc/apache2 directory, then we can assume it’s on your server.

Simple Steps to run multiple websites
First, prepare the directories on your server to point the new domain you want to add.
I usually do something like this:
/var/www/docs/ is the base
domain-name.com/ is the domain
public for files that are accessible to apache and the world
private for files that are accessible to apache only (like crons, included header files, etc…)
log for a place to log the entries and errors
backup for a place to save files

For example, if you are adding abc.com, you would create the following using terminal
cd /var/www/docs
mkdir abc.com
cd abc.com
mkdir public private log backup

Next, let’s go to apache and tell it we are ready to add more domains to the configuration.

Type in your terminal cd /etc/apache2
open the file (I use vi) vi apache2.conf
Look for

# Include the virtual host configurations:
Include /etc/apache2/sites-enabled/
NameVirtualHost *:80

If it isn’t there, add it. Then save the file. (always make a backup before making changes to any server file)

Next, let’s go to the existing website configuration directory and add our new domain
Type in the terminal cd /etc/apache2/sites-available
You’ll probably see a file default or 000-default
Note: The default configuration on apache is what tells the server where to look for index.html each time someone types in the ip address of your server, or the domain name you have already configured. It also tells apache where to log each server event. After you’ve added other domains, you may want to revisit the default file and decide which domain traffic should go to in the event the ip address is entered, and not the domain name itself.

Next, let’s prepare another file to tell apache there’s another domain to look for aside from the default.
Copy the default file to a new file with the name of the additional website(s) you want to run on this server. For example, let’s say you want to have abc.com on this server. you would type this command cp default abc.com

Next, edit the file you’ve just created to point to the directory on your server where you’d like to manage the files for that domain.
My apache config files look like this:


#
ServerAdmin webmaster@abc.com
DocumentRoot /var/www/docs/abc.com/public
ServerName abc.com
ServerAlias www.abc.com

Options FollowSymLinks
AllowOverride None


Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all


RewriteEngine On
RewriteBase /
ErrorDocument 404 /index.php

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all

ErrorLog /var/www/docs/abc.com/log/error.log
LogLevel warn
CustomLog /var/www/docs/abc.com/log/access.log combined
ServerSignature On
Alias /doc/ “/usr/share/doc/”

Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128

You will want to edit the file to meet your own needs. I copied mine here as an example. It would be better for you to edit the new file you’ve copied from your default.

Take care to enter the exact directory names of your new domain and make sure nothing is misspelled. Apache is not forgiving at all. When you try to reload apache, if one directory name is missing, the entire apache server will crash until you fix the offending entry.

Once you are sure the configuration file is accurate, save it and let’s move on.
From terminal, type in cd /etc/apache2
Next, type in a2ensite abc.com (the name of your domain instead of abc)
a2ensite is the command that creates a symlink for apache from sites-available to sites-enabled and tells apache you’re ready to accept traffic for this domain
Assuming you typed everything correctly, you should get a message back
Site abc.com installed; run /etc/init.d/apache2 reload to enable.
Then, simply reload apache
If you get
* Reloading web server config apache2 [ OK ]
Then you should be up and running with your new web domain
Put a sample file in your new domain’s public directory.
For example, open a new file index.html vi /var/www/docs/abc.com/public/index.html
edit it with a message like You got to the new domain 🙂
Save the file, then test by typing in your new domain in a web browser and seeing if that message appears.

To add more domains, simply start at the top of this page again.

We have tried to make this primer as straightforward as possible. As with anything, there is always a deeper level of understanding and things you can configure. First, we got the domains up, next we can tackle other issues like security, ports, etc… which will be discussed in future posts.

We hope you have found this useful, please add your comments and suggestions on how to improve the steps provided here.

Qadabra Malware or Legit Review

Qadabra Ad Network invited us to join their publisher network for display ads and pop ups.

We get so many requests for publisher networks that it’s hard to separate the legit from fakes. The first phase of review seemed to produce favorable results. The email invitation comes from an actual person with an actual mail address and phone number. I was able to search and find enough information about that person (Linked In page, Facebook, etc…) to believe that they are a legit company. Additionally, their website and community discussion groups suggest they are a good alternative or supplement to Google’s Adsense Network.
Continue reading “Qadabra Malware or Legit Review”