Set up Linux (Ubuntu) server to synchronise clock with NTP time server

ntupdate

ntupdate comes built in into Ubintu server. To manually adjust server time run:
sudo ntpdate ntp.ubuntu.com
You can choose another ntp server instead of  ntp.ubuntu.com

ntpd

To automatically keep server time up to date use ntp.

Install ntpd:
sudo apt-get install ntp

ntpd should start working immediately without any additional configuration. However you obviously can adjust settings if you wish.

Configuration

ntpd configuration file is located in /etc/ntp.conf

Default server is server ntp.ubuntu.com
To use additional servers just add them bellow server ntp.ubuntu.com. e.g.
# You do need to talk to an NTP server or two (or three).
server ntp.ubuntu.com
server pool.ntp.org


To enable logging uncomment:
statsdir /var/log/ntpstats/
logs will be placed in /var/log/ntpstats/

Useful commands

Reastart ntp
sudo /etc/init.d/ntp restart
Stop ntp
sudo /etc/init.d/ntp stop
Start ntp
sudo /etc/init.d/ntp start

List peers and status
ntpq -p

Check in ntpd process is running
ps ax | grep ntp

Ubuntu Server 10.10


Disable directory listing (index) in Apache


/etc/apache2/httpd.conf
Add line
Options –Indexes
sudo /etc/init.d/apache2 reload

OR

/etc/apache2/sites-availabl/[sitename]
find line:
Options Indexes FollowSymLinks MultiViews
And add "-" in front of the "Indexes":
Options -Indexes FollowSymLinks MultiViews
sudo /etc/init.d/apache2 reload

Ubuntu Server



Apache2 on Ubuntu – Hosting multiple websites

Create directories for a new site. E.g.
/var/www/sites/mysite.com/htdocs
/var/www/sites/mysite.com/logs
/var/www/sites/mysite.com/cg-bin


In /etc/apache2/conf.d/ create new file virtual.conf
#
# Running multiple virtual hosts.
#
NameVirtualHost *


/etc/apache2/sites-available
This contains configuration files for sites which are available but not necessarily enabled.
/etc/apache2/sites-enabled
This directory contains site files which are enabled.
Each configuration file in the sites-enabled directory is loaded when the server starts - whilst the files in sites-available are ignored.
Configuration files should be created in sites.available and later enabled running a2ensite command if needed (see bellow).

Create /etc/apache2/sites-available/www.mysite.com with the following contents:

<VirtualHost *>
ServerAdmin This email address is being protected from spambots. You need JavaScript enabled to view it.
ServerName  www.mysite.com
ServerAlias mysite.com

# Indexes + Directory Root
DirectoryIndex index.php index.html
DocumentRoot /var/www/sites/mysite.com/htdocs

# CGI Directory
ScriptAlias /cgi-bin/ /var/www/Sites/mysite.com/cg-bin
<Location /cgi-bin>
Options +ExecCG
</Location>

# Logfiles
ErrorLog  /var/www/sites/mysite.com/logs/error.log
CustomLog /var/www/sites/mysite.com/logs/access.log combined
</VirtualHost>

Enable site:
a2ensite www.mysite.com
(To disable - a2dissite www.mysite.com)
This puts symbolic link in sites-enabled

Restart apache:
/etc/init.d/apache2 reload

In addition (after change from one website to multiples):
Delete: default in sites-available and 000-default in sites enabled

Default site:
One of the sites is a default site. Default site is loaded when server can't match URL address.
It looks like the default site is the one which comes first in alphabetical order in sites-available folder. 

To stop warning NameVirtualHost *:80 has no VirtualHosts when reloading apache
/etc/apache2/ports.conf
Comment:
#NameVirtualHost *:80

To stop warning apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName when reloading apache
/etc/apache2/apache2.conf
Add Line:
ServerName www.mysite.com


Ubuntu Server 10.10

Ubuntu server network stops working after moving to another VMware host

Delete:
/etc/udev/rules.d/70-persistent-net.rules

Restart machine
This will update the MAC address

More Articles ...

  1. Set up Ubuntu Web Server