Tag Archives: apache

Default Virtual Host in Apache

If you have multiple domains installed in a virtual host configuration with one IP address in Apache, the IP address may not resolve to the domain you prefer. Let me explain.

For example, you have the following domains running on an Ubuntu Server with one IP address.

abc.com
cde.com
klm.com
xyz.com

All the domains are resolving as expected on the browser.

However, if you type the IP address on the browser, it only defaults to the first domain found in the /etc/apache2/sites-available directory, which is most likely abc.com.

If you want the IP address to default to another domain, such as klm.com for example, you will need to edit the /etc/apache2/httpd.conf file and add the following entries.

<VirtualHost *:80>
ServerName www.klm.com
ServerAlias klm.com
DocumentRoot /var/www/klm.com/www
</VirtualHost>

Those are the only entries you’ll need. Typing the IP address on the browser will now default to the contents of klm.com. All the other domains are still accessible via domain names on the browser.

Simple Invoices 500 Internal Server Error

Simple Invoices is a free, open source, web based invoicing system that you can install on your server, desktop, or at a service provider. I installed Simple Invoices on a webhost company I rather not mention. The application was working fine, until they tweak their PHP settings several months back. As a result, the PDF export in Simple Invoices no longer worked. I was bummed. So, I was forced to run Simple Invoices from my home server, which was fun, but the issue was, I can’t access it outside of the house.

So, I decided to install Simple Invoices on my new account at Linode. Now, the funny thing was, the application won’t even come up. Not even a login page. So, I searched online for a possible solution to my dilemma. Some suggested to increase the php memory settings to 128M, but that didn’t work out for me. At one time, I thought I had a missing pdo_mysql module, but that wasn’t the case. Then, I stumbled into something that led me to the ultimate discovery.

Simple Invoices has this configuration file called config.ini located inside the config folder. One thing this application doesn’t like are extra characters inside the config file. I happen to like funky passwords with interesting characters like +-)!@#. My MySQL password happens to have a close parenthesis in it. Essentially, this extra character caused the entire application to not start. So, I change my password, and sure enough, the application worked.

So, if you ever get a 500 internal server error with the Simple Invoices application, make sure you don’t have any of those extra characters inside your config.ini file. I wasted two hours trying to fix this issue, only to be surprised by such an idiotic requirement. That means I can’t use difficult passwords for this application. I think this is either a design issue or a funny requirement of the Zend Framework, which by the way, Simple Invoices is written on. It was somewhat funny, but I wasn’t amused.

Permissions To Webroot

I was wondering about the best way to implement and give permissions to webroot, also known as the root directory of your web server. I’m familiar with Ubuntu’s structure, so I’ll use Ubuntu’s default webroot directory, which is /var/www.

Based on numerous documents and discussions I’ve read online, the proper way to give permissions to webroot is to (1 ) add a user to the www-data group, (2) change webroot’s ownership to www-data, (3) give all members of www-data group read and right access.

ulysses = user
webroot = /var/www
www-data = user and group for Apache

Here are the commands to run from the Terminal.

Step 1

Add new user to the www-data group.

$ sudo adduser ulysses www-data

Or

Add existing user to the www-data group.

$ sudo usermod -a -G www-data ulysses

Step 2

Make www-data the group owner of /www/data

$ sudo chown -R ulysses:www-data /var/www

Step 3

Give members of www-data permissions.

$ sudo chmod -R g+rw /var/www

That’s it. Pretty straightforward.

Apache mod_spdy

Are you looking for ways to increase the speed of your website? Apache has a new module called mod_spdy which is a new networking protocol spawned by Google. Howtoforge has the install tutorial. It requires that you have access to your own web server, like a VPS or a home server.

SPDY (pronounced “SPeeDY”) is a new networking protocol whose goal is to speed up the web. It is Google’s alternative to the HTTP protocol and a candidate for HTTP/2.0. SPDY augments HTTP with several speed-related features such as stream multiplexing and header compression.

To use SPDY, you need a web server and a browser (like Google Chrome and upcoming versions of Firefox) that both support SPDY. mod_spdy is an open-source Apache module that adds support for the SPDY protocol to the Apache HTTPD server. This tutorial explains how to use mod_spdy with Apache2 on Ubuntu 12.04.

The instructions looks fairly easy.

More proof? Here’s a video showcasing mod_spdy.

YouTube Preview Image

Mount Bind

The mount command in Linux is used to attach a file system to a certain device. One of the least used features within mount is called bind. With bind, you can mount a certain directory to another directory within the file system. The result is, the files are accessible from both directories. This feature is particularly helpful when sharing files. I use it to map the home directory of a FTP user to the home directory of the web server. In this particular example, I’m using a FTP user called ‘ftpuser’ and mapping the drive to ‘/var/www,’ which is Apache’s home directory.

Mount Bind Command

mount --bind /var/www /home/ftpuser

Make It Permanent

To make this mount permanent, you need to add it to /etc/fstab.

/var/www /home/ftpuser bind defaults,bind 0 0

Apache Error: Fully Qualified Domain Name

I recently installed Ubuntu and the Apache web server on another desktop computer. If you like to know how to install Apache, please read my previous post about installing LAMP. In this instance, installing Ubuntu and Apache was a success. There is one minor issue however. Every time I restart the Apache web server, I would get this annoying message: “Could not reliably determine the server’s fully qualified domain name.” The error is more of a warning. It does not really affect the way Apache display web pages. It’s more of annoyance more than anything.

So, how do you get rid of this minor Apache error?

First things first, one of the things I would like to do when I install a new instance of Ubuntu is to assign the desktop’s hostname to “localhost.” In this case, I don’t have to worry about the hostname resolving to itself, since localhost is already bound to 127.0.0.1. You can change your hostname to localhost by typing this command on the Terminal:

~$ sudo hostname localhost

You don’t have to do this if you prefer another hostname.

Now, to fixing the minor nuisance.

Edit the Apache config: /etc/apache2/apache2.conf.

You will need to edit the Apache configuration and add your hostname as ServerName. You can edit the file via the Terminal and using either vi or Gedit. I prefer to work vi for minor changes. Gedit is probably easier for most.

~$ sudo vi /etc/apache2/apache2.conf

or

~$ sudo gedit /etc/apache2/apache2.conf

If you haven’t done anything previously to the Apache configuration, it will probably be an empty file. In my case, it was. Just add the following:

ServerName localhost

If you are going to use a different hostname, you will need to add the fully qualified domain name or FQDN in this format.

ServerName hostname.domain.com

After saving your changes, you will need to restart Apache to see if that minor annoyance is gone.

To restart Apache, type:

~$ sudo /etc/init.d/apache2 restart

The Perfect Server Based On Ubuntu 10.04

There is no such thing as a perfect server, but this particular one is as close as you can get to being perfect. This tutorial will walk you through how to install the Ubuntu 10.04 LTS Server with all the services available typically that you get from ISPs and hosters.

It contains the installation of Apache web server (SSL-capable), Postfix mail server with SMTP-AUTH and TLS, BIND DNS server, Proftpd FTP server, MySQL server, Courier POP3/IMAP, Quota, Firewall, etc. It also installs the free web hosting control panel called ISPConfig2. Here’s the link to the tutorial.

Run Multiple Applications in CodeIgniter

You’ve installed CodeIgniter and you’ve written a couple of applications. Now, you want to run two of your applications under one install of CodeIgniter. The following article discusses how to run several applications within a single install of CodeIgniter. The approach is accomplished using Apache’s Virtual Host.

Install Apache Virtual Host

1. To add a virtual host, edit /etc/apache2/sites-available/default. We will use “vhostname” as the virtual hostname in this example. Edit the default file and add the following:

<Virtualhost *:80>
ServerName vhostname
DocumentRoot /var/www2
</VirtualHost>

2. Run the a2ensite script which enables your virtualhost within the apache2 configuration. It creates symlinks within /etc/apache2/sites-enabled.

# sudo a2ensite vhostname

3. Restart Apache

# sudo /etc/init.d/apache2 restart

4. Check your virtualhost if it’s working by pointing your browser to http://vhostname.

CodeIgniter Setup

One way of setting up CodeIgniter to support multiple applications, is to have separate folders for each application. You can set up your CodeIgniter directories like the following:

system/
   application/
       app1/
          config/
       app2/
          config/

1. Under the “app1/config” directory, edit the config.php file. Point your application to be hosted at vhostname by changing the following line:

$config['base_url'] = “http://vhostname/”;

2. Copy the “index.php” file under the main CodeIgniter directory to the http://vhostname web root directory.

3. The “.htaccess” file recommended by CodeIgniter also needs to placed to the web root of http://vhostname.

4. Open your browser and check if your application is working by placing http://vhostname in the address bar of the browser.

5. Repeat steps 1-4 to add additional virtual hosts.That’s it.

If you have questions or suggestions, please leave a comment.

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 127.0.1.1 for ServerName … waiting apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 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.
Continue reading