Fully Qualified Server Name

If you are trying to restart an Apache server running on Ubuntu, Linux Mint or any other Ubuntu derived distro, you will get an warning message that your Apache server does not contain a fully qualified domain name.

Restarting Apache

sudo /etc/init.d/apache2 restart

Warning Message

* Restarting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using for ServerName ... waiting apache2: 
Could not reliably determine the server's fully qualified domain name, using for ServerName [ OK ]

To fix this annoying message, you need to set the hostname:

Set Hostname

sudo hostname computername.domain.com

So, the next time you restart the Apache server:

Restart Apache

sudo /etc/init.d/apache2 restart

There are no more warning messages.

No More Messages

* Restarting web server apache2
... waiting                                                              [ OK ]

Install Subversion Repository on Ubuntu Desktop

This is a tutorial how to install a Subversion on your desktop. Subversion is an open-source revision control system. A repository is usually installed on servers so developers and programmers can have easy access to code. Subversion uses a check-in an check-out process for submitting changes to the repository. The repository can also be installed on desktop systems. Access is gained through many means by way of direct file access, ftp, http, svn and svn+ssh. See chart below.

Installing Subversion will install both Subversion administration tools and the client. In Ubuntu or Debian-based systems, you can install Subversion by performing the following commands. By the way, I added an Apache and Subversion WebDav module so both can be installed with just a single command.

Install Subversion

sudo apt-get install subversion libapache2-svn

Reboot the Apache Web Server

sudo /etc/init.d/apache2 restart

Create a Subversion Repository

svnadmin create /home/yourname/repository/

I’m placing the repository in my home directory. You can place it anywhere in your system. You may need to use sudo if you install it outside of your home directory. Remember the repository location, we will use it a few times below to configure the Apache Subversion WebDav module, etc.

Import your Repository

svn import /path/to/import/directory file:///home/yourname/repository

If you have a repository ready, now is a good time to import it. If you are just starting out, you can initialize the Repository here.

Access to Subversion

file:// Direct access on local disk
http:// Browser using http WebDav protocol
https:// Browser using https secure and WebDav
svn:// Subversion protocol
svn+ssh:// Subversion protocol and SSH tunnel

Configure WebDav protocol

sudo vi /etc/apache2/apache2.conf


<Location /svn>
DAV svn
SVNPath /home/yourname/repository
AuthType Basic
AuthName "Repository"
AuthUserFile /etc/subversion/passwd
Require valid-user

Change Ownership to HTTP-User

sudo chown -R www-data:www-data /home/yourname/repository

Password Protect the Repository

sudo htpasswd -c /etc/subversion/passwd username

You will be asked to provide a password. Enter the password twice.

Reboot Apache Server

sudo /etc/init.d/apache2 restart

It’s probably a good idea to restart the Apache server one more time.

Browser Access
Next, open up your browser and access http://localhost/svn from the address bar. You will be asked for the username and password. You should see the repository and any content or directory underneath it. That’s it. Happy coding.

WordPress and Password Protected Directories

I think I just solved an issue with WordPress Permalinks and password protected directories that use Apache’s .htaccess. Here’s the problem in detail. I have WordPress installed on the root of my domain. Under that domain, I have a directory that I want password protected using .htaccess. It’s just a directory containing a few PHP scripts. Every time I try to access the password protected directory, I get a 404 page missing error. WordPress is confused thinking the directory is a post or a page. Since it’s not, it generates a 404 error instead.

The workaround for this is to place a couple of error codes at the top of the .htaccess to pre-empt the WordPress .htaccess rules. There are a couple of scenarios. If there is 401 situation, an authentication in this case, it will send the user to the error document which is just a blank html file. The WordPress permalinks rule never gets processed or is ignored. If there is a 403 error code, a forbidden situation in this case, it will send the user to that error document as well.

Here is the working .htaccess file. You will see the two error code rules at the top of the file. Underneath, you will see the standard WordPress permalinks rules.

ErrorDocument 401 ./blank.html
ErrorDocument 403 ./blank.html
# BEGIN WordPress
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

Simple fix. Thanks to aiso.net.

Prevent Others From Hotlinking

You can stop others from hotlinking on your site with the use of the .htaccess file in Apache. Hotlinking is when others are directly linking to an image or a file on your server. It’s bad because, they are using your server’s resources and bandwidth for free. You can edit your .htaccess file usually located in your root directory. If you don’t have one, just create one. It must start with a period, .htaccess. Enter this code:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpe [L]

Read more.

Maintenance Page Using .htaccess

If you own a website, there are times you need to bring your site down for maintenance or repair. Instead of the ugly 404 page not found, a nicely crafted maintenance page is ideal for your users to see. Enter .htaccess, a powerful Apache configuration file capable of many powerful functions. It can perform authorization or authentication, redirects, custom error messages, and cache control. This article explains how to create a custom error message. The  .htaccess file contains code to redirect your users to your maintenance page. In short, it uses .htaccess rewrite rule and even restricts viewing to a certain IP addresses. In this case it allows the admin to see the website as he would normally, while the rest will get a visually appealing maintenance page.

Remove Apache, Install Lighttpd

I was asked in my previous post as to why I installed the popular Apache web server instead of lighttpd, a fast and highly optimized web server with a small footprint. If you need enough convincing, Youtube, Wikipedia and Meebo all use the lighttpd web server. Well, if you asked for it, you’ll going to get it. This article is a how-to in removing Apache and replacing it with the lighttpd web server.

Remove Apache

sudo apt-get remove apache2

Remove Apache from startup

sudo update-rc.d -f apache2 remove

Install lighttpd

sudo apt-get install lighttpd

Install PHP-5 and modules

sudo apt-get install php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

Edit php.ini and set cgi.fix_pathinfo to 1

sudo vi /etc/php5/cgi/php.ini

Set cgi.fix_pathinfo = 1

Add lighttpd user

sudo useradd -d /home/lighttpd -m -s /bin/bash lighttpd

Add lighttpd group

sudo groupadd lighttpd

Set mod_fastcgi and mod_rewrite

sudo vi /etc/lighttpd/lighttpd.conf

Uncomment the following lines:

Add FastCGI</strong>
fastcgi.server = ( ".php" => ((
"bin-path" => "/usr/bin/php5-cgi",
"socket" => "/tmp/php.socket",
"max-procs" => 1,
"bin-environment" => (

Set file permissions to log files

sudo chown -R lighttpd:lighttpd /var/log/lighttpd/error.log
sudo chown -R lighttpd:lighttpd /var/log/lighttpd/access.log

Set WordPress Permalinks

sudo vi /etc/lighttpd/lighttpd.conf 
server.error-handler-404 = "/index.php"

Restart lighttpd web server

sudo /etc/init.d/lighttpd force-reload
sudo /etc/init.d/lightttpd restart

Install LAMP on Ubuntu Desktop

My development server is old. You’ll get a chuckle when you see the specs. It runs on a 400Mhz Pentium II CPU with a 128MB RAM and a 40GB drive. This old relic still manages to run Apache, MySQL, PHP and a local DNS. The server has also gone through 4 Ubuntu upgrades from version 7.04 to 9.04. After each upgrade, pages that require MySQL and PHP have slowed down considerably.

You guessed it. It’s about time to move to another machine. So, I’ve decided to install AMP minus the L (Linux) since we are already installing it on the Ubuntu Desktop. The following tutorial will show you how to install Apache, MySQL, PHP as well as the MySQL admin tool called PhpMyAdmin. Let’s get started:

Install Apache

sudo apt-get install apache2

Install PHP. Restart Apache

sudo apt-get install php5
sudo /etc/init.d/apache2 restart

Install MySQL

sudo apt-get install mysql-server
sudo apt-get install libapache2-mod-auth-mysql
sudo apt-get install php5-mysql

Finally PhpMyAdmin
sudo apt-get install phpmyadmin

You’ll be asked to provide passwords on the MySQL and PhpMyAdmin installations. There are a couple of minor tweaks you have to do to make sure the applications are working properly. First, make sure the MySQL extension is set in PHP. Restart Apache again after you make your changes.

MySQL Extension. Restart Apache

sudo vi /etc/php5/apache2/php.ini
sudo /etc/init.d/apache2 restart

Now, open your Firefox browser, and type `localhost` in the address bar. If you see “It Works!,” that means the installation was successful. One final thing before you go, I installed WordPress and the installation was a success, except for the mod_rewrite which wasn’t working if you try to use the permalinks feature. To make the permalinks feature work, first you’ll need to create a .htaccess file and make it writable. Next, turn on mod_rewrite module.

Mod Rewrite

cd /var/www/
touch .htaccess
chmod 777 .htaccess
sudo a2enmod rewrite

Lastly, make sure AllowOverride is set to All. Edit the file:

sudo vi /etc/apache2/sites-available/default

Allow Override

<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all

Restart Apache

sudo /etc/init.d/apache2 restart

Password Protect Using Htaccess

The easiest way to protect a web directory is to use a .htaccess file. A .htaccess file is a directory level configuration file used by several web servers including the highly popular Apache. The .htaccess file is placed in a web directory and the commands in the file controls the behavior of that directory.

A .htaccess file is used mainly for 3 purposes: authentication, the re-writing of URLs and cache control. Today, I’ll show you how to password protect a web directory using the .htaccess file.

Step 1
First, create a .htpasswd file. For security purposes, place the .htpasswd file outside of your web directory. You can place it anywhere in your file system, but your home directory is probably the best place for it. To create a .htaccess file, issue this command in your Terminal:

# sudo htpasswd -bc /home/ulysses/.htpasswd username password

The htpasswd command will create a file called .htpasswd in your home directory. The period at the beginning of the file denotes that it is a hidden file. You can view it by issuing a “ls -a” command from your Terminal. Don’t forget to supply your own username and password.

Step 2
Next, make a .htaccess file in the web directory that you want protected. In this example, we will password protect a web directory located in /var/www/widget.

# cd /var/www/widget
# vi .htaccess

Type in the following code in the .htaccess file.

AuthUserFile /home/ulysses/.htpasswd
AuthName EnterPassword
AuthType Basic
<Limit GET POST>
require valid-user

Save the file and open your browser and check if the web directory is password protected. You should see something similar to this from your browser.