How to: Install and Setup ntpdate on Debian

ntpdate is a client that allows you to keep both system date and time synchronized, by connecting to an NTP server.

The use of ntpdate is very useful in server systems, so you have always date and time in your time zone.

To select the NTP server in your time zone check out this site http://www.pool.ntp.org

Install ntpdate

on shell, as root user, type apt-get install ntpdate

root@massimilianomarini ~ # apt-get install ntpdate

Scheduling ntpdate for automatic update

to keep aligned both date and time of the server, you can schedule ntpdate in cron system by following these simple steps.

1. Edit the file /etc/crontab and add the following line at the bottom of the file's contents

5 *	* * *	root	/usr/sbin/ntpdate -v -b 0.it.pool.ntp.org

simply, we are telling the cron to run the command line /usr/sbin/ntpdate -v -b 0.it.pool.ntp.org as root user every 5 minutes.

2. Reload the configuration of cron service with the command /etc/init.d/cron reload

root@massimilianomarini ~ # /etc/init.d/cron reload

3. Restart the cron service with the command /etc/init.d/cron restart

root@massimilianomarini ~ # /etc/init.d/cron restart

Leggi questo post in italiano

How To: follow Symbolic Links with Pure-FTPd

My need was to share a directory with a chrooted user, and with Pure-FTPd doing it is very easy.

The FAQ is very exhaustive, I recommend you read it, here in my case I go directly to the point.

From the official FAQ http://download.pureftpd.org/pub/pure-ftpd/doc/FAQ

Making a symbolic link won't work, because when you are chrooted, it means that everything outside a base directory (your user's home directory) won't be reachable, even though a symbolic link.

If you are compiling Pure-FTPd from source, add --with-virtualchroot to your ./configure options.
Binary packages are compiled with this feature turned on, and this is my case.

Open this file: /etc/default/pure-ftpd-common

and set the VIRTUALCHROOT option to TRUE, by default is set to FALSE.

# VIRTUALCHROOT:
# whether to use binary with virtualchroot support
# valid values are "true" or "false"
# Any change here overrides the setting in debconf.
#VIRTUALCHROOT=false
VIRTUALCHROOT=true

Restart the Pure-FTPd server with /etc/init.d/pure-ftpd restart.

Now you are able to create the symbolic link into the user's directory.

How to upload files to remote server using ftp command from Windows Command Prompt

In this article, I will show you how to transfer files to a remote server, using the ftp command - line - directly from the Windows Command Prompt.

Prerequisites are: remote server must have FTP Server up and running and accept FTP connection.

Let's create the file scripts.txt, fill it with the necessary instructions to login, transfer mode, destination, files list, end connection.

file: script.txt

ftp_username
ftp_password
bin
cd public_html
put file_1.ext
put file_2.ext
put file_n.ext
bye

Now to start the transfer by command prompt: type the ftp command as follow.

You can reach the server with an IP address

ftp -s:script.txt xxx.xxx.xxx.xxx

Or domain name

ftp -s:script.txt example.com

If you want to automate this procedure, using a batch file, create a file upload.bat and fill it with the preferred command line.

How to enable email field and homepage field in Drupal 7 comment form

By default Drupal 7 does not enable the email field and homepage field in comment form for anonymous posts: so, enable them is very simple.

In your admin area, go to:

Structure -> Content types -> Article ( choose the content type you want, in my case Article and click on edit ) -> Comment settings -> Anonymous commenting (choose one of: Anonymous posters may/must leave their contact information) -> Save content type

Tags:

How to solve the JVM creation failed error when starting Netbeans

For those working with NetBeans on a Windows ( for sure XP and Vista ) machine this error is well known.

Do not worry, fix is very simple, just add an extra option in the configuration file.

You can find netbeans.conf under

C:\Program Files\NetBeans\etc

This is the original conf row

netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true"

Simply add this extra parameter to the above row

-J-XX:MaxPermSize=128m 

Finally the row looks like

netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=128m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true"

Restart NetBeans and enjoy coding.

Tags:

How to create a dinamic array of months: first element is the current month, the other elements are the following months

In this article I will show you how to create an array of months, where the first element is the current month, and the other elements are the following months.

This code is very useful when you need to handle events that have an expiration date.

<?php

	$months = array();
	$currentMonth = intval(date('m')); // get the current month number

	for($x = $currentMonth; $x < $currentMonth + 12; $x++) {
		$key = date('n', mktime(0, 0, 0, $x, 1));
		$value = date('F', mktime(0, 0, 0, $x, 1));

		$months[$key] = $value; // populate the associative array: $months( 6 => June, ... ) and so on
	}

	echo var_dump($months);  // print the array content
        
	/*
	array(12) { 
		[6]=> string(4) "June" 
		[7]=> string(4) "July" 
		[8]=> string(6) "August" 
		[9]=> string(9) "September" 
		[10]=> string(7) "October" 
		[11]=> string(8) "November" 
		[12]=> string(8) "December" 
		[1]=> string(7) "January" 
		[2]=> string(8) "February" 
		[3]=> string(5) "March" 
		[4]=> string(5) "April" 
		[5]=> string(3) "May" 
	}
	*/

?>

The mktime function, returns the unix timestamp corresponding to the arguments given: in our case hour, minute, second, month, day.
Take a look also to the date function, that return a string formatted using the given integer timestamp.

Tags:

How to improve Apache 2.x web server security: disabling headers

To increase the security of your Apache web server you should disable the Apache headers, as they contain a lot of sensitive information about the OS, the version of Apache, modules and other installed software.

This informations are exposing the system to potential security holes, because knowing the version of software is also possible to know which bugs are affected.

To disable the headers from Apache 2.x, we must enable and set the two directives:

  • ServerTokens
  • ServerSignature

On Apache 2.x built from sources with ./configure --prefix=/usr/local/apache2:

Edit the file /usr/local/apache2/conf/extra/http-default.conf and set:

ServerTokens Prod

and then

ServerSignature Off

Edit the file /usr/local/apache2/conf/httpd.conf and uncomment the directive:

# Various default settings
Include conf/extra/httpd-default.conf

Restart Apache

/usr/local/apache2/bin/apachectl restart

On a Debian 6 squeeze, with Apache 2.x installed from packages:

Edit the file /etc/apache2/conf.d/security and edit existing directives like the following:

ServerTokens Prod
ServerSignature Off

Restart Apache

/etc/init.d/apache2 restart

Header are now disabled and security is improved, if you want to check actual headers you can install a Google Chrome plugin or a Firefox add-ons.

CodeIgniter 2.x and Infomaniak: error when sending email

Working on a web application hosted on a server Infomaniak, I could not send emails.

The reason is because Infomaniak, in php.ini, has set safe_mode = off.

Searching on Google, I found the solution in the Expression Engine forum.

For CodeIgniter 2.x: edit /system/libraries/Email.php

Line 54: set $_safe_mode to true.

var $_safe_mode = TRUE;

Line 94: comment line.

//$this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE;

Line 130: comment line.

//$this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE;

Now it is possible to send email as well.

How to setup Static IP Address on Debian 6 squeeze

Set static IP on Debian is very simple: just edit the file /etc/network/interfaces.

During installation, if the network settings were not changed, the interfaces file is configured in DHCP mode, and looks like this:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp

To set the static IP address, you need to edit # The primary network interface like this:

# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.100
gateway 192.168.0.1
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255

IMPORTANT: The above/below values, as the interface eth0, ​​are just for example, replace them with those of your network configuration.

From shell, as root ( if you are normal user, put sudo before each command ), restart the network service with this command line:

~# /etc/init.d/networking restart

Yes, as the warning say, restart is deprecated: don't worry, the service will restart correctly.

or better:

~# ifdown eth0 && ifup eth0

We're done.

First Post

I'm a web developer and this blog will be a convenient place to share my thoughts about web developing and keep track of all my tips, tutorials, code snippets and web projects.

First post, first step! Let's move on.

Welcome, and thanks for reading.

Tags:

Subscribe to Massimiliano Marini RSS