Apache VirtualHost on Ubuntu

Here’s a quickie tutorial on how to add Virtual Hosts to Apache on Ubuntu. This tutorial assumes that you have a basic understanding of Apache configuration and that your Apache is installed and able to serve websites.

  1. cd /etc/apache2/sites-available
  2. sudo vim yourdomain.com.conf and enter your VirtualHost directive. Below I’ve put the most basic example, see Apache docs for details and additional features:
    <VirtualHost *>
      ServerName yourdomain.com
      DocumentRoot /home/youruser/public_html
    </VirtualHost>

    Save & exit.
  3. sudo vim /etc/hosts and add your new domain to the 127.0.0.1 localhost line so it looks like this:
    127.0.0.1 localhost yourdomain.com
    Save & exit.
  4. Enable your new virtualhost:
    sudo a2ensite yourdomain.com.conf
  5. Reload the Apache configuration:
    sudo /etc/init.d/apache2 reload

That’s it! Repeat for each of your VirtualHosts.

—————-
Now playing: Al̬may̬hu Esh̬t̩ РTchero Adari N̬gn
via FoxyTunes

Installing Ubuntu Server on a Dell Inspiron 530

I recently purchased a cheapie Dell Inspiron 530 to use as a new local devbox with the intent of installing Fedora 7 on it (the machine came with Ubuntu Desktop pre-installed). Foolish me, I just assumed that if Ubuntu was compatible with the hardware, then Fedora surely would be as well. WRONG. Fedora was unable to detect/install both the SATA controller and the integrated ethernet port. After a few hours trying to get Fedora to install, I decided to give up and give Ubuntu Server a try. Of course it wasn’t easy, so here are some of my notes in getting Ubuntu Server installed onto the Dell Inspiron 530.

I wanted to keep it simple so I just installed all of the defaults presented by the installer, including the LAMP package. Everything installed fine, however, the Integrated Network card was not detected/installed, so here’s how to get it up and running by compiling and installing the driver.

  1. First we need to install some prerequisites that are required in order to compile the driver. Make sure your Ubuntu Server CD is in the CD drive and run the following:
    sudo apt-get install linux-headers-2.6.20-15-server
    sudo apt-get install gcc
  2. Download the ethernet driver from Intel. The one I used is e1000-7.6.5.tar.gz. If you can’t find it at Intel, just Google the filename and I’m sure you’ll be able to find it somewhere.
  3. Burn the driver to a CD, mount it on your Ubuntu machine, and copy it to a local dir:
    sudo mkdir /mnt/cdrom
    sudo mount /dev/cdrom /mnt/cdrom
    sudo cp /mnt/cdrom/e1000-7.6.5.tar.gz /usr/src
  4. Compile and install the driver:
    cd /usr/src
    tar xfvz e1000-7.6.5.tar.gz
    cd e1000-7.6.5/src
    sudo make install
    sudo modprobe e1000
  5. Now configure your network card:
    sudo vim /etc/network/interfaces and your file should look like this (substitute your IP of choice):
    # 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
     
    # This is a list of hotpluggable network interfaces.
    # They will be activated automatically by the hotplug subsystem.
    mapping hotplug
    script grep
    map eth0
     
    # The primary network interface
    auto eth0
    iface eth0 inet static
    address 192.168.1.66
    netmask 255.255.255.0
    network 192.168.1.0
    broadcast 192.168.1.255
    gateway 192.168.1.1
  6. Setup your DNS servers:
    sudo vim /etc/resolv.conf and it should look like this (I am using OpenDNS here but you can substitute your own):
    nameserver 208.67.222.222
    nameserver 208.67.220.220
  7. Restart the network:
    sudo /etc/init.d/networking restart
  8. Upgrade your system for good measure:
    sudo apt-get upgrade

That should be enough to get your Ubuntu Server up and running on the Dell Inspiron 530 with full network connectivity. Once you’re up and running, here are some other tweaks I did, although some of these may be personal preference.

  1. I don’t like Ubuntu’s sudo setup (I prefer log in in as root when needed). Out of the box the root account is disabled and your default account is given admin rights to run commands via sudo. To get around this, simply reset root’s password:
    sudo passwd root
    Now you will be able to su - and log in as root directly.
  2. Install SSH
    sudo apt-get install ssh
  3. Disable root login to SSH:
    sudo vim /etc/ssh/sshd_config and set the following:
    PermitRootLogin no
  4. Change the MySQL root password:
    mysqladmin -u root password "newpassword"
  5. Enable Apache’s mod_rewrite:
    sudo a2enmod rewrite
    sudo /etc/init.d/apache2 force-reload
  6. Install some other useful goodies:
    sudo apt-get install vim
    sudo apt-get install php5-mcrypt
    sudo apt-get install php5-curl
    sudo apt-get install php5-gd
    sudo apt-get install php-pear
    sudo pear upgrade-all
    sudo pear install mdb2
    sudo pear install pear/MDB2#mysqli

—————-
Now playing: Apparat – Steinholz (Monolake Remix)
via FoxyTunes

PHP & imagettftext with Webcore TrueType fonts.

If you’re trying to write some text using PHP/GD & the imagettftext() function, you will of course need some TrueType fonts to work with. I’ve found a great set of fonts available for free: Webcore. Webcore contains all the fonts web designers constantly use, things like Arial, Tahoma, Verdana, Georgia, etc..

To install, simply download to your server and install the RPM (Fedora):
shell> wget http://avi.alkalay.net/software/webcore-fonts/webcore-fonts-3.0-1.noarch.rpm
shell> rpm -i webcore-fonts-3.0-1.noarch.rpm

These fonts will now be available to you in /usr/share/fonts/webcore/.

Make sure you specify the full path when calling imagettftext(), eg:
<?php
 
// Set the content-type
header("Content-type: image/png");
 
// Replace path by your own font path
$font = '/usr/share/fonts/webcore/arial.ttf';
 
// Create the image
$im = imagecreatetruecolor(400, 30);
 
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
 
// The text to draw
$text = 'Hello world!';
 
// Add some text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
 
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

Your mileage may vary if you are using a different distribution, but the docs state that this RPM should work on other distros.

Yum: Cannot find a valid baseurl for repo: core

I went to update my Fedora Core 5 machine today, and received the following error:
[root ~] yum check-update
Loading "installonlyn" plugin
Setting up repositories
core [1/3]
Cannot find a valid baseurl for repo: core
Error: Cannot find a valid baseurl for repo: core

I tried running yum clean all but it didn’t help. After looking around I found that all of my repo files in /etc/yum.repos.d/ had their baseurl values commented out. Don’t ask me how that happened, I have no idea. Simply un-commenting all the baseurl values in all my repo files fixed the problem, and yum is once again running as expected. So if you run into this problem, make sure everything is set up right in /etc/yum.repos.d/*.repo

Installing PDFlib Lite as a PHP module on Fedora Core 4

The instructions for doing so (here) seemed straightforward enough, but I ran into a few problems. So here’s how I got PDFLib working with my PHP install on Fedora Core 4.

First we need to build PDFlib Lite from Source. Download it from here. Unpack it, then:
./configure
make
make install

Easy enough. Now:
yum install automake
yum install php-devel
pecl install pdflib

(Note: php-devel is required because we need phpize which is used by the pecl command.)

The PECL install will ask you a question: “Path to PDFlib installation?” This is where I ran into problems. You must put /usr/local/ and NOT /usr/local/include because the script is hardcoded to look inside the include directory automatically. Once PECL finds pdflib.h it will continue and finish compiling our shared object, pdf.so. The script will install it for us in /usr/lib/php/modules/
Now we just have to tell PHP to load the SO. Open up php.ini and add the following line:
extension=pdf.so
Save & exit, and restart your Apache with apachectl graceful. Now browse to a file containing the phpinfo() function and check to see if PDFlib is now active. If you see it, you’re good to go!

NOTE: I ran into a problem with RPM GPG Keys at the automake install step. I was getting the following error:
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID db42a60e
public key not available for autoconf-2.59-5.noarch.rpm
Retrieving GPG key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora
The GPG key at file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora (0x4F2A6FD2)
is already installed but is not the correct key for this package.
Check that this is the correct key for the "Fedora Core 4 - i386 - Base" repository.

To get around this we need to import all the keys by run the following command:
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
I found this solution in this thread.

Red Hat Fedora Linux: Add an additional IP to your network card.

Adding an additional IP or IPs to your network card in Linux is easy. Here’s how I did it in my Fedora Core 4 installation:
cd /etc/sysconfig/network-scripts/
cp ifcfg-eth0 ifcfg-eth0:0

Now you will need to open your newly created ifcfg-eth0:0 file in your favorite editor and modify it to fit your needs. The two lines you MUST change are the following, the rest are optional:
DEVICE=eth0:0
IPADDR=192.x.x.x

Of course you will want to fill in the IPADDR value to fit your needs.

Now, to make the changes take effect, you will need to bring your new IP up by issuing the following command:
./ifup eth0:0
Or if you want you can just restart the entire network:
/etc/rc.d/init.d/network reload
There you go! Run ifconfig and you should see your new IP assigned to eth0:0. It should look something like this:
eth0:0 Link encap:Ethernet HWaddr 00:D0:B7:B7:XX:XX
inet addr:192.168.1.XX Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

You can add even more IPs by repeating this process and incrementing the value of eth0:0, for example you can add eth0:1, eth0:2, etc.