Web Development Tutorials for September 2011

PHP set timezone

PHP comes with a dedicated configuration setting for the timezone that it is supposed to use. On both Windows and Linux this setting usually comes blank and PHP defaults to using the system timezone when doing calculations using the date function for example.

On both Windows and Linux systems, the configuration to set the timezone is in the main php.ini file.

Get or set current system time on Ubuntu Linux using the terminal

Managing the date and time on a Linux system is fairly simple using the command line. Once you are familiar with the relevant command and its syntax, it is very easy to get and set the system date/time properly.

The commands shown below are tested on Ubuntu Linux but should work well on most if not all other popular variants of Linux.

To get the current Ubuntu system date/time, execute the following command in a terminal:


Change timezone on MySQL Server on Ubuntu

There are various ways of setting the timezone that the MySQL server uses. To explicitly set the timezone that MySQL uses on Ubuntu, all we have to do is add a line to the MySQL configuration file.

Note that it is usually not necessary to explicitly set the timezone for the MySQL server as MySQL is pretty good at getting the correct timezone from the system. Use the method outlined below only if you have special requirements.

Open a terminal, and run the following command as root:

nano /etc/mysql/my.ini

PHP Array Size

PHP array size is important when we will be manipulating the contents of our array. By virtue of us using an array to store our variables in the first place, it usually means that we plan to operate on them as a unit. Since we usually use for loops to process arrays, we need to know the array size so that we can know when to end the loop.

There are two functions which can be used to get the size of an array. There is the count function and another function which is the alias of the aforementioned function called sizeof.

List all virtual hosts served by Apache2 on Ubuntu

By using virtual host configurations, it is possible for more than one website to be served by the same Apache web server on the same machine. Virtual hosting makes it easy to run multiple websites from the same server. You simply make a new virtual host configuration for each new website that you want to set up and then reload the Apache configuration.

Change timezone on Ubuntu using the Command Line

It is very easy to change the timezone on your Ubuntu desktop or server system when using the command line. Debian-based versions of Linux, like Ubuntu, make this task as easy as reconfiguring a package via the package management system. To change the timezone on your Ubuntu system, execute the following in a terminal as root:

dpkg-reconfigure tzdata

The package tzdata should already be installed but in case it isn't just install it by running the following command as root:

apt-get install tzdata

Image to Base64 Conversion Tool

Did you know that images can be embedded right into the HTML code of a page and not require an external resource to work? It is true. Using the Data URI scheme, the binary data from images can be encoded using base64 encoding and embedded right into an HTML page.