Directory names not visable under ls? Change your colours.

There is a problem I frequently encouter on Redhat/Fedora/CentOS systems with the output of the ls command. Under those distributions, the default setup is to display directories in a very dark colour. If you usually use a white foreground and a black background on your terminal client (such as Putty) then you will struggle to read the names of the directories under Redhat-based distributions.

There are two soloutions that I have used:

1. Change the colour settings in Putty

If you use Putty, ticking ‘Use System Colours’ here changes the “white foreground, black background” default into a “white background, black foreground”. This way you can at least read the console properly, good for a quick fix. You can also save these settings in putty to be the default for the host that you are connecting to, or even all hosts.

2. Change the LS_COLORS directive temporarily in the shell.

Alternatively, you can ask the ls command to display directories and other entries in colours that you specify. You could add these lines to the bottom of your .bashrc to make these changes permanent, or if you are using a shared machine, just copy and paste the following lines into the terminal and they will change the colours to a reddish more visable set, until you logout. :

alias ls='ls --color' # just to make sure we are using coloured ls
LS_COLORS='di=94:fi=0:ln=31:pi=5:so=5:bd=5:cd=5:or=31:mi=0:ex=35:*.rpm=90'
export LS_COLORS

(Original source for this particular LS_COLORS combo: http://linux-sxs.org/housekeeping/lscolors.html)

VirutalHosts on CentOS

A common task when setting up an Apache webserver under Linux, is writing a httpd.conf file. The httpd.conf file is the main configuration file for Apache. One of the main reasons to edit the httpd.conf file is to setup virtual hosts In Apache. A Virtual host configuration allows several different domains to be run off a single instance of Apache, on a single IP. Each host is a ‘Virtual host’, and typically has a different web root, log file, and any number of subdomains aliased to it. The virtualhosts are configured in parts of the httpd.conf file that look like this:


    ServerName myserver.co.uk
    ServerAlias www.myserver.co.uk
    ServerAdmin me@myserver.co.uk
    DocumentRoot /var/www/html/myserver.co.uk
    ErrorLog logs/myserver.co.uk-error_log
    CustomLog logs/myserver.co.uk-access_log common

Now on Ubuntu, virutalhosts are made easy. The httpd.conf is split into several files. Each virutalhost has a different file in /etc/apache2/sites-available. When you want to activate a particular vitualhost, you create a symbolic link from /etc/apache2/sites-enabled/mysiteto /etc/apache2/sites-available/mysite (if you wanted to call your site configuration file ‘mysite’). When apache boots up, it loads all the files it can find in /etc/apache2/sites-available/* and that determines which virutalhosts it loads. If there is not a link from /etc/apache2/sites-available/ to your virutalhost file, it won’t load it. So you can easily remove the links in /etc/apache2/sites-available without deleting the actual virutalhost file. Therefore you can easily toggle which virtualhosts get loaded.

CentOS uses a different structure. Everything is lumped into /etc/apache/httpd.conf. So there is no way to easily toggle virutalhosts on/off, and everything is a bit more chaotic. I’ve just had to setup a new CentOS webserver, and I struggled for a bit after being used to ubuntu-server. Here’s a format you can use if you’re in the same boat, and you have to setup httpd.conf files for CentOS:

NameVirtualHost *:80 # this is eseential for for name-based switching

# an example of a simple VirtualHost that serves data from 
# /var/www/html/myserver.co.uk to anyone who types in
# www.myserver.co.uk to the browser

  ServerName myserver.co.uk
    ServerAlias www.myserver.co.uk
    ServerAdmin me@myserver.co.uk
    DocumentRoot /var/www/html/myserver.co.uk
    ErrorLog logs/myserver.co.uk-error_log
    CustomLog logs/myserver.co.uk-access_log common 


# an example of a VirutalHost with apache overrides allowed, this means you can use
# .htaccess files in the servers web root to change your config dynamically

    ServerName bobserver.co.uk
    ServerAlias www.bobserver.co.uk
    ServerAdmin me@bobserver.co.uk
    DocumentRoot /var/www/html/bobserver.co.uk
    ErrorLog logs/bobserver.co.uk-error_log
    CustomLog logs/bobserver.co.uk-access_log common
 
  
      AllowOverride All
  
  
      AllowOverride AuthConfig
      Order Allow,Deny
      Allow from All
  


# an example of a VirutalHost with apache overrides allowed, and two subdomains
# (mail and www) that both point to the same web root

  ServerName fredserver.co.uk
    ServerAlias www.fredserver.co.uk
    ServerAlias mail.fredserver.co.uk
    ServerAdmin me@fredserver.co.uk
    DocumentRoot /var/www/html/fredserver.co.uk
    ErrorLog logs/fedserver.co.uk-error_log
    CustomLog logs/fredserver.co.uk-access_log common
 
  
      AllowOverride All
  
  
      AllowOverride AuthConfig
      Order Allow,Deny
      Allow from All
  


# .. etc

With the above structure, you can add as many VirutalHosts to your configuration as you have memory to support (typically dozens). Apache will decide on which to choose based on the ‘ServerName’ specified in each VirtualHost section. Just remember to add that all-important NameVirtualHost: *:80 in the beginning.

Once you’ve got your httpd.conf file the way you like it, be sure to test it before you restart apache. If you restart apache and your httpd.conf file has errors in it, Apache will abort the load process. This means that all the websites on your webserver will fail to load. I always use apachectl -t or apache2ctl -t before I restart. That will parse the httpd.conf file and check the syntax. Once that’s OK, then you can issue a /etc/init.d/httpd restart to restart Apache.