Extract the TLD from a domain name

There is no standard PHP function to extract the TLD from a domain name, parsing an URL with parse_url() will return the host name and other URL information. If you need only the TLD, for example to query the WHOIS data of a given domain name, the following script should be useful. To run this script you need a database with all TLD’s. The snippet is using a database table which is required for the scripts functionality, download the MySQL table dump here. Continue reading Extract the TLD from a domain name

How-to create a virtual host in Apache (Ubuntu)

You will find on most Linux based web hosts a directory which is called “sites-available” (inside /etc/httpd/ or /etc/apache2/). Create a configuration file with the name “domain.com” for your host and add this code:

ServerName domain.com
ServerAlias www.domain.com
ServerAdmin webmaster@localhost
DocumentRoot /home/user/domain.com/public_html/
ErrorLog /var/log/apache2/domain.com-error.log
# Possible values include: debug, info, notice, warn, error, crit, alert, emerg
LogLevel warn
CustomLog /var/log/apache2/domain.com-access.log combined

Create the directory for your web host and activate the host with a2ensite domain.com and reload your apache engine.