GD, Apache, Captcha, PHP, Error

I had to setup a captcha on someone’s website. The captcha refused to load. The easiest way to get the error (since, by default, PHP will not list out all the problems when called from another page) is to call the script directly.
Say your site is http://www.mysite.net. You’ll want to go to http://www.mysite.net/CaptchaSecurityImages.php. You can do the website math.

I had apache installed, GD installed, PHP installed.

This is the error I was receiving:
Warning: imagettfbbox() [function.imagettfbbox]: Could not find/open font in /var/www/sitehere/CaptchaSecurityImages.php on line 60

Error in imagettfbbox function, eh? That’s none too helpful. Good thing I can read: Could not find/open font. That’s all I need to know.

If you were to open up CaptchaSecurityImages.php and change the location of monofont.ttf to a debian/ubuntu file location, everything would probably end up working correctly.

SSH to your machine
nano CaptchaSecurityImages.php
Search for:
var $font = 'monofont.ttf'
and replace with:
var $font = './monofont.ttf'
Reload your script on your web browser

AWStats on Apache

If you’ve ever seen an Apache log file, you’ll notice that it’s rather long to read. It’s not that the log is hard to read, it’s just full of a lot of useless information. If you view a website with a browser, the log will show that you connect and retrieve every single file (images are included). Ouch.

I installed Debian 5.0 Server on an HP DL380 G4 server. I then did all the updates etc. I’m assuming you know how to install apache and how to “su” to root.

apt-get install awstats
nano /etc/apache2/awstats.conf
This creates a new file called awstats.conf

Alias /awstatsclasses “/usr/share/awstats/lib/”
Alias /awstats-icon/ “/usr/share/awstats/icon/”
Alias /awstatscss “/usr/share/doc/awstats/examples/css”
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
ScriptAlias /awstats/ /usr/lib/cgi-bin/
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch

Save this file and exit back to the shell.

nano /etc/apache2/apache2.conf

Add this to the end of the conf file:

Include /etc/apache2/awstats.conf

Save and exit apache.conf.

apache2ctl restart

cd /etc/awstats
cp awstats.conf awstats.www.mysite.org.conf
nano awstats.www.mysite.org.conf

Search for and edit the following:

LogFile=”/var/log/apache2/access.log”
SiteDomain=”mysite.org”

Save the file and exit to the shell.

Now we need to run the script to parse the log files into a stats page:
perl /usr/lib/cgi-bin/awstats.pl -update -config=www.mysite.org

If it fails due to permissions:
chmod -R 777 /var/log/apache2
Then re-run the script

Now check your stats at http://www.mysite.org/awstats/awstats.pl

As long as everything went to plan, the script should also automatically install a cron job to update the stats every 10 minutes.

You can find out by typing the following:
dpkg -L awstats | grep cron
Which shows the following:

/etc/cron.d
/etc/cron.d/awstats

If you nano the awstats cron, you can edit the times and locations of the scripts.

EDIT!!!

If you’re using virtual hosts (like I am) and you want each site to have its own stats:

Edit your sites-available default:
nano /etc/apache2/sites-available/default

Add the following in your VirtualHost:

NameVirtualHost 192.168.1.4

DocumentRoot “/var/www/web123”
ServerName web123.com
ServerAlias *.web123.com
CustomLog /var/log/apache2/web123.com.log combined

Then you’ll have to create the awstats.web123.com.conf file in /etc/awstats
cp /etc/awstats/awstats.conf /etc/awstats/awstats.web123.com.conf
nano /etc/awstats/awstats.web123.com.conf

Change the following:

LogFile=”/var/log/apache2/web123.com.log”
LogFormat=1
SiteDomain=”web123.com”
HostAliases=”web123.com www.web123.com localhost 127.0.0.1″

This will allow you to use the browser to update the stats if your CRON job is set for long periods of time:

AllowToUpdateStatsFromBrowser=1

And I set this up because I have apache do a DNS lookup on its own:

DNSLookup=0

Then restart apache:
apache2ctl restart

LAMP on Debian

LAMP is Linux Apache MySQL PHP. Debian is the primary for Ubuntu.

Tried to install Ubuntu server 8.10 on an HP DL380 G4 with mixed results. Grub was failing on me. Instead of trying to fix it I just took a Debian 5 CD and wrote it over. Only problem is no LAMP – Ubuntu is much better for setting up initially, but both OSes are basically the same.

nano /etc/apt/sources.list
remove the cdrom

apt-get update
apt-get upgrade
apt-get install ssh-server

apt-get install apache2
apt-get install apache2-mpm-prefork
apt-get install php5

apt-get install mysql-server php5-mysql
apt-get install phpmyadmin
apt-get install webmin
apt-get install libapache2-mod-php5 php5-cli php5-common php5-cgi

nano /etc/apache2/apache2.conf
AddType application/x-httpd-php .php
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.shtml index.htm

I installed SSH so I could remotely do the rest of the work.

At this point, you should be able to go to http://youripaddress and see a generic “IT WORKS!” apache page.
You can also go to http://youripaddress/phpmyadmin and load up the phpmyadmin page. I suggest prohibiting this from being viewed outside your internal subnet using access rules in apache.
Then you can go to http://youripaddress:10000 and view the webmin page

Potential Problems:
Your repository list is incorrect.
nano /etc/apt/sources.list
deb ftp://ftp2.fr.debian.org/debian/ stable main contrib non-free
deb-src ftp://ftp2.fr.debian.org/debian/ stable main

You can not apt-get webmin:
wget http://voxel.dl.sourceforge.net/sourceforge/webadmin/webmin_1.460_all.deb
dpkg -i webmin-1.460_all.deb
apt-get install -f

You want ASP support on this Linux Box:
apt-get install libapache-asp-perl

You want to edit the sudoers list:
apt-get install sudo
visudo
Uncomment the following line:
%sudo ALL=NOPASSWD: ALL

Install XP From USB Key

I say USB Key, but there are a number of other buzzwords you can use: key fob, flash drive, thumb drive… the list goes on for a little while.

Things you need:
Computer that allows booting via USB/removable drives
USB Key with at least 1GB of free space – your key will be erased during the steps, so make sure nothing important resides on your device
A copy of Windows XP

After searching for a little bit on how to install XP from an external source, I found this script suite:
USB_MultiBoot_10.rar (10.9MB RAR format). Obviously you’ll need a program like WinRAR to open it.

How to run the script:

1.) Open USB_MultiBoot_10.cmd
2.) Press any key to pass the instructions
3.) Press P – this will load up the PeToUSB.exe (Preinstallation Environment To USB) that will format your USB key to allow it to be bootable. Make sure Quick Format and Enable LBA (FAT16X) are checked. Then press Start.
4.) When you close out of PeToUSB.exe, the command script will continue.
5.) Options – press the option number or letter and then hit enter:
Option 0 should already be set to USB-stick
Option 1 should be setup to point to your XP CD
The other options generally will not be needed/do not apply.
6.) When finished, press C and enter. This will add all the files needed to the USB key.
7.) When finished, try it out on your laptop/desktop
8.) My installation actually had an error – it was missing a flash file DLL, I skipped the error and everything else worked just fine.

I also recommend using nLite or another program to slipstream all necessary files on your Windows Disk BEFORE going through all these steps. But that is not a necessary step.