Install APC (alternative PHP cache) on RedHat RHEL 5

After attending php|tek 2009 I decided it was finally time for me to play with APC, and at least install it on a server to see what all of the excitement is about. After all, if it is good enough for Facebook it must be pretty beneficial, right?

According to the documentation the following command is what it takes to install:

pecl install apc

However, then I tried this I quickly received an error stating “phpize: command not found”. So after a little searching I discovered that I needed to install php-devel.i386 to enable pear to install packages. (You may also need to install autoconf, automake and libtool to do phpize. I must have already had them installed.)

sudo yum install php-devel.i386

Note: I used sudo, but you can also use su to change to the root user and then run the command as root.

Now after installing that, which also installed a couple of dependencies and updated a couple of other applications, I figured I would be all set. To the contrary I tried the install apc command again and I received one prompt asking:

Use apxs to set compile flags (if using APC with Apache)? [yes]:

I received a new error after answering “yes” :

Sorry, I was not able to successfully run APXS.  Possible reasons:
 
1.  Perl is not installed;
2.  Apache was not compiled with DSO support (--enable-module=so);
3.  'apxs' is not in your path.  Try to use --with-apxs=/path/to/apxs
The output of apxs follows
/tmp/tmpArfGXr/APC-3.0.10/configure: line 3196: apxs: command not found
configure: error: Aborting
ERROR: `/tmp/tmpArfGXr/APC-3.0.10/configure --enable-apc-mmap=yes
--with-apxs' failed

After a few minutes of searching I found a post somewhere that informed me that httpd-devel.i386 also needed to be installed.

sudo yum install httpd-devel.i386

Once the package installed, along with a few more dependencies and updates, I was then ready to try again. This time all went well, and APC was installed.

One final step was to activate it in the php.ini file. I added the following:

extension=apc.so
apc.enabled = On

Next I was ready to restart Apache and see APC in action:

sudo /etc/init.d/httpd restart

After creating a quick phpinfo() call I could now see that the APC module was indeed active. Once I copied the apc.php file that comes with the APC install files into a web accessible directory (preferably password protected) I was clearly able to see stats associated with APC.

There is much more you can do with APC settings, etc. However, that is another story for another time. Here are a couple of links to help get you started though.
C7y Tutorial
Pecl page

Categorized under: Quick Tips, linux, php, programming

Installing mhash on RHEL 4 and PHP 4.3.9

Recently I had a customer that was receiving errors from an Authorize.Net web submit form in their shopping cart. The error simply stated:

“The gateway no longer supports the requested method of integration.”

While doing some digging I found that they were using a very old web submit method that Authorize.Net no longer supported. There were two ways to fix the problem:

  1. Change to AIM method of submission, which required an SSL certificate that the client did not have.
  2. Change to SIM method of submission, which required either PHP 5.1.2 installed to use the hash_hmac function, or for PHP 4.3.9 it required that mhash be installed on the server.

Since the client did not want to spend the extra cash for the SSL certificate, and I could not install PHP 5.1.2 because I had too many other clients on the server that were not ready for the upgrade, I decided to do some searching for a way to install mhash.

It turned out that the Red Hat repositories did not carry php-mhash for RHEL 4, so this meant I needed to look in other areas. After reading many different blog and BB postings saying that it required an install, then a recompile of PHP I started to get a little worried. I did not look forward to recompiling PHP.

Finally I found some posts that brought a ray of hope. There are RPMs available to install php-mhash without the PHP recompile, but it required that libmhash be installed first. Here are the steps I followed:

  • I went to http://dag.wieers.com/packages/libmhash/ and downloaded the newest version of libmhash for my server.
  • Then I installed using the following to satisfy dependencies of mhash:
    rpm -iv libmhash-0.9.1-1.rhel3.dag.i386.rpm
  • Next I downloaded the php-mhash by using:
    wget ftp://rpmfind.net/linux/sourceforge/p/ph/phprpms/php-mhash-4.3.2-19.ent.2.i386.rpm
  • I followed that by installing it using:
    rpm -iv php-mhash-4.3.2-19.ent.2.i386.rpm

After following those steps I created a phpinfo script to see that everything went well:

<?php
phpinfo();
?>

I could now plainly see that mhash was installed perfectly, and with further tests I confirmed it was working.

Categorized under: Hardware, Quick Tips, Ubuntu, linux

Ubuntu can mount ISO files, and IMG files after converting them to ISO

Today I needed to create an OEM Microsoft Office 2007 CD and found that I could download the disks directly from the Microsoft site. However, the files that I downloaded were in IMG format. At first I was puzzled, but quickly (via Google) found out that they were essentially ISO files. However, I did not quickly find anything in Ubuntu that would burn an IMG to disk.
Diligent searching finally revealed that while there were not really ways to burn an IMG to disk, or mount an IMG file directly, there is a tool called ccd2iso that converts the IMG to ISO format.

First I had to install the ccd2iso package via Synaptic package manager, or I could have used ’sudo apt install ccd2iso’.

After installing this I could simply run the following command from terminal:

ccd2iso myfile.img myfile.iso

The same methods can be used for other image type files:
mdf2iso -> myfile.mdf
nrg2iso -> myfile.nrg

Now I have a regular iso file that can be used to serve our purposes by burning to disk or mounting:

sudo mount -o loop myfile.iso mountname
 
or
 
sudo mount -o loop -t iso9660 myfile.iso mountname

The .nrg files can also be mounted in this manner without converting to ISO by using:

sudo mount -o loop,offset=307200 myfile.nrg mountname

NOTE: if this doesn’t work and you get an error like: “Unrecognized sector mode (0) at sector 0!” it may be due to the limitations of the ccd2iso. In my case the MS Office disk had multiple sessions, and I could not convert it to ISO.

Another post I found on Ubuntuforums said to try the following:

growisofs -dvd-compat -Z /dev/dvdrw=dvd.img

Where /dev/dvdrw is your dvd/cd burner.

FOLLOWUP:
The IMG file I had from Microsoft was a multi-session disk so I was not able to use the steps above. However, when I simply changed the file extension to ‘.iso’ it worked fine. There seems to be very little difference between IMG and ISO.

Categorized under: OS, Quick Tips, Ubuntu, linux, mac, programming

Finding a text string inside a file on a Linux server

It never fails that I find myself hunting for a way to search for a particular text string in files.  Usually I know the file, but often times I also find that I am completely unsure what file contains the string.  Or while I am writting some code I need to find how many files use a certain function.

I know that using grep is the best way to search on a Linux server, so I start there.  Here is the command syntax:

grep "text string to search for" /path/to/search

Examples
To search for a string called “myFunction” in all text files located in /var/www/html/*.php use:

grep "myFunction" /var/www/html/*.php

To search recursively in all sub-directories you would alter the command by adding the -r option:

grep -r "myFunction" /var/www/html

Now you have probably noticed that grep prints out the matching lines containing your string, but you may also need the filenames of the files containing the string instead. You can use the -H option to narrow the output the filename followed by the line containing your search string, like so:

grep -H -r "myFunction" /var/www/html

This would output something like:

...
your_file.php: line containing myFunction
..

To print out just the filename you can cut command like this to clean the output further: (Note the one after the f, not an L)

grep -H -r "myFunction" /var/www/html | cut -d: -f1

The new cleaner out put would be like:

...
your_file.php
...

Backup files from Linux to a Windows server

Ok, this may be my last disaster recovery and backup blog for a long time. As you can probably tell from the title this blog entry is all about keeping backup strategies as cheap as possible.

My strategy is to backup all of my Windows and Linux servers to one central Windows server that is running a Tivoli backup agent. All of my servers are hosted elsewhere, and since it costs $99.00 per server to backup I am getting the most for my money by only backing a single server to tape/SAN. However that single server carries all of the files that need to be remotely backed up to tape/SAN.

My earlier posts show how to backup the Windows servers:
Windows backup bat script using xcopy

Also, how to backup the Windows Domain Controller:
Backup Windows Domain Controller using NTBACKUP via cmd

And I also showed how to backup a Linux server to a local file:
Linux backup using CRON to local directory

Now I will show how I moved the files backed up on the Linux servers to the Windows server prior to tape/SAN backup. I have decided to use Samba and mount a directory pointing to a shared folder on the Windows server. Lets begin:

Linux backup using CRON to local directory

As many have pointed out I am on a backup and disaster recovery kick lately. Some would say that it is about time, others are simply glad to see that data is now being backed up. I have found that it is easiest to zip up files on a local machine prior to moving them to a final destination. So lets get started:

I have multiple Linux servers with many websites on each, as well as database. So I created a script that simply tar’s the files, then gzips them with the date in the filename for archiving.

Here is the file named ‘backupall.sh’ that I save in a place reachable by the user I will use to schedule this cronjob:

#!/bin/sh
date
echo "############### Backing up files on the system... ###############"
 
backupfilename=server_file_backup_`date '+%Y-%m-%d'`
 
echo "----- First do the sql by deleting the old file and dumping the current data -----"
rm -f /tmp/backup.sql
mysqldump --user=mysqluser --password=password --all-databases --add-drop-table > /tmp/backup.sql
 
echo "----- Now tar, then zip up all files to be saved -----"
tar cvf /directory/to/store/file/${backupfilename}.tar /home/* /var/www/html/* /usr/local/svn/* /etc/php.ini /etc/httpd/conf/httpd.conf /tmp/backup.sql /var/trac/*
gzip /directory/to/store/file/${backupfilename}.tar
rm /directory/to/store/file/${backupfilename}.tar
chmod 666 /directory/to/store/file/${backupfilename}.tar.gz
 
echo "############### Completed backing up system... ###############"
date

Backup Windows Domain Controller using NTBACKUP via cmd

Backing up your servers for disaster recovery these days much include your Domain Controller if you are utilizing a Windows Active Directory to manage your users. To do this is easy using a tool that comes installed on all Windows servers called NTBACKUP. Of course you can launch the GUI by entering NTBACKUP from the run or command line. However, this does not make automated backup work very well. So here is the .bat file that I use to execute it via Windows Scheduled tasks:

@echo off
:: variables
set logfile=D:\backup_log_file.txt
 
echo %Date% # # # Backing up system state containing: local Registry, COM+ Class Registration Database, System Boot Files, Certificates(if certificate server installed), Cluster database(if installed), NTDS.DIT, and SYSVOL folder >> %logfile%
ntbackup backup systemstate /J "System State Backup Job" /F "D:\system_state_backup.bkf" >> %logfile%
 
echo %Date% Backup Completed! >> %logfile%

(NOTE: I am doing this backup via an internal network and using a user account that exists on both systems. Security may dictate that you handle this differently based on your circumstances.)

After the file is executed by Windows Scheduled Tasks you will then be left with a file that is ready to backup somewhere. I do this by making a copy to another server by using the methods covered in a previous blog post at Windows backup bat script using xcopy.

Categorized under: MSSQL, Scheduled Tasks, servers, windows

Windows backup bat script using xcopy

Recently I had the need to create a bat script that could be executed by the Windows Scheduled Tasks. The purpose was to copy files from one server to another as a cheap way to backup files created by MSSQL backing up the databases. Here is the .bat file contents (cleaned up to protect sensitive data):

@echo
:: variables
set sourcedrive=D:\
set backupdrive=\\servername\d$
set backupcmd=xcopy /s /c /d /e /h /i /r /y
 
echo # # # Moving files
%backupcmd% "%sourcedrive%\directory_to_backup" "%backupdrive%\directory_to_store_backup"
 
echo # # Moveing Complete!

(NOTE: I am doing this backup via an internal network and using a user account that exists on both systems. Security may dictate that you handle this differently based on your circumstances.)

Notice that for the backupdrive I am calling another Windows server and using the d$. This would require that the Windows Scheduled Task be executed using a user that is trusted on both machines. Also you could specify a local directory on the same server if you did not need to copy the files to another server.

Categorized under: Quick Tips, Ubuntu, applications, linux

UltraEdit on Linux and MAC…finally ! ! !

I received an email that just made my day. It was the announcement that UltraEdit will finally be available on Linux! The screenshots show it on Ubuntu, and they say there will also be a version for MAC. (Initially it will only be packaged for Ubuntu with tar balls for the others, but soon there will also be packages for Suse, and Redhat) And it is very close to release, supposedly Alpha in April 2009.

UltraEdit on Ubuntu

UltraEdit on Ubuntu

You can find out more on the Blog Post, or you can see the Formal Product Page.

Categorized under: OS, Plesk, apache, linux, servers

Redhat, Plesk, named, and chroot oh my!

Well once again I performed my updates via Redhat up2date, and once again I lost all name services on a server.  This time I thought I would post my fix, since it was the same as last time.

There was an update issued by RHN this evening which updated the bind-chroot rpm. As part of it’s post install script it will attempt to relocate any zone files that may be located outside of the chroot into a chrooted directory in /var/named/chroot.

Since PSA implements a chroot for named outside of this package the nameserver files will be relocated to a path like…

/var/named/chroot/var/named/run-root/var/named/

This will of course break named’s ability to startup.

simply remove the bind-chroot rpm and re-link the /etc/named.conf file to the right location.

rpm -e bind-chroot
ln -sf /var/named/run-root/etc/named.conf /etc/named.conf
/sbin/service named restart

You should be good to go at that point.

Categorized under: Databases, MySQL, OS, Quick Tips, apache, linux, servers

Get SSL running on Apache (CentOS)

I was playing with a new virtual server that had CentOS installed on it recently, and wanted to get SSL working for Apache.  Since I was only setting up a development server I really didn’t need to purchase a certificate and decided to use a self-signed certificate.  Here is what I did:

First I needed to get ‘make’ and ‘mod_ssl’ running to allow for this. (I use sudo but you could login as su)

sudo yum install make
sudo yum install mod_ssl

Next I did the following steps:

  1. Go to /etc/pki/tls/certs
  2. Run the command sudo make mycert.pem
  3. Enter the information you are prompted for about country, state, city, host name etc, your certificate and key has been created
  4. Now edit /etc/httpd/conf.d/ssl.conf and update the following items:
    • SSLCACertificateFile /etc/pki/tls/certs/mycert.pem
    • SSLCACertificateKeyFile /etc/pki/tls/mycert.pem
  5. I was forced to create a symbolic link for the SSLCACertificateKeyFile as follows: (I think this was supposed to happen automagically.)
    • I went to /etc/pki/tls and created the symbolic link using the next line.
    • sudo ln -s certs/mycert.pem mycert.pem
  6. Restart Apache (/etc/init.d/httpd restart)

There, now you have a self-signed certificate for your apache virtualhosts.

TinyMCE URL rewrite problem editing emails (kinda solved)

TinyMCE has a habit of rewriting the URL for images, etc.  However, this becomes broken when using TinyMCE to edit things like emails.  The relative path is totally useless in an email because the email is not being viewed from the server like a webpage would be.

To fix this I searched the tiny_mcs.js and found that TinyMCE had two settings in the tiny_mce.js file that are boolean flags (true,false or 0,1) dealing with URL’s. The variables are relative_urls and convert_urls, and by default they are set to true, or 1.

After changing these setting to false (or zero) I have not had any further problems with using TinyMCE to edit email content.

Categorized under: Hardware, OS, Quick Tips, linux, servers

Hard disk usage from command line on Linux

From the command line I have found many great tools for system management, but really needed to dig into ways of tracking hard disk usage on Linux without the aid of GUI tools. Google to the rescue! I found a few places with great tips and hints on how to do this, but one article on Linux.com came in very handy. Here were my findings:

The df utility displays the disk space usage on all mounted filesystems. The -T option prints the filesystem type as well. By default, df measures the size in 1K blocks, which could be a little difficult for a desktop user to decipher. Use the -h option to get more understandable output:

$ df -h -T
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/hda6     ext3     20G  9.3G  9.1G  51% /
/dev/hda7 reiserfs     13G  2.1G   11G  17% /mnt/suse
/dev/sda1     vfat    241M  152M   90M  63% /media/usbdisk

You can use the du command to determine which files or directories need to be deleted — or at least trimmed. A simple du will print usage for the present working directory and its subdirectories, along with the size of each directory.

If you want the size of an particular directory, specify it with du directoryname. For instance, du -h /home/bodhi/podcasts will print the size of the podcasts directory in a more readable format than the kilobytes used by default. The -c option prints the grand total size of the directory at the end. The -a option also displays the file names along with directories and can be of use when you want to see a list of files in a particular directory. The -s option will display a summary, without showing all of the subdirectories.

Running du -ch | grep total prints just one line with the total size of the directory. If there’s a particular type of file that you would like to be excluded while calculating a directory’s usage, specify it with the --exclude=type option. Here we’ll check the disk usage of the current directory, and display all file names with their disk usage, and then sort them numerically using the sort utility:

$ du -ah | sort -n
4.2M    ./eweek.10.28.05.mp3
4.5M    ./LQ-Podcast-101105.mp3
4.8M    ./LQ-Podcast-110905.mp3
19M     ./LQRadio-Episode3.mp3
20M     ./LQRadio-Searls.mp3
36M     ./LQRadio-HiserAndAdelstein.mp3
197M    .
Categorized under: css, graphics, html, images, programming

Background image generator – BgPatterns.com

After Ian posted this on his blog I thougth I would follow suit. (He always seems to find the cool stuff.)

This very nifty site allows you to create tiled background images for use wherever you may need them. At first I thought “yuck, I stopped using backgrounds long ago”. But after playing with rotation, colors, and opacity I found that a pretty nice tiled background can be useful when applied right.

It is very difficult to do a good job on tiled backgrounds, but this site makes it easy.
www.BgPatterns.com

Categorized under: Databases, MySQL, OS, Ubuntu, programming

MySQL not creating mysql.sock and broken on Hardy Heron

Recently I started receiving errors when I tried to connect to MySQL using command line or PHPMyAdmin. In command line I would get “ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)”, and with PHPMyAdmin I would get “#2002 – The server is not responding (or the local MySQL server’s socket is not correctly configured)”.

The system in question is my Dell Inspiron 1720 running Hardy Heron Ubuntu. I knew of a few changes to my system, but none of them seemed to have caused the problem. So I hunted for a few days trying to figure it out. I performed multiple searches on the net, and each led me to a dead end. Many said, “Set this … in your php.ini” or “Set that … in your my.cnf”, and some even said Apache was to blame. However, I found the solution to be very simple.

MySQL was expecting the mysql.sock to be located in ‘/tmp/mysql.sock’. However, for some reason it had moved or the symbolic link to it’s actual location was deleted by some update or install I did recently.

I fixed the problem by adding a symbolic link to the actual home of mysqld.sock, which was /var/run/mysqld/mysqld.sock. Here is how I created the symbolic link: (at the command line)

sudo ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock

sudo puts us in super user mode, “ln -s” creates a symbolic link followed by the target the links sould point to and last by the location of the link.

Edited on Sep. 26th with update below:

The fix above did not work as a permanent fix. I found that whenever I rebooted the OS it forced me to recreate the symbolic link. MySQL was failing to recreate the symbolic link on it’s own. To permanently fix the issue I needed to add the creation of the symbolic link to my SESSION startup. Here is how I did that:

By going to the System->Preferences->Sessions to edit the Startup Programs. I added an item that automatically issues the command above, but without the “sudo”.

Mission accomplished…permanently.

Categorized under: Hardware, OS, Quick Tips, Ubuntu, bluetooth, dell, linux

Ubuntu Hardy Heron sound broken

Recently I was having a consistent problem with the sound on my Dell Inspiron 1720, which is running on Ubuntu Hardy Heron. It would consistently stop working all together, and I had a terrible time finding the cause of the problem. If I viewed a flash video on the web, the sound would die afterwards. If I listened to streaming Internet radio, the sound would die. If I received an emial or IM the sound would die.

Finally it dawned on me, and I am not sure why or how. But a few weeks prior I had been toying with a Bluetooth stereo headset and had turned on the Audio service in the Bluetooth manager on the services tab.

Problem fixed: I simply turned off the Audio service in the Bluetooth manager, and all is working normally again. However, if I ever need the Audio service I suppose it will break my sound.

Categorized under: Quick Tips, email, html, javascript, programming

Hiding an email address using Javascript

Have you ever wondered why you suddenly started getting tons of spam?

Do you have, or did you recently post your email address on a website?

Then the reason is probably because you did not properly protect the email address, and spammers get most email addresses from robot script that harvest email addresses from websites. It is pretty simple really. The robot script hits the largest search engines for certain key words or phrases, to help the spammer hit the most relevent email addresses, and then systematically follows the links to websites. Once the robot gets to the website it then searches all links on the page. Each link it finds on the page that is a “mailto:” is an email address, and in a matter of minutes a robot script can harvest hundreds of emails.

So now you are asking, “What can be done to protect me from these vile robots?”. Well that answer is also simple. Most robot script are not smart enough, yet, to search Javascript code that scrambles an email address and form it back into a valid email address. So here is how to do it:

First, you need to go into the HTML code and insert the Javascript as follows:

var theuser = "username" // change this to be the username, or portion of the email to the left of the @
var thehost = "your-domain.com" // change this to be your domain name
 
var themessage = theuser + "@" + thehost;
 
// Now we tell Javascript to bring the pieces of the email address together visually on the screen as a link
document.write("<a href=" + "mail" + "to:" + theuser + "@" + thehost + ">" + themessage + "</a>")

Note: Be sure to substitute username and your-domain.com with your own information.

Now when you view your webpage in your favorite browser (Firefox) you will see the email as a link like you wanted, and the robots will see a bunch of code that most of them cannot form into a valid email address.

SSH port forwarding/tunneling for MySQL connection

Create an account on the remote MySQL database server.

useradd -s /bin/false remote_user
mkdir /home/remote_user/.ssh
touch /home/remote_user/.ssh/authorized_keys
chown -R remote_user:remote_user /home/remote_user/.ssh
chmod 755 /home/remote_user/.ssh
chmod 600 /home/remote_user/.ssh/authorized_keys

Add MySQL permissions in the remote MySQL database to allow user connections from localhost.

USE mysql;
GRANT ALL ON db.* TO database_user@127.0.0.1 IDENTIFIED BY 'database_pass';
FLUSH PRIVILEGES;

Now, on the local server (as root) create an RSA key pair to avoide the need for passwords for remote_user. (Simply hit enter for each question encountered.)

ssh-keygen -t rsa

Now transfer the public key file to the remote server from your local server.

scp /var/root/.ssh/id_rsa.pub root@remote_server.com:/tmp/local_server.local_rsa.pub
ssh remote_server.com
cat /tmp/local_server.local_rsa.pub >> /home/remote_user/.ssh/authorized_keys

On the local server, create an SSH tunnel to the remote MySQL database server using the following command.

ssh -fNg -L 3306:127.0.0.1:3306 remote_user@remote_server.com sleep 9999

To use this from PHP you would simply do this:

$remote_server_mysql = mysql_connect( "127.0.0.1", "database_user", "database_pass" );
mysql_select_db( "database", $remote_server_mysql );
Categorized under: OS, Quick Tips, apache, linux, programming, servers

Using the UNIX tail -f command to watch log files

When troubleshooting a problem in Apache it is a pain to open the log file, find an error, close the log file, and then open it again after you perform some action. This is why ‘tail’ is so handy.

Simply use the command below to view the last 100 lines of a log file, and as new entries are added to the file they are automatically displayed on the screen.

tail -f /the/file/name -n -100
Categorized under: Plesk

Plesk backup problem

I had a problem backing up domains on a server and received the following error message:

Error: Unable to create backup session: Specified file is not accessible

Finally i solved this problem!!!! it was all about wrong permission in some folders!

check that the folders ‘/var/lib/psa/dumps’ and ‘/var/lib/psa/dumps/tmp’ are chmod to 777

Categorized under: OS, Quick Tips, linux

Change/update time on Linux

Sets whether the hardware clock is stored as UTC or local time.

/etc/sysconfig/clock

Symlink /etc/localtime to /usr/share/zoneinfo/… to set your timezone.

To set the current system date/time.

date MMDDhhmm

To set the hardware clock.

/sbin/hwclock --systohc
Categorized under: Quick Tips, apache, css, javascript, programming

Javascript disable right click and image tool bar

A recent request from a client was to make life more difficult for his competitors to steal images from his site. He was worried that they could save the images using the Image Toolbar in newer versions of Internet Explorer, and by using the right click menu on the page. For those of you that wish to stop the right clickers from stealing your code, or from stealing images, here is a quick and easy way to make life more difficult for them.

To disable the Internet Explorer Image Toolbar for an entire page add this meta tag:

<meta http-equiv="imagetoolbar" content="no">

To disable the Internet Explorer Image Toolbar for an individual Image do this:

<img src="image.gif" width="250" height="250" galleryimg="no>

Now to handle those who love their “right-click”. For the entire page:

<body oncontextmenu="return false">

And for individual images:

<img src="image.gif" width="250" height="250" oncontextmenu="return false">

CSS style sheet switcher using Prototype

A recent project had a requirementfor a style switcher allowing a visitor to control font size on the site as needed. (Many do not know how to change it through a browser, and most sites are not designed to allow for font size changes without completely trashing presentation.)

Because the project in question was a dynamic site I wanted to make a style sheet switcher that didn’t force a page reload and it seemed like most examples on the net required a page to reload with a new stylesheet. (After PHP or some other scripting language decided which css sheet to render the page with.) This meant additional calls to the server to repopulate data grids and other info, after re-running a query and parsing in PHP. To me this was truly unacceptable load on a server to simply change font sizes on a page.

Categorized under: OS, Plesk, Quick Tips, apache, linux, php, programming, servers

PHP failing to upload images on a Plesk managed server

I recently upgraded a few of my Linux servers from Plesk 7.5 to 8.2. Everything seemed to be fine, however calls started coming in about PHP forms not uploading images correctly.

My team and I were troubleshooting this problem for a few days trying to narrow down the problem. We looked at folder permissions, script permissions, database connectivity, and almost anything else we could think of. Then we stumbled across the error message given by PHP (who would have thought to look at the error message?) that said function move_uploaded_file will not work in safe_mode.

Now looking at the PHP info the main php.ini was set with safe_mode off. However, I found that the httpd.conf for the individual domains on a Plesk managed server carries a declaration for PHP safe_mode, and it was turned on. Upon further investigation I found that in the Plesk interface for the domain there is a checkbox beside the PHP setting that allows safe_mode to be turned on and off.

Mission accomplished!

Adding mssql capability to PHP5 on CentOS

I had a need to connect to MSSQL using PHP version 5 from a CentOS 5 server. To do this I needed FreeTDS and the module mssql in PHP. After a diligent search I found that there was no quick and easy way to install the mssql module, like “up2date install php-gd” to get GD to work from PHP.

I found a few places that had ideas and hints to make this work, but finally used the directions I found at http://www.howtoforge.com/installing_php_mssql_centos5.0 (slightly altered to fit my means) and will duplicate here so I can easily find it later.

At first I thought I needed to recompile PHP, but as it turned out I only needed to pre-compile it so that I could fetch the mssql.so, and then manually edit the php.ini to use it.

RSSSubscribe to my feed now.

About Me

GeekyBoy.com